@blog.justoneplanet.info

日々勉強

Elastic IPを別のホストに関連付ける

Elastic IPを別のホストに関連付けた後でmacのターミナルからsshでアクセスしようとすると以下のようなエラーが出る。

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
00:88:66:99:77:aa:bb:cc:dd:ee:ff:11:22:33:44:55.
Please contact your system administrator.
Add correct host key in /Users/name/.ssh/known_hosts to get rid of this message.
Offending key in /Users/name/.ssh/known_hosts:7
RSA host key for 123.123.123.123 has changed and you have requested strict checking.
Host key verification failed.

以前に同じ証明書で接続したホストとフィンガープリントが変わっていると警告してくれている。以下のようにして対処する。

ssh-keygen -R 123.123.123.123

CentOSにHaskellを入れる

めも。

■ghc

wget http://www.haskell.org/ghc/dist/7.2.2/ghc-7.2.2-x86_64-unknown-linux.tar.bz2
tar xvfj ghc-7.2.2-x86_64-unknown-linux.tar.bz2
cd ghc-7.2.2
./configure --prefix=/usr/local/haskell/ghc/7.2.2
make install
export PATH=/usr/local/haskell/ghc/7.2.2/bin:$PATH

コーディング

vim hello.hs
main = putStrLn "Hello World"

実行

以下のコマンドでコンパイルと実行が同時にできる。

ghc -e main hello.hs

もしくは以下のコマンドを実行する。

ghc --make hello.hs
./hello

インタプリタ

以下のコマンドで起動する。

ghci

以下のようにしてインストールできる。

Prelude> putStrLn "Hello World"
Hello World

以下のようにしてインタプリタを終了できる。

<ctrl>+D

エラー

<command line>: can't load .so/.DLL for: libgmp.so (libgmp.so: cannot open shared object file: No such file or directory)

以下のコマンドで解決できる。

cd /usr/lib64
ln -s libgmp.so.3 libgmp.so

参考

■hugs

インタプリタ。ghciもあるので必要がないと思われる。

wget http://cvs.haskell.org/Hugs/downloads/2006-09/hugs98-Sep2006.tar.gz
tar xvzf hugs98-Sep2006.tar.gz
cd hugs98-Sep2006
./configure
make
make install

開始

hugs

終了

<ctrl>+D

Hello World

Hugs> putStrLn "Hello World"
Hello World

CentOSにjenkinsをインストールする

以下のコマンドでインストールできる。

yum install java-1.6.0-openjdk
wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
yum install jenkins

デフォルトのJENKINS_HOMEは以下のようになる。

/var/lib/jenkins

■ポート変更

以下のコマンドで設定ファイルを編集する。

vim /etc/sysconfig/jenkins

デフォルトでは8080番を使用しているので以下のように変更する。

JENKINS_PORT="1234"

■起動

/sbin/service jenkins start

以下のアドレスでアクセスできる。


http://localhost:8080/

■セキュリティ

以下のURLにアクセスする。


http://localhost:8080/configure

デフォルトではすべてのユーザが閲覧可能でありジョブを追加することができるので、「セキュリティを有効化」の項目にチェックを入れる。

特定のユーザのみが操作可能にする

Jenkinsのユーザーデータベース

Jenkinsのユーザーデータベースを選択し、ユーザーにサインアップを許可を外して一度保存する。

権限管理

行列による権限設定を選択し、上述で追加したユーザ名に対して全権限を与える。また、匿名ユーザには必要な権限だけ付加する。

Unixユーザを使用した管理の方が便利かもしれない。

■E-mail通知

以下のURLにアクセスする。


http://localhost:8080/configure

SMTP認証にチェックを入れ以下のように入力する。

SMTPサーバー
mail.example.com
E-mailのサフィックス
@example.com
送信元メールアドレス
john@sample.com
ユーザ名
mike
パスワード
mike’s_pasword
SMTPポート
587

メールを送信して設定を確認にチェックを入れて実際にメールが送信できるか確認する。

■JDKのインストール

以下のURLにアクセスする。


http://localhost:8080/configure

JDKの項目があるので入力して保存する。oracleアカウントが面倒。

■Git連携

以下の画面にアクセスする。


http://localhost:8080/pluginManager/available

Git Pluginを選択し「ダウンロード後に再起動しインストール」を選択する。

gitの設定

http://localhost:8080/job/SampleProject/configure

android

以下にアクセスしてAndroid Emulator Pluginをインストールする。


http://localhost:8080/pluginManager/available

gitで過去のcommitに対してbranchをきる

まず、コミットのハッシュ値を調べる

gitx

gitxを入れていない場合は以下のコマンドで調べる。

git log --all --graph

以下のコマンドで一度チェックアウトしたあとブランチを切った後、元のブランチをチェックアウトする。

git checkout 1234567
git branch -a
git checkout -b forgetbranch
git checkout master

addしてないファイルとかあると少し面倒になる。

reboot時にコマンドを実行する

以下のコマンドでファイルを編集する。

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からgithubを使う

そーいやmacで使ってなかったので一応メモ。

cd ~/.ssh
sh-3.2# 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.

httpd restartでAddress already in useが表示されたとき

以下のコマンドで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する。

crontabとCakePHPでバッチ処理をする

バッチ処理したい時などに使う技である。

■実装

app/vendors/shells/calc.php

以下のようにして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を編集する。

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よりも簡単に感じる。

Gaucheをインストールする

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

pywebsocketをインストールする

■pywebsocket単体で動作させる

draft75

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ポートにアクセスする。(●´ω`●)

■apacheモジュールとして動作させる

http-devel

yum install http-devel

mod_python

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

mod_pywebsocket

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モジュールとして動作させた時のリソースの消費量は明らかに大きいようだ。