2011年5月31日火曜日

[Ruby] gem updateがエラーとなった場合の対応

■概要
gem updateのエラーごとの対応をまとめていく

1.Proxy認証エラー
$ gem update --system
Updating RubyGems
ERROR: http://gems.rubyforge.org/ does not appear to be a repository
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
Errno::ECONNREFUSED: 対象のコンピュータによって拒否されたため、接続できませ
んでした。 - connect(2) (http://gems.rubyforge.org/yaml)

Proxy認証を通すコマンドは以下の通り
gem update --system --http-proxy http://User:Passward@Proxy_Server:Port_No

以上です。

2011年5月11日水曜日

[Deploy][Mac] Capistranoコマンド試行

前回、Capistranoをセットアップしました。
[Deploy][Mac] Capistranoセットアップ

今回は実際にコマンドを発行してみます。

まずローカルでCapfileという設定ファイルを作成します。
ファイルはどこで作成しても問題ありません。

$ vim Capfile
set :user, 'app' // 実行ユーザを指定。ここでは前回作成したappユーザを指定します。
task :diskcheck, :hosts => "192.168.251.131" do // タスク名と実行ホストを指定。
run "df -kh" // 実行コマンドを指定。ここではリモートサーバのディスク使用量を確認するコマンドを指定してみます。
end

Capfileを作成したら、実際にコマンドを発行してみます。
$cap diskcheck
* executing `diskcheck'
* executing "df -kh"
servers: ["192.168.251.131"]
[192.168.251.131] executing command
** [out :: 192.168.251.131] Filesystem サイズ 使用 残り 使用% マウント位置
** [out :: 192.168.251.131] /dev/mapper/VolGroup00-LogVol00
** [out :: 192.168.251.131] 18G 5.9G 11G 36% /
** [out :: 192.168.251.131] /dev/sda1 99M 12M 82M 13% /boot
** [out :: 192.168.251.131] tmpfs 506M 0 506M 0% /dev/shm
command finished in 130ms

対応するタスクが実行され、リモートサーバのディスク使用量を確認することができました。

Capistranoにはデプロイ用のタスクが予め多数用意されていて、それを使用することでデプロイを容易に行うことができます。
次回からはデプロイ用タスクを掘り下げて行きます。


以上です。

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
パスワードなしでログインできれば設定完了。


以上です。