« Nokon 取り付け終了 | メイン | Capistrano を使ってみる 定常作業の自動化 »
2009年5月19日
Capistrano を使ってみる
最近、管理する台数が多くてデプロイツールが必要になってきていろいろしています。
puppet も検討にいれていたが、クライアント(Web,DB サーバ)にruby,puppet をインストールする
かと思うと気が遠くなる...
Capistrano は管理サーバに設定をすれば良いので管理は楽です。
ただし、管理するクライアントのユーザとパスワードをある程度統一されている必要がある。
とりあえず、ntp の再起動と、その後のntpq -p の確認までの手順。
Cent OS 5.x で行いました。
[管理サーバ]
ruby-1.8.7-p160.tar.bz2
rubygems-1.3.3.tgz
を用意します。
bzip2 -d ruby-1.8.7-p160.tar.bz2
tar xvf ruby-1.8.7-p160.tar
cd ruby-1.8.7-p160
./configure
./make
./make install
tar xvzf rubygems-1.3.3.tgz
ruby setup.rb
gem install capistrano
/root/deploy.rb
set :application, "ntp restart"
set :user, "hideki"
set :password, "hogehoge"
set :use_sudo, false
role :hoge1, "192.168.2.1"
role :hoge2, "192.168.2.2"
task :restart, :roles =>[:hoge1, :hoge2] do
sudo "/etc/init.d/ntpd restart;"
sudo "/usr/sbin/ntpq -p"
end
task :start, :roles =>[:hoge1, :hoge2] do
sudo "/etc/init.d/ntpd start;"
sudo "/usr/sbin/ntpq -p"
end
task :stop, :roles =>[:hoge1, :hoge2] do
sudo "/etc/init.d/ntpd stop;"
sudo "/usr/sbin/ntpq -p"
end
[ログイン先のサーバ]
/etc/sudoers
hideki ALL=(ALL) ALL
[管理サーバ]
cap -f deploy.rb restart
[root@localhost ~]# cap -f deploy.rb restart
* executing `restart'
* executing "sudo -p 'sudo password: ' /etc/init.d/ntpd restart;"
servers: ["192.168.2.1"]
[192.168.2.1] executing command
*** [err :: 192.168.2.1]
** [out :: 192.168.2.1] Shutting down ntpd:
** [out :: 192.168.2.1] [
** [out :: 192.168.2.1] OK
** [out :: 192.168.2.1] ]
** [out :: 192.168.2.1]
** [out :: 192.168.2.1] Starting ntpd:
** [out :: 192.168.2.1] [ OK ]
command finished
* executing "sudo -p 'sudo password: ' /usr/sbin/ntpq -p"
servers: ["192.168.2.1"]
[192.168.2.1] executing command
** [out :: 192.168.2.1] remote refid st t when poll reach delay offset jitter
** [out :: 192.168.2.1] =====================================================================
** [out :: 192.168.2.1] ntp1.jst.mfeed. .INIT. 16 u - 64 0 0.000 0.000 4000.00
** [out :: 192.168.2.1] ntp2.jst.mfeed. .INIT. 16 u - 64 0 0.000 0.000 4000.00
** [out :: 192.168.2.1] ntp3.jst.mfeed. .INIT. 16 u - 64 0 0.000 0.000 4000.00
command finished
と出力されればおkです。role などをうまく利用してグループ操作をすれば簡易化できそうです。
参考記事
http://www.howgry.com/page/view/id/56
http://doruby.kbmj.com/tacchi_on_rails/20080725/capistrano_1
投稿者 hideki : 2009年5月19日 00:08
トラックバック
このエントリーのトラックバックURL:
http://zephel.com/hideki/cgi-bin/mt/mt-tb.fcgi/2564