LoginSignup
16
16

More than 5 years have passed since last update.

EC2でChefサーバをたてる

Last updated at Posted at 2013-07-04

参考

Install Chef Server 11.x
http://docs.opscode.com/install_server.html

入門 Chef Server #biglobetechtalk
http://www.slideshare.net/biglobedojo/chefserver-rev100

Chef を始める #1 – 概要、Chef Server を EC2 上にインストール、Workstation の設定まで
http://dev.classmethod.jp/server-side/chef-server-install/

環境

Chefサーバ

m1.smallインスタンス
ubuntu server 12.04
Chef 11.4.4

workstation

Mac OS X Lion

Chef Server構築

準備

AWSでインスタンス作成(t1.microだとメモリ不足で落ちた)

  • ElasticIPをつけておく(任意)
  • WebUIにアクセスするためsecurity groupの設定でhttpsアクセス出来るようにしておく
  • ホスト名で名前解決出来るようにしておく(重要)
$ sudo hostname <Public DNS名>
$ sudo vi /etc/hostname

設定とテスト

ホスト名で名前解決出来るようになってないとここでコケます

$ sudo chef-server-ctl reconfigure
$ sudo chef-server-ctl test

t1.microインスタンスでやったらメモリ不足で失敗したので

[2013-06-20T23:21:00+00:00] FATAL: Stacktrace dumped to /opt/chef-server/embedded/cookbooks/cache/chef-stacktrace.out
[2013-06-20T23:21:00+00:00] FATAL: Errno::ENOMEM: execute[/opt/chef-server/embedded/bin/createdb -T template0 -E UTF-8 opscode_chef] (chef-server::postgresql line 141) had an error: Errno::ENOMEM: Cannot allocate memory - fork(2)

m1.smallに変更してもう一度reconfigureとtest

成功すると色々テストして最後にこんな感じになる

Finished in 1 minute 25.08 seconds
70 examples, 0 failures

起動したり停止したり

$ sudo chef-server-ctl start
$ sudo chef-server-ctl stop

WebUIにアクセス

https://<Public DNS名>

kobito.1371870335.891591.png

Work Stationセットアップ

インストール

手元のmacをwork stationにします

$ curl -L https://www.opscode.com/chef/install.sh | sudo bash
$ echo 'export PATH="/opt/chef/embedded/bin:$PATH"' >> ~/.bash_profile && source ~/.bash_profile
  • chef-validator.pem
  • admin.pem が必要

/etc/chef-server/admin.pem
/etc/chef-server/chef-validator.pem
Chefサーバから持って来てworkstationの
~/chef-repo/.chef
あたりのディレクトリ下に置く

knife configureコマンドでknife.rbファイルを作成

成功するとこんな感じ

$ cd ~/chef-repo
$ knife configure -i
WARNING: No knife configuration file found
Where should I put the config file? [/Users/<user>/.chef/knife.rb] /Users/<user>/chef-repo/.chef/knife.rb
Please enter the chef server URL: [http://mac.local:4000] https://<chef-serverのURL>
Please enter a name for the new user: [<user>]
Please enter the existing admin name: [admin]
Please enter the location of the existing admin's private key: [/etc/chef/admin.pem] /Users/<user>/chef-repo/.chef/admin.pem
Please enter the validation clientname: [chef-validator]
Please enter the location of the validation key: [/etc/chef/validation.pem] /Users/<user>/chef-repo/.chef/chef-validator.pem
Please enter the path to a chef repository (or leave blank):
Creating initial API user...
Please enter a password for the new user:
Created user[<user>]
Configuration file written to /Users/<user>/chef-repo/.chef/knife.rb
$

Nodeの登録

t1.microインスタンス作ってNodeとして登録してみる

chef-clientインストール

$ sudo true && curl -L https://www.opscode.com/chef/install.sh | sudo bash
$ sudo mkdir /etc/chef && cd /etc/chef
$ sudo knife configure client -s https://<chef-serverのURL> ./

client.rbとvalidation.pemが作られる

validation.pemはchefサーバのchef-validator.pemの中身をコピペ

client.rbにnode_nameを追記

$ cat client.rb 
log_level        :info
log_location     STDOUT
chef_server_url  'https://<chef-serverのURL>'
validation_client_name 'chef-validator'
node_name 'sample_node'
$

chef-client実行

$sudo chef-client -c client.rb

sample_nodeが登録されます

試してみる

サンプルcookbookのgetting-startedとってきて試す
(ホームディレクトリにchef-getting-started.txtを作成するだけのパッケージ)

$ cd ~/chef-repo/cookbooks/
$ git clone https://github.com/opscode-cookbooks/getting-started
$ knife cookbook upload getting-started -o .
Uploading getting-started [0.4.0]
Uploaded 1 cookbook.
$

RunList設定

$ knife node run_list add sample_node "recipe[getting-started]"

Node上でclientコマンド実行

$ sudo chef-client
$ cat chef-getting-started.txt 
Welcome to Chef!

This is Chef version 11.4.4.
Running on mac_os_x.
Version 10.7.5.
$

反映されました

雑感

  • よくわかっていなかったのでいきなりサーバ立てて試したけど ちょっとした用途ならchef-soloかhosted chefでいいのかも
  • Nodeのセットアップ(chef-clientインストールしてchef-validator.pemをコピー)が面倒なので何か工夫したい
  • Nodeの細かい情報(OS, HW情報,各種設定)がChefサーバに集約されるのが地味に楽しい
16
16
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
16
16