显示标签为“OSX”的博文。显示所有博文
显示标签为“OSX”的博文。显示所有博文

2013年12月1日星期日

mac os 定期任务配置


http://www.netingcn.com/mac-os-plist.html


在linux下执行定期任务可以使用crontab,目前mac os也可以使用它,不过已不推荐使用。推荐做法是采用plist脚本,plist脚本可以设置执行的动作,时间间隔等其他一些信息。另外crontab的最小时间间隔是一分钟,使用plist脚本原则上时间间隔可以为一秒。
plist脚本存放路径为/Library/LaunchDaemons或/Library/LaunchAgents,其区别是后一个路径的脚本当用户登陆系统后才会被执行,前一个只要系统启动了,哪怕用户不登陆系统也会被执行。
可以通过两种方式来设置脚本的执行时间。一个是使用StartInterval,它指定脚本每间隔多长时间(单位:秒)执行一次;另外一个使用StartCalendarInterval,它可以指定脚本在多少分钟、小时、天、星期几、月时间上执行,类似如crontab的中的设置。
一个简单例子如下:



    Label
    com.yangyz.cron.test.plist
    ProgramArguments
    
        /Users/yangyz/plist-test.sh
    
    KeepAlive
    
    RunAtLoad
    
    StartInterval
    60

其中key是plist脚本定义的属性,紧跟着的下一行是该属性对应的值。上述脚本是每间隔60秒执行一次/Users/yangyz/plist-test.sh这个shell脚本,也可以使用StartCalendarInterval来替换StartInterval达到同样的效果,例如:
StartCalendarInterval

  Minute
  0
上述设置的意思为每天的每个小时的第0分钟执行,也即使每60秒执行一次。
plist脚本中定义的属性以及具体的含义,可以参看苹果官方网站的说明,地址为:launchd.plist(5) Mac OS X Manual Page
launchctl命令可以控制plist脚本停止或重新加载。例如:
停止脚本com.yangyz.cron.test.plist运行
launchctl unload /Library/LaunchDaemons/com.yangyz.cron.test.plist 

启动脚本com.yangyz.cron.test.plist运行
launchctl load /Library/LaunchDaemons/com.yangyz.cron.test.plist
如果执行上面命令看到launchctl: Dubious ownership on file (skipping): /Library/LaunchDaemons/com.yangyz.cron.test.plist这样的错误,其原因是该脚本的owner和当前执行操作用户不一致。使用chown修改一下即可。

2013年9月28日星期六

Access hidden user library files

http://helpx.adobe.com/x-productkb/global/access-hidden-user-library-files.html

Apple made the user library folder hidden by default with the 10.7 and later releases of Mac OS. If it's necessary to access these files for Adobe-related troubleshooting, use one of the following methods to make the user library content visible.

Method 1

  1. In the Finder, choose Go > Go To Folder.
  2. In the Go To Folder dialog, type ~/Library
  3. Click Go.

Method 2

Hold down the Alt (Option) key when using the Go menu. The user library folder is listed below the current user's home directory.
Note: After you open the Library folder, you can drag the Library icon from the top of that window to the Dock, Side Bar, or toolbar. That way, it's readily accessible.

Method 3

The following method makes the user library folder permanently visible. 

Note: Adobe recommends that only advanced users use this method.
  1. Launch Terminal from Mac HD > Applications > Utilities.
  2. From within Terminal type the following command and press Return:

    chflags nohidden ~/Library
  3. Enter the system administrator password, if prompted, and press Return.
Note: The System administrator password is not visible as you type it.  
Close Terminal for this change to take effect.

2013年9月17日星期二

OSX10.7 安装mysql-python报错cc1: error: unrecognized command line option

Mac OS X 10.7 安装 mysql-python 报错

cc1: error: unrecognized command line option "-Wno-null-conversion"
error: Setup script exited with error: command 'llvm-gcc-4.2' failed with exit status 1

应该是 llvm-gcc-4.2 的编译器不识别 option 导致的



http://stackoverflow.com/questions/16127493/cc1-error-unrecognized-command-line-option-wno-null-conversion-within-insta


将 mysql_config 里面的相关 option 去掉再次编译就可以了 



Try to Remove cflags -Wno-null-conversion -Wno-unused-private-field in
/usr/local/mysql/bin/mysql_config.
like:
cflags="-I$pkgincludedir  -Wall   -Os -g -fno-strict-aliasing -DDBUG_OFF -arch x86_64 "

2013年7月8日星期一

os x nginx和php-fpm

第一步,安装xcode,打开这个窗口,Install Command Line Tools

第二步,安装homebrew,为了安装一些php依赖的库
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
brew tap homebrew/dupes
brew tap josegonzalez/homebrew-php
brew install git
brew update
brew install wget mysql pcre freetype gd geoip jpeg libpng libtool

第三步,下载php源码包和nginx源码包
自行移步到 http://www.php.net/downloads.php 和 http://nginx.org/en/download.html
下载吧,下载完解压就不用教了吧?

第四步,编译php5.4
cd php5.4的源码文件夹
./configure  --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --sysconfdir=/private/etc --enable-cli --with-config-file-path=/etc --with-libxml-dir=/usr --with-openssl=/usr --with-kerberos=/usr --with-zlib=/usr --enable-bcmath --with-bz2=/usr --enable-calendar --disable-cgi --with-curl=/usr --enable-dba --enable-exif --enable-fpm --enable-ftp --with-gd --with-freetype-dir=/usr/X11 --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --enable-gd-native-ttf --with-icu-dir=/usr --with-iodbc=/usr --with-ldap=/usr --with-ldap-sasl=/usr --with-libedit=/usr --enable-mbstring --enable-mbregex --with-mysql=mysqlnd --with-mysqli=mysqlnd --without-pear --with-pdo-mysql=mysqlnd --with-mysql-sock=/var/mysql/mysql.sock --with-readline=/usr --enable-shmop --with-snmp=/usr --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --with-tidy --enable-wddx --with-xmlrpc --with-iconv-dir=/usr --with-xsl=/usr --enable-zip --with-pcre-regex=/usr --with-pgsql=/usr --with-pdo-pgsql=/usr
make
sudo make install

第五步,编译nginx
cd 到nginx的源码文件夹
./configure --prefix=/usr --sbin-path=/usr/sbin --conf-path=/private/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --with-poll_module  --with-http_ssl_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module  --with-http_spdy_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_dav_module --with-http_sub_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --http-log-path=/var/log/nginx/access.log

make
sudo make install

第六步,修改nginx,解决php白页
vim /etc/nginx/ fastcgi_param增加下面一行
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

第七步,开启php-fpm和nginx的服务
sudo /usr/sbin/php-fpm
sudo /usr/sbin/nginx
开启之后,可以写个php文件调试一下了。
nginx默认目录在/usr/html/,创建一个test.php 里面 写上一句
可以输入http://127.0.0.1/test.php测试一下了

第八步,增加自启动项
执行sudo -s命令,切换到管理员权限
在/Library/LaunchDaemons目录创建两个文件
org.lukin.php-fpm.plist,文件的内容:

http://www.apple.com/DTDs/PropertyList-1.0.dtd
">


  KeepAlive
 
  Label
  org.lukin.php-fpm
  Program
  /usr/sbin/php-fpm
  RunAtLoad
 
  WorkingDirectory
  /usr/local/var

org.lukin.nginx.plist,文件的内容:

http://www.apple.com/DTDs/PropertyList-1.0.dtd
">


  KeepAlive
 
  Label
  org.lukin.nginx
  Program
  /usr/sbin/nginx
  RunAtLoad
 
  WorkingDirectory
  /usr/local/var

增加开机启动任务,执行以下命令:
launchctl load -w /Library/LaunchDaemons/org.lukin.php-fpm.plist
launchctl load -w /Library/LaunchDaemons/org.lukin.nginx.plist

可以重启机器了,重启之后,用 netstat -nat | grep LISTEN 这个命令,看看是否已经开启相应的端口了。
80端口和9000如果已经有了,就说明你的配置都正常了。

2013年7月7日星期日

查看端口占用

lsof -i :端口  显示占用该端口的进程情况 

homebrew安装与使用

http://mxcl.github.io/homebrew/

https://github.com/mxcl/homebrew/wiki/installation



homebrew的安装 在使用

ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"

需要在当前用户下运行,而不是root

如果使用root运行,则会报错 Don't run this as root !














常用brew命令

brew search #查找软件包

brew install #安装软件包

brew list #列出软件包

brew uninstall #卸载软件包

brew update #更新

brew info #查看软件包的基本资料



http://linfan.info/blog/2012/02/25/homebrew-installation-and-usage/

Mac OS X是基于Unix的操作系统,可以安装大部分为Unix/Linux开发的软件。然而,如果只是以使用为目的,对每个软件都进行手工编译不是很方便,也不利于管理已安装的软件,于是出现了类似于Linux中APT、Yum等类似的软件包管理系统,其中最著名的有MacPorts、Fink、Homebrew等。
我曾经是MacPorts的使用者,但了解Homebrew之后,立即“弃暗投明”了。其实MacPorts也是一个很不错的解决方案,除了一个实在让我头疼的特性。MacPorts有个原则,对于软件包之间的依赖,都在MacPorts内部解决(/opt/local),无论系统本身是否包含了需要的库,都不会加以利用。这使得MacPorts过分的庞大臃肿,导致系统出现大量软件包的冗余,占用不小的磁盘空间,同时稍大型一点的软件编译时间都会难以忍受。
而Homebrew的原则恰恰相反,它尽可能地利用系统自带的各种库,使得软件包的编译时间大为缩短;同时由于几乎不会造成冗余,软件包的管理也清晰、灵活了许多。Homebrew的另一个特点是使用Ruby定义软件包安装配置(叫做formula),定制非常简单。
至于Fink,由于并未安装使用过,不加讨论。(从互联网上的消息看,Fink由于维护人手的问题,软件包的更新不是很及时。)于我而言,Homebrew已经足够完善,除非发现重大的问题或者出现新的具有突破性的竞争对手,否则我没兴趣折腾别的软件包管理系统了。
下面说说Homebrew的安装与使用。

Homebrew的安装

首先确保你的系统满足如下要求:
  1. 基于Intel CPU
  2. 操作系统为Mac OS X 10.5 Leopard或更高版本
  3. 已安装版本管理工具Git(Mac OS X 10.7 Lion已经预安装)
  4. 已安装Xcode开发工具1
  5. 已安装Java Developer Update2
注1:Xcode 4.3中,命令行编译工具是可选安装,需要在Preferences > Downloads中激活。
注2:可选,Homebrew本身不依赖于Java,只有部分软件包的安装需要Java支持。
Homebrew的安装非常简单,在终端程序中输入以下命令即可。
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
由于Homebrew的安装地址可能变化,请到官方网站查看最新的安装方法。
安装过程需要输入root口令。

Homebrew的使用

Homebrew的可执行命令是brew,其基本使用方法如下(以wget为例)。
查找软件包
brew search wget
安装软件包
brew install wget
列出已安装的软件包
brew list
删除软件包
brew remove wget
查看软件包信息
brew info wget
列出软件包的依赖关系
brew deps wget
更新brew
brew update
列出过时的软件包(已安装但不是最新版本)
brew outdated
更新过时的软件包(全部或指定)
brew upgrade 或 brew upgrade wget

定制自己的软件包

如果自己需要的软件包并不能在Homebrew中找到,怎么办呢,毕竟Homebrew是一个新生项目,不可能满足所有人的需求。当然,我们可以自行编译安装,但手工安装的软件包游离于Homebrew之外,管理起来不是很方便。
前文说过,Homebrew使用Ruby实现的软件包配置非常方便,下面简单谈一谈软件包的定制(假定软件包名称是bar,来自foo站点)。
  1. 首先找到待安装软件的源码下载地址
    http://foo.com/bar-1.0.tgz
  2. 建立自己的formula
    brew create http://foo.com/bar-1.0.tgz
  3. 编辑formula,上一步建立成功后,Homebrew会自动打开新建的formula进行编辑,也可用如下命令打开formula进行编辑。
    brew edit bar
    Homebrew自动建立的formula已经包含了基本的configuremake install命令,对于大部分软件,不需要进行修改,退出编辑即可。
  4. 输入以下命令安装自定义的软件包
    brew install bar

关于Homebrew的其它功能,比如将自定义软件包提交到官方发布等,请参考Homebrew项目的主页及其Man Page。你将发现Homebrew不仅是“家酿”,更是“佳酿”。


Mac OS X 安装 nginx


什么是Nginx?
Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器,在高连接并发的情况下Nginx 是 Apache 服务器不错的替代品.其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好.目前中国大陆使用nginx网站用户有:新浪、网易、 腾讯,另外知名的微网志Plurk也使用nginx。 
  Nginx 作为 负载均衡 服务器: 
Nginx 既可以在内部直接支持 Rails 和 PHP 程序对外进行服务,也可以支持作为 HTTP 代理服务器对外进行服务。 Nginx 采用 C 进行编写, 不论是系统资源开销还是 CPU 使用效率都比 Perlbal 要好很多。作为邮件代理服务器: 
  Nginx 同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也是作为邮件代理服务器), Last.fm 描述了成功并且美妙的使用经验。Nginx 是一个安装非常简单,配置文件非常简洁(还能够支持perl语法), Bugs非常少的服务器: Nginx 启动特别容易,并且几乎可以做到 7*24 不间断运行,即使运行数个月也不需要重新启动。 你还能够不间断服务的情况下进行软件版本的升级。

Nginx的安装
模块依赖性Nginx需要依赖下面3个包
1. gzip 模块需要 zlib 库 ( 下载: http://www.zlib.net/ )
2. rewrite 模块需要 pcre 库 ( 下载: http://www.pcre.org/ )
3. ssl 功能需要 openssl 库 ( 下载: http://www.openssl.org/ )


依赖包安装顺序依次为:openssl、zlib、pcre, 然后安装Nginx包.

图解教程
第一步: 下载安装所需包
openssl-fips-2.0.2.tar.gz
zlib-1.2.7.tar.gz
pcre-8.21.tar.gz
nginx-1.2.6.tar.gz
第二步:依次安装openssl-fips-2.0.2.tar.gz, zlib-1.2.7.tar.gz, pcre-8.21.tar.gz, nginx-1.2.6.tar.gz
1.安装openssl-fips-2.0.2.tar.gz
复制代码
[root@localhost mrms]# tar -zxvf openssl-fips-2.0.2.tar.gz 

[root@localhost mrms]# cd openssl-fips-2.0.2

[root@localhost openssl-fips-2.0.2]# ./config 

[root@localhost openssl-fips-2.0.2]# make

[root@localhost openssl-fips-2.0.2]# make install
复制代码
2.安装zlib-1.2.7.tar.gz
复制代码
[root@localhost mrms]# tar -zxvf zlib-1.2.7.tar.gz

[root@localhost mrms]# cd zlib-1.2.7

[root@localhost zlib-1.2.7]# ./configure 

[root@localhost zlib-1.2.7]# make

[root@localhost zlib-1.2.7]# make install
复制代码
3.安装pcre-8.21.tar.gz
复制代码
[root@localhost mrms]# tar -zxvf pcre-8.21.tar.gz

[root@localhost mrms]# cd pcre-8.21

[root@localhost pcre-8.21]# ./configure 

[root@localhost pcre-8.21]# make

[root@localhost pcre-8.21]# make install
复制代码
 4.安装 nginx-1.2.6.tar.gz
复制代码
[root@localhost mrms]# tar -zxvf nginx-1.2.6.tar.gz 

[root@localhost mrms]# cd nginx-1.2.6

[root@localhost nginx-1.2.6]# ./configure --with-pcre=../pcre-8.21 --with-zlib=../zlib-1.2.7 --with-openssl=../openssl-fips-2.0.2

[root@localhost nginx-1.2.6]# make

[root@localhost nginx-1.2.6]# make install
复制代码
至此Nginx的安装完成!
第三步:检测是否安装成功
[root@localhost nginx-1.2.6]# cd  /usr/local/nginx/sbin

[root@localhost sbin]# ./nginx -t
出现如下所示提示,表示安装成功
 
启动nginx
[root@localhost sbin]# ./nginx
查看端口
[root@localhost sbin]# netstat -ntlp
结果如下