以下のコマンドでファイルを編集する。
vi /etc/rc.d/rc.local
以下のような記述があると思う。
touch /var/lock/subsys/local
最終行に起動時に実行したいコマンドを記述する。
ulimit -n 32768 /home/hogehoge/fugafuga/check.sh > /home/hogehoge/fugafuga/result.txt &
以下のコマンドでファイルを編集する。
vi /etc/rc.d/rc.local
以下のような記述があると思う。
touch /var/lock/subsys/local
最終行に起動時に実行したいコマンドを記述する。
ulimit -n 32768 /home/hogehoge/fugafuga/check.sh > /home/hogehoge/fugafuga/result.txt &
そーいやmacで使ってなかったので一応メモ。
cd ~/.ssh ssh-keygen -t rsa -C "user@hogehoge.com" Generating public/private rsa key pair. Enter file in which to save the key (/var/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /var/root/.ssh/id_rsa. Your public key has been saved in /var/root/.ssh/id_rsa.pub.
以下のコマンドで内容をメモる。
vi id_rsa.pub
Account Settingsのキーの方にペーストする。
ssh -T git@github.com Hi hogehoge! You've successfully authenticated, but GitHub does not provide shell access.
以下のコマンドでapacheを再起動する。
/etc/init.d/httpd restart
以下のようなメッセージが表示されて再起動できなくなる。
Starting httpd: (98)Address already in use: make_sock: could not bind to address [::]:80
以下のコマンドでポートを使用しているプロセスを調べる。
/usr/sbin/lsof -i | grep http
プロセス番号が表示されるのでkillする。
バッチ処理したい時などに使う技である。
以下のようにしてShellクラスを継承する。基本的にはコントローラと同様にモデルなどが使用できるがコンポーネントについては注意が必要である。
date_default_timezone_set('Asia/Tokyo'); //Configure::write('Config.environment', isset($_SERVER['CAKE_ENV']) ? $_SERVER['CAKE_ENV'] : "development");// コマンドラインから叩いている場合、$_SERVERによる環境分岐ができない Configure::write('Config.environment', "production"); class RankShell extends Shell { public $uses = array( 'Logs', 'Ranks' ); /** * 処理を実行する前に読み込むコンポーネントなどを記述する */ public function initialize() { parent::initialize(); //$this->Email = new EmailComponent($this);// コンポーネント名に注意 } /** * ここに記述した処理が実行される */ public function main() { $this->out("start"); if($result = $this->Log->getRank()){ $this->Ranks->deleteAll(); if($this->Ranks->saveAll($result)){ $this->out("success"); } else{ $this->out("failed to save"); } } else{ $this->out("failed to calc"); } } }
以下のようにして実行できるかどうか確認する。
/usr/bin/php /var/www/hogehoge.justoneplanet.info/cake/console/cake.php calc
以下のコマンドを実行してcrontabを編集する。
crontab -e
例えば10時のオヤツを忘れないよう10:15に実行するようにするには以下のようにする。
15 10 * * * /usr/bin/php /var/www/hogehoge.justoneplanet.info/cake/console/cake.php calc
15分ごとに処理をするには以下のように記述する。
*/15 * * * * /usr/bin/php /var/www/hogehoge.justoneplanet.info/cake/console/cake.php calc
以上のようにCakePHPでは非常に簡単にバッチ処理を書くことができる。個人的にはZendFrameworkよりも簡単に感じる。
yum install gcc make wget http://prdownloads.sourceforge.net/gauche/Gauche-0.9.1.tgz tar xvzf Gauche-0.9.1.tgz cd Gauche-0.9.1 ./configure make make install
vi /home/pywebsocket-0.5.2/src/mod_pywebsocket/standalone.py
以下の部分を
parser.add_option('--allow-draft75', dest='allow_draft75', action='store_true', default=False, help='Allow draft 75 handshake')
以下のように変更する。
parser.add_option('--allow-draft75', dest='allow_draft75', action='store_true', default=True, help='Allow draft 75 handshake')
python /home/pywebsocket-0.5.2/src/mod_pywebsocket/standalone.py -p 8800 -d /home/pywebsocket-0.5.2/src/example
WebSocketで8800ポートにアクセスする。(●´ω`●)
yum install http-devel
wget http://archive.apache.org/dist/httpd/modpython/mod_python-3.3.1.tgz tar xvzf mod_python-3.3.1.tgz cd mod_python-3.3.1 ./configure –with-apxs=/usr/sbin/apxs –with-python=/usr/bin/python make make install
vi /etc/httpd/conf.d/python.conf
以下の記述の下に
LoadModule python_module modules/mod_python.so
以下の記述を付加する。
AddHandler mod_python .py
wget http://pywebsocket.googlecode.com/files/mod_pywebsocket-0.5.2.tar.gz tar xvzf mod_pywebsocket-0.5.2 cd pywebsocket-0.5.2/src python setup.py build python setup.py install
vi /etc/httpd/conf.d/python_mod_pywebsocket.conf
以下を記述する。
<IfModule python_module> PythonPath "sys.path+['/usr/lib/python2.4/site-packages/']" PythonOption mod_pywebsocket.handler_root /var/www/html/wsh PythonHeaderParserHandler mod_pywebsocket.headerparserhandler PythonOption mod_pywebsocket.allow_draft75 On </IfModule>
/etc/init.d/httpd restart
cp /home/pywebsocket-0.5.2/src/example/echo_wsh.py /var/www/html/wsh/
WebSocketクライアントで/echoにアクセスする。(●´ω`●)
正確性は微妙だが100クライアントからの接続でのロードアベレージは、「node : pywebsoket(standalone) : pywebsoket(apache) = 0.15 : 0.25 : 0.8」となった。最初の2つの差は微妙だったが、Apacheモジュールとして動作させた時のリソースの消費量は明らかに大きいようだ。
前回に引き続きWebSocketサーバをたてる。今回はAmazon EC2を使用する。
sudo passwd root
rootのパスワードを設定したら以下のコマンドを実行する。
su yum install openssl-devel gcc-c++ make wget http://nodejs.org/dist/node-v0.4.3.tar.gz tar xvzf node-v0.4.3.tar.gz cd node-v0.4.3 ./configure make make install curl http://npmjs.org/install.sh | sh npm install websocket-server npm install base64
使用しているインスタンスによって、makeは時間がかかるので10分では無理。(๑°⌓°๑)
以下のようにnaveを使ってインストールする手法もある。
su yum install openssl-devel gcc-c++ git make git clone https://github.com/isaacs/nave.git ~/.nave ~/.nave/nave.sh install latest ~/.nave/nave.sh use latest echo "~/.nave/nave.sh use latest" >> ~/.bash_profile curl http://npmjs.org/install.sh | sh npm install websocket-server npm install base64
残念ながらmicroインスタンスでコンパイルすると負荷が高すぎて途中終了してしまった。Largeでコンパイルすればサクっと終わる。
会社で同僚に教えてもらった。
nvmを使えばnpmも同時にインストールできる。
su yum install openssl-devel gcc-c++ git make git clone git://github.com/creationix/nvm.git ~/.nvm source ~/.nvm/nvm.sh echo "~/.nvm/nvm.sh" >> ~/.bash_profile echo "nvm use v0.4.8" >> ~/.bash_profile nvm sync nvm install v0.4.8 npm install websocket-server npm install base64
smallインスタンスたどコンパイルに時間がかかる。
話が前後するがアカウントの作成からだと流石に10分は無理。作成方法については以下を参照すると良い。
コマンドラインツールを使用するにはX.509 証明書が必要。基本的にはコントロールパネルから操作が可能。インスタンスを起動させるフローで証明書(鍵)がダウンロードできる。SSHはその鍵で接続する。そんな感じ。(。・ω・)ノ゙
以下のコマンドを実行しツールをインストールする。
npm install node-dev #ファイルを変更すると再実行 npm install node-inspector #Developer Tool npm install cloud9 #IDE
たぶん10分くらいで可能。
yum install openssl-devel wget http://nodejs.org/dist/node-v0.4.3.tar.gz tar xvzf node-v0.4.3.tar.gz cd node-v0.4.3 ./configure make make install curl http://npmjs.org/install.sh | sh npm install websocket-server npm install base64
make中は一休みできる(●´ω`●)
websocket-serverは新しいWebSocketの仕様に対応してないのでwebsocketを使用する。
yum install openssl-devel gcc-c++ make wget http://nodejs.org/dist/v0.6.8/node-v0.6.8.tar.gz tar xvzf node-v0.6.8.tar.gz cd node-v0.6.8 ./configure make make install curl http://npmjs.org/install.sh | sh npm install websocket
以下のコマンドで軽く設定してiptablesの設定ファイルを生成しておく。
system-config-firewall-tui
実際の設定は以下のコマンドを実行して行う。
vim /etc/sysconfig/iptables /etc/init.d/iptables restart vim /etc/sysconfig/ip6tables /etc/init.d/ip6tables restart
naveを使ってnodeをインストールする。
sudo yum -y install openssl-devel gcc-c++ git make git clone https://github.com/isaacs/nave.git ~/.nave ~/.nave/nave.sh install stable ~/.nave/nave.sh use stable echo "~/.nave/nave.sh use stable" >> ~/.bash_profile sudo curl https://npmjs.org/install.sh --insecure | sh npm -g install forever
以下のようなファイルが存在するとする。
lib.a
以下のコマンドを実行し元のファイル名に分解できる。
ar -t lib.a
但しファイルによっては以下のように表示される。
ar: lib.a is a fat file (use libtool(1) or lipo(1) and ar(1) on it)
アーカイブには複数のアーキテクチャ用のコードが含まれているためであり、以下のコマンドを実行して単一のアーキテクチャのファイルを抽出した後、arコマンドを実行する。
lipo lib.a -thin armv6 -output libarm6.a ar -t libarm6.a
wget http://mirrors.kernel.org/gnu/hello/hello-2.7.tar.gz tar xvzf hello-2.7.tar.gz cd hello-2.7 ./configure --help=short
以下のように表示される。
Configuration of GNU Hello 2.7: Optional Features: --disable-option-checking ignore unrecognized --enable/--with options --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] --disable-dependency-tracking speeds up one-time build --enable-dependency-tracking do not reject slow dependency extractors --disable-nls do not use Native Language Support --disable-rpath do not hardcode runtime library paths Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-gnu-ld assume the C compiler uses GNU ld default=no --with-libiconv-prefix[=DIR] search for libiconv in DIR/include and DIR/lib --without-libiconv-prefix don't search for libiconv in includedir and libdir --with-libintl-prefix[=DIR] search for libintl in DIR/include and DIR/lib --without-libintl-prefix don't search for libintl in includedir and libdir Some influential environment variables: CC C compiler command CFLAGS C compiler flags LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a nonstandard directory <lib dir> LIBS libraries to pass to the linker, e.g. -l<library> CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if you have headers in a nonstandard directory <include dir> CPP C preprocessor Use these variables to override the choices made by `configure' or to help it to find libraries and programs with nonstandard names/locations. Report bugs to <bug-hello@gnu.org>. GNU Hello home page: <http://www.gnu.org/software/hello/>. General help using GNU software: <http://www.gnu.org/gethelp/>.
ふむふむ。
./configure --prefix=/opt/hello-2.7 make sudo make install
以下のコマンドを実行する。
hello
以下のように表示される。
Hello, world!
以下のコマンドを実行する。
env LANG=ja_JP.UTF-8 hello
以下のように表示される。
世界よ、こんにちは!