LoginSignup
11
10

More than 5 years have passed since last update.

chef-zero導入

Posted at

目的

開発用にvagrantを使用してchef-zeroでchef-workstaionを構築する。

環境

  • Windows7 Professional
  • Vagrant 1.7.2
  • CentOS Linux release 7.0.1406 (Core)
  • Amazon Linux AMI release 2015.03

イメージ

image.jpg

設定

chef-zeroインストール

$ wget https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chefdk-0.3.5-1.x86_64.rpm
$ sudo rpm -Uvh chefdk-0.3.5-1.x86_64.rpm
$ sudo chef gem install knife-zero

レポジトリ作成

$ chef generate repo chef-repo
$ cd chef-repo

クックブック作成

$ knife cookbook create nginx

レシピ作成

とりあえず、ノードにnginxをインストール。
$nano ~/chef-repo/cookbooks/nginx/recipes/default.rb

~/chef-repo/cookbooks/nginx/recipes/default.rb
package "nginx" do
  action :install
end

service "nginx" do
  supports :status => true, :restart => true, :reload => true
  action [ :enable, :start ]
end

ノード初期化

ノードにchefがインストールされ、workstationのnodeへ初期化したノードが定義される。
workstationで管理しやすいよう、--node-nameで指定した文字列をnodenameに設定できる。
$ sudo knife zero bootstrap ノードGIP|FQDN -x ec2-user --node-name node1 -i ~/.ssh/秘密鍵

レポジトリで使用するknife.rb作成

~/chef-repo/knife.rb
#-z、--localモード
#ローカルモードでシェフクライアントを実行するために使用します。
local_mode true
chef_server_url   'http://Workstation-IP:8889'
node_name         'Workstation-nodename'
client_key        '~/.ssh/ノードに接続する際の秘密鍵'

ノードにレシピ定義

$ knife node run_list add node1 'recipe[nginx]'

ノードにレシピ適用

$ sudo knife zero chef_client 'name:node1' -x ec2-user -i ~~/.ssh/秘密鍵

ノードにて確認

$ rpm -qa nginx $$ chef;ps aux | grep nginx
chef-11.18.12-1.el6.x86_64
nginx-1.6.2-1.23.amzn1.x86_64
root     28272  0.0  0.2 109516  2088 ?        Ss   11:17   0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx    28276  0.0  0.3 109936  3224 ?        S    11:17   0:00 nginx: worker process
ec2-user 28294  0.0  0.0 110404   856 pts/0    S+   11:22   0:00 grep nginx

nginx.JPG


commit

>vagrant sandbox commit
[default] Committing the virtual machine...
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
11
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
10