windows+CygwinでChef - 7.berkshelf導入編
さて、前回すっごい苦労しながら、berkshelfを入れたので、
今回は、Berkshelfを使って簡単セットアップをやってみたいと思います。
Windos+Chef入門目次を作成しました!
参考にしたサイト
BerkshelfとChefのインストールに苦労した話 - DQNEO起業日記
WindowsでのBerkshelfのインストール成功 | 5丁目通信(仮称)
64bit 版で gem install ffi すると native extension のコンパイルに失敗する件の回避方法 - msfukuiの日記
実行環境の用意について
前回の記事で実行環境を用意しましたが、一応おさらいって事で、書いておきたいと思います。
$ mkdir chef_13 $ cd ./chef_13 $ vagrant init centos6.5 $ vagrant up #鍵認証 $ vagrant ssh-config --host chef_13 >> ~/.ssh/config #接続テスト $ ssh chef_13 Welcome to your Vagrant-built virtual machine. [vagrant@localhost ~]$ exit logout Connection to 127.0.0.1 closed. #リポジトリの作成と仮想マシンにchefを用意 $ knife solo init berktest $ cd berktest $ knife solo prepare chef_13
Berkshelfの使い方
使用したいcookbookを定義するBerksfileを修正していきます。
opscodeから、nginxを使う場合は、以下のように記述していきます。
cookbookのmetadata.rbに定義された依存パッケージも一緒に落としてきてくれます。
$ cat Berksfile site :opscode cookbook "nginx", "~> 2.6"
記述後、以下のようにコマンドを実行します。
$ berks install DL is deprecated, please use Fiddle Installing nginx (2.7.4) from site: 'http://cookbooks.opscode.com/api/v1/cookbooks' Installing apt (2.4.0) from site: 'http://cookbooks.opscode.com/api/v1/cookbooks' Installing bluepill (2.3.1) from site: 'http://cookbooks.opscode.com/api/v1/cookbooks' Installing rsyslog (1.12.2) from site: 'http://cookbooks.opscode.com/api/v1/cookbooks' Installing build-essential (2.0.4) from site: 'http://cookbooks.opscode.com/api/v1/cookbooks' Installing ohai (2.0.0) from site: 'http://cookbooks.opscode.com/api/v1/cookbooks' Installing runit (1.5.10) from site: 'http://cookbooks.opscode.com/api/v1/cookbooks' Installing yum (3.2.0) from site: 'http://cookbooks.opscode.com/api/v1/cookbooks' Installing yum-epel (0.3.6) from site: 'http://cookbooks.opscode.com/api/v1/cookbooks'
nginxをインストールしただけなのに、依存関係のものも入れられたようです。
今取得したファイルは、「Berksfile.lock」というファイルが作成され、そこに記載されていました。
次に、nodesに使用したいレシピに記載します。
{ "run_list":[ "recipe[nginx]" ] }
cookを実行します!
$ knife solo cook chef_13 Running Chef on chef_13... Checking Chef version... DL is deprecated, please use Fiddle Installing Berkshelf cookbooks to 'cookbooks'... Using nginx (2.7.4) Using apt (2.4.0) Using bluepill (2.3.1) Using rsyslog (1.12.2) Using build-essential (2.0.4) Using ohai (2.0.0) Using runit (1.5.10) Using yum (3.2.0) Using yum-epel (0.3.6) ・・・中略・・・・ Starting Chef Client, version 11.12.4 Compiling Cookbooks... Recipe: ohai::default * remote_directory[/etc/chef/ohai_plugins] action create ・・・中略・・・ Recipe: nginx::ohai_plugin * ohai[reload_nginx] action nothing (skipped due to action :nothing) * template[/etc/chef/ohai_plugins/nginx.rb] action create - create new file /etc/chef/ohai_plugins/nginx.rb - update content in file /etc/chef/ohai_plugins/nginx.rb from none to 9f7e82 ・・・中略・・・ Recipe: nginx::default * service[nginx] action start - start service service[nginx] * service[nginx] action reload - reload service service[nginx] Running handlers: Running handlers complete
完了したようです!
確認しておきたいと思います。
$ vagrant ssh Last login: Sat Jun 7 04:37:26 2014 from 10.0.2.2 Welcome to your Vagrant-built virtual machine. [vagrant@localhost ~]$ service nginx status nginx (pid 3121) is running...
おおー・・・・w
これかなり簡単だなぁ・・・w
バージョンを指定していれる事も可能だそうです!
IPtablesの問題で、アクセスできなかったんですが、「service iptables stop」で
ブラウザからのアクセスも確認出来ました!
はい!今回の目的は、berkshelfを触ってみるってだけだったので、
このあたりで終わりにしたいと思います。
今後、開発サーバーを作成するときは、berkshelfを使っていけたら
かなりchefの開発時間の短縮になりそうですね!
長々とChefについて書いてきましたが、今回で一旦入門編は終了したいと思います!
この他にも色々試したいものがあるんです!
次は何やろうかなぁ~・・・
使用環境
- ホストOS: Windows7 x64
- Cygwin : Cygwin64
- VirtualBox: 4.3.10
- Vagrant: 1.5.2
- Chef : 11.12.4
- knife-solo:0.4.1