ソフトウェアの導入
まずRubyと必要なパッケージを導入しておく。
# yum install gcc make ruby rubygems ruby-devel ruby-ri ruby-rdoc
次にcapistranoを導入する。
# gem install capistrano --no-rdoc --no-ri
# gem install capistrano_colors --no-rdoc --no-ri
# gem install capistrano-ext --no-rdoc --no-ri
# gem list
*** LOCAL GEMS *** capistrano (2.13.4) capistrano-ext (1.2.1) capistrano_colors (0.5.5) highline (1.6.15) jruby-pageant (1.1.1) net-scp (1.0.4) net-sftp (2.0.5) net-ssh (2.6.0) net-ssh-gateway (1.1.0)
これでcapistranoを実行する準備ができた。
# cap -h
Usage: cap [options] action ...
-d, --debug Prompts before each remote command execution.
-e, --explain TASK Displays help (if available) for the task.
-F, --default-config Always use default config, even with -f.
-f, --file FILE A recipe file to load. May be given more than once.
-H, --long-help Explain these options and environment variables.
-h, --help Display this help message.
-l [STDERR|STDOUT|file] Choose logger method. STDERR used by default.
--logger
-n, --dry-run Prints out commands without running them.
-p, --password Immediately prompt for the password.
-q, --quiet Make the output as quiet as possible.
-r, --preserve-roles Preserve task roles
-S, --set-before NAME=VALUE Set a variable before the recipes are loaded.
-s, --set NAME=VALUE Set a variable after the recipes are loaded.
-T, --tasks [PATTERN] List all tasks (matching optional PATTERN) in the loaded recipe files.
-t, --tool Abbreviates the output of -T for tool integration.
-V, --version Display the Capistrano version, and exit.
-v, --verbose Be more verbose. May be given more than once.
-X, --skip-system-config Don't load the system config file (capistrano.conf)
-x, --skip-user-config Don't load the user config file (.caprc)
sshの認証設定
capistrano を使うためには管理対象ノードに対して、sshで認証なしのアクセスができたほうが便利なので、
capis-host# ssh-keygen -i xxxxx.pub
→ パスワードは空で作成
capis-host# ssh-copy-id -i ~/.ssh/xxxxx.pub username@targethost
としてキーを配布しておく。
やらないと毎回パスワード聞かれるだけなので、そっちが好みなら必要なし。
基本的な使い方
まず適当にレシピを保管するディレクトリを作成する。
# mkdir capis-recipes
# cd capis-recipes
実際にレシピを格納していく方法はいくらでもあるが、自分は以下の構成で使っている。
capis-recipes/ ・・・トップディレクトリ(githubへ登録している) ├── recipe1 ・・・レシピ1 │ ├── Capfile ・・・オプション指定されない場合に最初に読み込まれる │ └── config │ ├── deploy ・・・ capistrano-extで利用できる環境ごとのファイルを置く │ │ ├── common.rb │ │ └── set-bonding.rb │ └── deploy.rb ・・・Capfileから呼び出される。共通設定を記述する。 ├── recipe2 ・・・レシピ2 └── recipe3 ・・・レシピ3
使い方は、実行したいレシピのトップディレクトリへ移動して、
# cd ~/capis-recipes/recipe1
# cap enviroment method
という感じで使っている。
以下はサンプルで、各ノードへchef-solo環境をディプロイするレシピになる。
https://github.com/irixjp/capistrano-recipe
0 件のコメント:
コメントを投稿