2011年5月7日土曜日

[Deploy][Mac] Capistranoセットアップ

自宅MacにCapistranoをインストールして、いろいろやってみようという試み。

CapistranoはRubyで動作する有名なデプロイツール。インストールはgemを使用する。

インストール前にgemをアップデート。
$sudo gem update --system
Password:
Updating RubyGems
Updating rubygems-update
Successfully installed rubygems-update-1.8.4
Updating RubyGems to 1.8.4
Installing RubyGems 1.8.4
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/commands/update_command.rb:153: warning: Insecure world writable dir /usr/local/share in PATH, mode 040777
RubyGems 1.8.4 installed

=== 1.8.4 / 2011-05-25

* 1 minor enhancement:

* Removed default_executable deprecations from Specification.


------------------------------------------------------------------------------

RubyGems installed the following executables:
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/gem

次にcapistranoがインストールされていないことを確認する。
$gem list capistrano

*** LOCAL GEMS ***

上記の場合はインストールされていない。
続けてインストールコマンドを実行する。
$sudo gem install capistrano
Password:
Fetching: highline-1.6.2.gem (100%)
Fetching: net-ssh-2.1.4.gem (100%)
Fetching: net-sftp-2.0.5.gem (100%)
Fetching: net-scp-1.0.4.gem (100%)
Fetching: net-ssh-gateway-1.1.0.gem (100%)
Fetching: capistrano-2.6.0.gem (100%)
Successfully installed highline-1.6.2
Successfully installed net-ssh-2.1.4
Successfully installed net-sftp-2.0.5
Successfully installed net-scp-1.0.4
Successfully installed net-ssh-gateway-1.1.0
Successfully installed capistrano-2.6.0
6 gems installed
Installing ri documentation for highline-1.6.2...
Installing ri documentation for net-ssh-2.1.4...
Installing ri documentation for net-sftp-2.0.5...
Installing ri documentation for net-scp-1.0.4...
Installing ri documentation for net-ssh-gateway-1.1.0...
Installing ri documentation for capistrano-2.6.0...
Installing RDoc documentation for highline-1.6.2...
Installing RDoc documentation for net-ssh-2.1.4...
Installing RDoc documentation for net-sftp-2.0.5...
Installing RDoc documentation for net-scp-1.0.4...
Installing RDoc documentation for net-ssh-gateway-1.1.0...
Installing RDoc documentation for capistrano-2.6.0...

capistranoのバージョンを確認する。
以下のようにバージョンが表示されれば正常にインストールされている。
$cap --version
Capistrano v2.6.0

次にsshの準備を行う。
すでに作成済みの公開鍵をデプロイ対象のサーバにアップロードする。
※未作成の場合は$ssh-keygenを実行し鍵を作成する。

今回はVM上に構築したCentOS環境にアップロードします。
$scp -p .ssh/id_rsa.pub radengineer@192.168.251.131:~
radengineer@192.168.251.131's password:
id_rsa.pub 100% 410 0.4KB/s 00:00

公開鍵を配置
$ mkdir -m 700 .ssh
$ cat id_rsa.pub >> .ssh/authorized_keys

また、デプロイ用に共有アカウントを用意します。
$ sudo /usr/sbin/useradd -m app
$ sudo -u app mkdir -m 700 /home/app/.ssh
$ sudo -u app touch /home/app/.ssh/authorized_keys
$ sudo sh -c "cat id_rsa.pub >> /home/app/.ssh/authorized_keys"

リモートログイン時のパスフェイズ入力を省略する為の設定を行う。
$ ssh-agent bash
$ ssh-add
Enter passphrase for /Users/Radengineer/.ssh/id_rsa:
Identity added: /Users/Radengineer/.ssh/id_rsa (/Users/Radengineer/.ssh/id_rsa)

公開鍵で本番サーバにログインする。
$ ssh 192.168.251.131
$ ssh app@192.168.251.131
パスワードなしでログインできれば設定完了。


以上です。

0 件のコメント:

コメントを投稿