BLOG引越しました
新しいBLOGは http://massat.jp こちら
Amazon LinuxにKyototycoonをインストール
Basic 64-bit Amazon Linux AMI 2011.09 (AMI Id: ami-0a44f00b) にて。
Checkinstallインストール済
先にKyotocabinetをインストール
[root@localhost ~]# yum install -y gcc-c++ zlib-devel [root@localhost ~]# cd ~/workspace [root@localhost workspace]# wget http://fallabs.com/kyotocabinet/pkg/kyotocabinet-1.2.72.tar.gz [root@localhost workspace]# tar xzf kyotocabinet-1.2.72.tar.gz [root@localhost workspace]# cd kyotocabinet-1.2.72 [root@localhost kyotocabinet-1.2.72]# ./configure [root@localhost kyotocabinet-1.2.72]# make [root@localhost kyotocabinet-1.2.72]# checkinstall checkinstall 1.6.3, Copyright 2010 Felipe Eduardo Sanchez Diaz Duran This software is released under the GNU GPL. The checkinstallrc file was not found at: /usr/local/sbin/../checkinstallrc Assuming default values. The package documentation directory ./doc-pak does not exist. Should I create a default set of package docs? [y]: Preparing package documentation...OK Please choose the packaging method you want to use. Slackware [S], RPM [R] or Debian [D]? R Please write a description for the package. End your description with an empty line or EOF. >> ************************************** **** RPM package creation selected *** ************************************** This package will be built according to these values: 1 - Summary: [ Package created with checkinstall 1.6.3 ] 2 - Name: [ kyotocabinet ] 3 - Version: [ 1.2.72 ] 4 - Release: [ 1 ] 5 - License: [ GPL ] 6 - Group: [ Applications/System ] 7 - Architecture: [ x86_64 ] 8 - Source location: [ kyotocabinet-1.2.72 ] 9 - Alternate source location: [ ] 10 - Requires: [ ] 11 - Provides: [ kyotocabinet ] Enter a number to change any of them or press ENTER to continue: Installing with make install... [root@localhost kyotocabinet-1.2.72]# rpm -ivh ~/rpmbuild/RPMS/x86_64/kyotocabinet-1.2.72-1.x86_64.rpm Preparing... ########################################### [100%] 1:kyotocabinet ########################################### [100%] [root@localhost kyotocabinet-1.2.72]# cd .. < 続いてKyototycoonをインストール >|sh| [root@localhost workspace]# wget http://fallabs.com/kyototycoon/pkg/kyototycoon-0.9.53.tar.gz [root@localhost workspace]# tar xzf kyototycoon-0.9.53.tar.gz [root@localhost workspace]# cd kyototycoon-0.9.53 [root@localhost kyototycoon-0.9.53]# ./configure [root@localhost kyototycoon-0.9.53]# make [root@localhost kyototycoon-0.9.53]# checkinstall checkinstall 1.6.3, Copyright 2010 Felipe Eduardo Sanchez Diaz Duran This software is released under the GNU GPL. The checkinstallrc file was not found at: /usr/local/sbin/../checkinstallrc Assuming default values. The package documentation directory ./doc-pak does not exist. Should I create a default set of package docs? [y]: Preparing package documentation...OK Please choose the packaging method you want to use. Slackware [S], RPM [R] or Debian [D]? R Please write a description for the package. End your description with an empty line or EOF. >> ************************************** **** RPM package creation selected *** ************************************** This package will be built according to these values: 1 - Summary: [ Package created with checkinstall 1.6.3 ] 2 - Name: [ kyototycoon ] 3 - Version: [ 0.9.53 ] 4 - Release: [ 1 ] 5 - License: [ GPL ] 6 - Group: [ Applications/System ] 7 - Architecture: [ x86_64 ] 8 - Source location: [ kyototycoon-0.9.53 ] 9 - Alternate source location: [ ] 10 - Requires: [ ] 11 - Provides: [ kyototycoon ] Enter a number to change any of them or press ENTER to continue: Installing with make install... [root@localhost kyototycoon-0.9.53]# rpm -ivh ~/rpmbuild/RPMS/x86_64/kyototycoon-0.9.53-1.x86_64.rpm Preparing... ########################################### [100%] 1:kyototycoon ########################################### [100%] [root@localhost kyototycoon-0.9.53]# echo /usr/local/lib >> /etc/ld.so.conf [root@localhost kyototycoon-0.9.53]# ldconfig < Basic 64-bit Amazon Linux AMI 2011.09 (AMI Id: ami-0a44f00b) にて実施 >|sh| [root@localhost ~]# yum install -y git gettext rpm-build [root@localhost ~]# mkdir workspace [root@localhost ~]# cd workspace/ [root@localhost workspace]# git clone http://checkinstall.izto.org/checkinstall.git [root@localhost workspace]# cd checkinstall [root@localhost checkinstall]# make [root@localhost checkinstall]# make install [root@localhost checkinstall]# mkdir -p ~/rpmbuild/SOURCES [root@localhost checkinstall]# checkinstall checkinstall 1.6.3, Copyright 2010 Felipe Eduardo Sanchez Diaz Duran This software is released under the GNU GPL. The checkinstallrc file was not found at: /usr/local/sbin/../checkinstallrc Assuming default values. The package documentation directory ./doc-pak does not exist. Should I create a default set of package docs? [y]: Preparing package documentation...OK Please choose the packaging method you want to use. Slackware [S], RPM [R] or Debian [D]? R ************************************** **** RPM package creation selected *** ************************************** This package will be built according to these values: 1 - Summary: [ CheckInstall installations tracker, version 1.6.2 ] 2 - Name: [ checkinstall ] 3 - Version: [ 20120219 ] 4 - Release: [ 1 ] 5 - License: [ GPL ] 6 - Group: [ Applications/System ] 7 - Architecture: [ x86_64 ] 8 - Source location: [ checkinstall ] 9 - Alternate source location: [ ] 10 - Requires: [ ] 11 - Provides: [ checkinstall ] Enter a number to change any of them or press ENTER to continue: Installing with make install... [root@localhost checkinstall]# rpm -ivh ~/rpmbuild/RPMS/x86_64/checkinstall-20120219-1.x86_64.rpm
Supervisord を Amazon Linux AMI にインストール
daemontoolsのalternative的なツール。SupervisordをAWS環境で動かしてみた。
以下環境
Supervisordインストール
Amazon Linux AMIを使用すると初期状態からeasy_installが利用可能。
[root@ip-x-x-x-x ~]# easy_install supervisor Searching for supervisor Reading http://pypi.python.org/simple/supervisor/ Reading http://www.plope.com/software Reading http://www.plope.com/software/supervisor2/ Reading http://dist.supervisord.org/ Reading http://www.plope.com Reading http://www.plope.com/software/supervisor/supervisor-a3.tgz/download Reading http://supervisord.org/dist/ Best match: supervisor 3.0a10 Downloading http://pypi.python.org/packages/source/s/supervisor/supervisor-3.0a10.tar.gz#md5=99c6fbd45bade87301296b7a597fb68e Processing supervisor-3.0a10.tar.gz Running supervisor-3.0a10/setup.py -q bdist_egg --dist-dir /tmp/easy_install-8XSd1H/supervisor-3.0a10/egg-dist-tmp-xbvxo3 no previously-included directories found matching 'docs/*.pyc' no previously-included directories found matching 'docs/.build' Adding supervisor 3.0a10 to easy-install.pth file Installing echo_supervisord_conf script to /usr/bin Installing pidproxy script to /usr/bin Installing supervisorctl script to /usr/bin Installing supervisord script to /usr/bin Installed /usr/lib/python2.6/site-packages/supervisor-3.0a10-py2.6.egg Processing dependencies for supervisor Searching for meld3>=0.6.5 Reading http://pypi.python.org/simple/meld3/ Reading http://svn.supervisord.org/meld3/ Reading http://dist.repoze.org/meld3/ Reading http://www.plope.com/software/meld3/ Best match: meld3 0.6.7 Downloading http://pypi.python.org/packages/source/m/meld3/meld3-0.6.7.tar.gz#md5=53e589482029ee84ffac9362db71eabe Processing meld3-0.6.7.tar.gz Running meld3-0.6.7/setup.py -q bdist_egg --dist-dir /tmp/easy_install-i5PCas/meld3-0.6.7/egg-dist-tmp-m8Gj27 zip_safe flag not set; analyzing archive contents... Adding meld3 0.6.7 to easy-install.pth file Installed /usr/lib/python2.6/site-packages/meld3-0.6.7-py2.6.egg Finished processing dependencies for supervisor
自動起動の設定
起動スクリプトを適当に用意
[root@ip-x-x-x-x ~]# wget https://raw.github.com/gist/1280482/5cb72046c2b9dc07b1e6de90bc32d77085d9cad4/supervisord --2011-10-12 09:05:37-- https://raw.github.com/gist/1280482/5cb72046c2b9dc07b1e6de90bc32d77085d9cad4/supervisord Resolving raw.github.com... 207.97.227.243 Connecting to raw.github.com|207.97.227.243|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 1023 [text/plain] Saving to: “supervisord” 100%[=========================================================================================================================================>] 1,023 --.-K/s in 0s 2011-10-12 09:05:38 (323 MB/s) - “supervisord” saved [1023/1023] [root@ip-x-x-x-x ~]# cp supervisord /etc/init.d/ [root@ip-x-x-x-x ~]# chkconfig --add supervisord [root@ip-x-x-x-x ~]# chkconfig | grep supervisord supervisord 0:off 1:off 2:on 3:on 4:on 5:on 6:off
Supervisordの設定
supervisord.confをつくる。
[root@ip-x-x-x-x ~]# echo_supervisord_conf > /etc/supervisord.conf
監視対象プログラム毎の設定ファイル置場をつくる。
[root@ip-x-x-x-x ~]# mkdir -p /etc/supervisord/conf/
監視対象プログラム毎の設定ファイルを読むように設定する。
最終行あたりを修正。
[include] files = supervisord/conf/*.conf
監視対象プログラムの追加
/etc/supervisord/conf/memcached.conf を作成
[program:memcached] command = memcached -p 11211 -u memcached -m 64 -c 1024 -P /var/run/memcached/memcached.pid process_name = memcached autostart = true autorestart = true
supervisord の起動
[root@ip-x-x-x-x supervisord]# service supervisord start Starting supervisord: [ OK ] [root@ip-x-x-x-x supervisord]# ps aux | grep memcached 220 21768 0.0 0.1 46056 996 ? Sl 05:24 0:00 memcached -p 11211 -u memcached -m 64 -c 1024 -P /var/run/memcached/memcached.pid root 21775 0.0 0.1 5532 716 pts/0 S+ 05:24 0:00 grep memcached
memcachedをkillしてみる
[root@ip-x-x-x-x supervisord]# kill 21768 [root@ip-x-x-x-x supervisord]# ps aux | grep memcached 220 21776 0.0 0.1 46056 988 ? Sl 05:25 0:00 memcached -p 11211 -u memcached -m 64 -c 1024 -P /var/run/memcached/memcached.pid root 21783 0.0 0.1 5532 716 pts/0 S+ 05:26 0:00 grep memcached
復活した!
付属のクライアントツール supervisorctl を使ってみる
[root@ip-x-x-x-x supervisord]# supervisorctl memcached RUNNING pid 21776, uptime 0:00:42 supervisor> ? default commands (type help <topic>): ===================================== add clear fg open quit remove restart start stop update avail exit maintail pid reload reread shutdown status tail version
とめてみる
supervisor> stop memcached memcached: stopped supervisor> status memcached STOPPED Oct 13 05:29 AM
動かしてみる
supervisor> start memcached memcached: started supervisor> status memcached RUNNING pid 21785, uptime 0:00:03
おわりに
とりあえず、インストール・設定・監視をひととおり。
Webからの管理インターフェースもあるようだが、それはまたの機会。
homebrewでMongoDB × PHP環境構築
以下環境
PHP Driverインストール
こちらの通り、
[massat@massat-mbp.local ~]$ sudo pecl install mongo
して、php.iniに
extension=mongo.so
を追記するだけ。
[massat@massat-mbp.local ~]$ php -i | grep mongo mongo mongo.allow_empty_keys => 0 => 0 mongo.allow_persistent => 1 => 1 mongo.auto_reconnect => 1 => 1 mongo.chunk_size => 262144 => 262144 mongo.cmd => $ => $ mongo.default_host => localhost => localhost mongo.default_port => 27017 => 27017 mongo.long_as_object => 0 => 0 mongo.native_long => 0 => 0 mongo.no_id => 0 => 0 mongo.utf8 => 1 => 1
動作確認
PHPからの接続はおいとくとして、シェルから確認する。
DB起動
デフォルトの設定ファイルを使用して起動
[massat@massat-mbp.local ~]$ mongod -f /usr/local/Cellar/mongodb/1.6.5-x86_64/mongod.conf Mon Feb 7 18:38:29 MongoDB starting : pid=98408 port=27017 dbpath=/usr/local/var/mongodb 64-bit Mon Feb 7 18:38:29 db version v1.6.5, pdfile version 4.5 Mon Feb 7 18:38:29 git version: 0eb017e9b2828155a67c5612183337b89e12e291 Mon Feb 7 18:38:29 sys info: Darwin erh2.10gen.cc 9.6.0 Darwin Kernel Version 9.6.0: Mon Nov 24 17:37:00 PST 2008; root:xnu-1228.9.59~1/RELEASE_I386 i386 BOOST_LIB_VERSION=1_40 Mon Feb 7 18:38:29 [initandlisten] waiting for connections on port 27017 Mon Feb 7 18:38:29 [websvr] web admin interface listening on port 28017
DB接続
クライアントユーティリティから接続して、保存したり検索したり。
[massat@massat-mbp.local ~]$ mongo MongoDB shell version: 1.6.5 connecting to: test > db.users.save({name: "massat"}); > db.users.find({name: "massat"}) { "_id" : ObjectId("4d4fc73e2881b21c69cad9d7"), "name" : "massat" }
homebrewでuniversal binaryなImageMagickをビルド
勢いでパッケージ管理をMacPortからhomebrewに切り替えて予想通りつまづいたのでメモ。
環境
後先考えずにMacPortをアンインストールして、homebrewをインストール。
開発環境を整えようとImageMagickを入れる。
[massat@massat-mbp.local ~]$ brew install imagemagick [massat@massat-mbp.local ~]$ sudo MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp" CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" LDFLAGS="-arch i386 -arch x86_64 -bind_at_load" /Applications/MAMP/bin/php5/bin/pecl install imagick
[massat@massat-mbp.local ~]$ /Applications/MAMP/bin/php5/bin/php -i dyld: lazy symbol binding failed: Symbol not found: _MagickWandGenesis Referenced from: /Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20060613/imagick.so Expected in: flat namespace dyld: Symbol not found: _MagickWandGenesis Referenced from: /Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20060613/imagick.so Expected in: flat namespace Trace/BPT trap
以前も書いたとおり、
MAMPに載ってるPHPは64bit環境用にビルドされていない。
[massat@massat-mbp.local ~]$ file /Applications/MAMP/bin/php5/bin/php /Applications/MAMP/bin/php5/bin/php: Mach-O universal binary with 2 architectures /Applications/MAMP/bin/php5/bin/php (for architecture ppc): Mach-O executable ppc /Applications/MAMP/bin/php5/bin/php (for architecture i386): Mach-O executable i386
これに対してhomebrewでインスコしたImageMagickは64bit環境向けにビルドされる。
[massat@massat-mbp.local ~]$ file /usr/local/Cellar/imagemagick/6.6.7-1/bin/convert /usr/local/Cellar/imagemagick/6.6.7-1/bin/convert: Mach-O 64-bit executable x86_64
ので、homebrewでuniversal binaryなImageMagickをビルドしたい。
ググって出てきた記事では、
For your own personal usage you can try to get a universal binary by calling: ENV.universal in that formula's install function.
って言ってるが、自分の環境ではこれは動かなかった。
homebrewのソースを確認してみると、
[massat@massat-mbp.local ~]$ vim /usr/local/Library/Homebrew/extend/ENV.rb
ENV.universal_binary があった。
# i386 and x86_64 only, no PPC def universal_binary append_to_cflags '-arch i386 -arch x86_64' self.O3 if self['CFLAGS'].include? '-O4' # O4 seems to cause the build to fail append 'LDFLAGS', '-arch i386 -arch x86_64' # Can't mix "-march" for a 32-bit CPU with "-arch x86_64" remove_from_cflags(/-march=\S*/) if Hardware.is_32_bit? end
ので、手元のformulaを修正して、
[massat@massat-mbp.local ~]$ cp /usr/local/Library/Formula/imagemagick.rb /usr/local/Library/Formula/imagemagick.rb.org [massat@massat-mbp.local ~]$ brew edit imagemagick
"ENV.universal_binary"を追加。
[massat@massat-mbp.local ~]$ diff -u /usr/local/Library/Formula/imagemagick.rb.org /usr/local/Library/Formula/imagemagick.rb --- /usr/local/Library/Formula/imagemagick.rb.org 2011-02-05 17:02:46.000000000 +0900 +++ /usr/local/Library/Formula/imagemagick.rb 2011-02-05 17:03:07.000000000 +0900 @@ -75,6 +75,7 @@ def install ENV.x11 # Add to PATH for freetype-config on Snow Leopard ENV.O3 # takes forever otherwise + ENV.universal_binary args = [ "--disable-osx-universal-binary", "--without-perl", # I couldn't make this compile
んで、再度ビルドする。
[massat@massat-mbp.local ~]$ sudo pecl uninstall imagick [massat@massat-mbp.local ~]$ brew uninstall imagemagick [massat@massat-mbp.local ~]$ brew install imagemagick [massat@massat-mbp.local ~]$ sudo MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp" CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" LDFLAGS="-arch i386 -arch x86_64 -bind_at_load" /Applications/MAMP/bin/php5/bin/pecl install imagick
したら、動いたー。
[massat@massat-mbp.local ~]$ /Applications/MAMP/bin/php5/bin/php -i | grep imagick imagick imagick module => enabled imagick module version => 3.0.1 imagick classes => Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator imagick.locale_fix => 0 => 0 imagick.progress_monitor => 0 => 0
これ解決するのに3時間ほどかかってしまった・・・。
作業履歴をとるのにscriptコマンドが便利
http://archive.linux.or.jp/JM/html/util-linux/man1/script.1.html
作業の履歴を保存するのに便利。
$ script -a install-log.txt
MAMP on Snow Leopard環境にてPHPモジュールをインストールするときにいちいちハマるのでメモ
MAMPに載ってるPHPが64bit環境に対応していないことでいちいちハマるのでメモ。
ぼやっとインストールすると実行時に
PHP Warning: PHP Startup: Unable to load dynamic library '/Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20060613/imagick.so' - (null) in Unknown on line 0
とか言われて冷や汗かく。
こちらでSnow Leopard上のMAMPにImageMagikを苦労してインストールしてくれている。
あとモジュールを追加したりしだすと、依存ライブラリが必要になったりしてくる。
MacPorts使って入れる場合には、UniversalBinaryがビルドされるような設定にしておく必要がある。
/opt/local/etc/macports/variants.conf に、
+universal
と書いておく。