CentOS 6.3ã§ã®Chef Soloã®ç°å¢è¨å®
ã¯ããã«
æè¿è©±é¡ã®ï¼ï¼ï¼Chefã®ç°å¢ãCentOS 6.3ä¸ã«æ§ç¯ããã¬ã·ãã®æ¸ãæ¹ã®åºæ¬çãªäºã説æããã
Chef Soloç°å¢æ§ç¯ã«é¢ããå ¬å¼ããã¥ã¡ã³ãã¯こちら
ããã«OSå¥ã®ã¤ã³ã¹ãã¼ã«ããã¥ã¡ã³ããããããCentOSãªã©ã®Red Hatç³»ã¯こちらãåºæ¬ã¯ããã«æ²¿ã£ã¦ãã£ã¦ããããæ¬è¨äºã§ã¯ä¸é¨ããã¨ã¯éãå
容ãããã®ã§æ³¨æã
Chefã®ã¤ã³ã¹ãã¼ã«
RBELã¬ãã¸ããªã¨ããã®ãæå¹ã«ããã
$ sudo rpm -Uvh http://rbel.frameos.org/rbel6
次ã«Rubyé¢é£ã®ããã±ã¼ã¸ãã¤ã³ã¹ãã¼ã«ã
$ sudo yum install ruby ruby-devel ruby-ri ruby-rdoc ruby-shadow gcc gcc-c++ automake autoconf make curl dmidecode
ããã¥ã¡ã³ãã ã¨RubyGemsã¯ã½ã¼ã¹ããå ¥ãããã¨ã«ãªã£ã¦ãããããããyumã§å ¥ããã
$ sudo yum install rubygems
Chefã¯gemçµç±ã§å ¥ãããã¨ã«ãªã£ã¦ãããããããyumã§å ¥ããã
$ sudo yum install rubygem-chef
â»ããã¥ã¡ã³ãã«æ²¿ã£ã¦RubyGemsã¨Chefã¯å¥ã ã®ã³ãã³ãã§å ¥ãããã©ãrubygem-chefã¯rubygemsã«ä¾åãã¦ããã®ã§ãå®éã«ã¯sudo yum install rubygem-chefã ãã§rubygemsãåæã«å ¥ãã
先ほどのドキュメントã§å¿ è¦ãªã®ã¯ããã¾ã§ããã以éã¯Chef Clientã®è¨å®ãªã®ã§ã
Chefã®ã¢ã¼ããã¯ãã£
ããã§Chefã®ã¢ã¼ããã¯ãã£ã«ã¤ãã¦ç°¡åã«èª¬æããããåãã£ã¦ããªãã¨ãããããä½ããã¦ããã®ããåãããªããªãã®ã§ãこちらのページã®ä¸ã®æ¹ã®å³ãåç §ã
ä¾ãã°ãChefã«ãã£ã¦20å°ã®Webãµã¼ãã¼ã¨4å°ã®DBãµã¼ãã¼ã管çããã¨ãããé常ã¯ããã®24å°ã«å ãã¦ãChef Server(1å°)ã¨Workstation(1å°ä»¥ä¸)ãå¿ è¦ã«ãªãã
- Node: Chefã«ãã£ã¦ç®¡çãããã³ã³ãã¥ã¼ã¿ã¼ãããã§ã¯Webãµã¼ãã¼20å°ã¨DBãµã¼ãã¼4å°ã
- Chef Server: ãµã¼ãã¼ã®è¨å®æ å ±(Cookbook)ããNodeã«é¢ããæ å ±ãªã©ãå ¥ã£ã¦ããã
- Chef Client: Nodeã«ã¤ã³ã¹ãã¼ã«ããå¿ è¦ãããããã°ã©ã ãChef Serverããå½ä»¤ãåãåã£ã¦ãå種å¦çãè¡ã(ããã±ã¼ã¸ã®ã¤ã³ã¹ãã¼ã«ãè¨å®ãã¡ã¤ã«ã®æ´æ°ãªã©ãªã©)ã
- Workstation: Cookbookãä½æãã¦Chef Serverã«ã¢ãããã¼ãããããNodeã®è¨å®ãå¤æ´ããããå種管çä½æ¥ãè¡ã端æ«ã
ããããã«ã»ããã®Chefã®æ§æãªãã ãã©ãåããéãããã ã¨å¤§æããã§ãªããªã使ãã®ãé£ããã
ä»å説æããChef Soloã¯ãããåä½ã§å®è¡å¯è½ãªããã¿ãããªã大éæã«è¨ãã¨ã1å°ã®ã³ã³ãã¥ã¼ã¿ã¼ã§Chef Clientã¨Workstationã§å®è¡ãããããªå 容ãå®è¡ããã1å°~æ°å°ã®ã³ã³ãã¥ã¼ã¿ã¼ã管çããå ´åã«ã¯ãã¾ãã¯Chef Soloã§æ軽ã«ç®¡çããã®ãããããã
Chef Soloç¨ã®ç°å¢è¨å®
åºæ¬ã¯こちらã«æ²¿ã£ã¦ãã£ã¦ããããä¸é¨éãé¨åãããã
èªåã®ãã¼ã ãã£ã¬ã¯ããªã«chef-soloã¨ãããã£ã¬ã¯ããªã¼ãä½ã£ã¦ãåºæ¬çã«ã¯å ¨ã¦ããã§ä½æ¥ããããã«ããã
$ mkdir ~/chef-solo
solo.rb
ããã«Chef Soloã使ãããã®è¨å®ãæ¸ãã¦ããã先ほどのドキュメントã 㨠/var/chef-solo 以ä¸ã®ãã£ã¬ã¯ããªã¼ãæå®ãã¦ããããä»åã¯å ã»ã©ä½ã£ã /home/user/chef-solo ãæå®ããã
file_cache_path "/home/k4200/chef-solo" cookbook_path "/home/k4200/chef-solo/cookbooks" log_level :debug
node.json
次㫠node.json ã¨ããã®ãä½ããããã¯Chef Soloã®æã ã使ããã¡ã¤ã«ãé常ã®Chef Serverã¨Chef Clientã使ã£ãå ´åããã¼ãã®å±æ§(= Attribute)ã¯Chef Serverã«ä¿åããã¦ãã¦ãå¿ è¦ã«å¿ãã¦Chef Clientããåç §ã§ããããChef Soloã®å ´åã«ã¯ããããä»çµã¿ã¯ãªããããJSONãã¡ã¤ã«ãä½ã£ã¦ããã«ãã¼ãã®å±æ§ãè¨è¿°ããã
ä»åã¯ä»¥ä¸ã®å 容ã§ã
{ "run_list": [ "recipe[sample1]" ] }
Cookbook, Recipeçãç¨èªã®èª¬æ
Chefã«ã¯Cookbook, Recipeçãè²ã ãªç¨èªãããã®ã§ãããã§ã¯Webãµã¼ãã¼ã®åæè¨å®ãè¡ãã¨ããã·ããªãªãä¾ã¨ãã¦ãå¾æ¥ã®æ¹æ³ã¨å¯¾æ¯ãã¤ã¤èª¬æããã
ãããªã·ããªãªãèãã
å¾æ¥ã§ããã°ã以ä¸ã®æ§ãªèªåããã±ã¼ã¸ãç¨æãã¦ãsetup.shãå®è¡ãã¦ã»ããã¢ãããè¡ãªãã¨ããã®ã¯å²ã¨ä¸è¬çã ã£ãã¨æã(â»)ã
setup.sh ã®ä¸ã§ã¯ä»¥ä¸ã®æ§ãªãã¨ãå®è¡ããã
- OSã®è¨å®
- webappã¦ã¼ã¶ã¼ãä½æ
- iptablesãé©åã«è¨å®
- resolve.conf ãèªåããã±ã¼ã¸ã®ãã®ã¨ç½®ãæãã
- Apacheã®è¨å®
â»ããã¾ã§ä¾ã®ããã«å¤èãæ¹æ³ãåãä¸ãã¦ãããå®éã¯Chefã使ããªãã¦ããAmazon Web Servicesã®å ´åã¯ã«ã¹ã¿ã AMIãä½ã£ãããRed Hatç³»ã®å ´åã¯Kickstartã使ã£ãããã¦ãããç¨åº¦èªååã¯åºæ¥ããã¡ãªã¿ã«ããããã¨Chefã¯æä»çãªãã®ã§ã¯ãªããçµã¿åããã¦ä½¿ããã®ã
Chefã ã¨ã©ããªãï¼
ãããChefã§ç½®ãæããã¨ãä¸çªåç´ãªãã¿ã¼ã³ã§ã¯ä»¥ä¸ã®ããã«ãªãã
ãµã¼ãã¼ã»ããã¢ããç¨ã®Cookbook(âãã£ã¬ã¯ããªã¼)ãä½æãããã®ä¸ã«ä»¥ä¸ã®ãã¡ã¤ã«ãç¨æããã
- setup.sh ã®ãããªå½¹å²ããã default.rb ã¨ããååã® Recipe
- httpd.conf.erb ã¨ããååã® Template
- resolve.conf ã¨ããååã® File
Recipeã®ä¸ã§ã¯ä»¥ä¸ãå®è¡ããã
å®éã«Chef Soloã§ãã£ã¦ã¿ã
ä¸ã§æããã·ããªãªããChef Soloã使ã£ã¦ï¼ä¸é¨ï¼å®è¡ãã¦ã¿ãã
Cookbook ã®ä½æ
$ knife cookbook create sample1 -c ~/chef-solo/solo.rb
ããã§ã~/chef-solo/cookbooks 以ä¸ã« sample1 ã¨ããååã® Cookbook ãä½æããããCookbook ã¯åãªããã£ã¬ã¯ããªã¼ã§ããã®ä¸ã«å種ãã¡ã¤ã«ããµããã£ã¬ã¯ããªãä½æããã¦ããã
Recipe ã®ä½æ
sample1/recipes ã®ä¸ã«ãdefault.rb ã以ä¸ã®ããã«ä½æãããRubyã触ã£ããã¨ããã人ã§ããã°(ã¨ãããããã°ã©ãã¼ã§ããã°)ãç¹ã«èª¬æã¯ãããªãã¯ãã
%w{httpd mod_ssl}.each do |pkg| package pkg do action :install end end
Recipeã®å®è¡
$ sudo chef-solo -c ~/chef-solo/solo.rb -j ~/chef-solo/node.json
ã¨ã©ã¼ãåºãªããã°OKãä¸ã®solo.rbã®ã¨ããã§log_levelãdebugã«ãã¦ããã®ã§ãã¨ã©ã¼ã®å ´åè²ã ãã°ãåºãã¨æãã
ããã§ãhttpd 㨠mod_ssl ãã¤ã³ã¹ãã¼ã«ãããã¯ããrpm -q ã¨ãã§ç¢ºèªãã¦ããã
ããã¾ã§ããChef Soloå®è¡ã®è¶ åºæ¬ã
Recipeã®ä½æãããå°ã詳ãã
åºæ¬ãåãã£ãæã§ãããå°ãRecipeã«è²ã æ¸ãã¦ã¿ãã
ãã¡ã¤ã«ã®åç´ãªç½®ãæã
å ç¨ã®ä¾ã®setup.sh ã§ã¯ /etc/resolv.conf ãããã¡ãã§æå®ãããã®ã«ç½®ãæãã¦ããããChefãã¼ã¸ã§ã³ã§ãåãäºããããã
ã¾ãã¯Recipeã«ä»¥ä¸ã追è¨ããã
cookbook_file "/etc/resolv.conf"
次ã«ãsample1/files/default/resolv.conf ã¨ãããã¡ã¤ã«ã以ä¸ã®ããã«ä½æããã
domain foo.example.com nameserver 192.168.1.2 nameserver 192.168.1.3
ããã§ããä¸åº¦Recipeãå®è¡ããã¨ã/etc/resolv.conf ããä¸ã®å 容ã«ç½®ãæããã
ãã¡ã¤ã«ã®ä¸èº«ãåçã«å¤æ´ãã
ä»åº¦ã¯ãhttpd.conf ããã¡ãã§æå®ãããã®ã«ç½®ãæãããããã ãããã¡ã¤ã«ã®ä¸èº«ã¯åºå®ã§ã¯ãªããä¸é¨ç°å¢ã«ãã£ã¦ç°ãªãå¤ãè¨å®ãããã
ããã©ã«ãã® httpd.conf ããsample1/templates/default/httpd.conf.erb ã¨ããååã§ã³ãã¼ããã
次ã«ãhttpd.conf.erb ã® Servername ã®é¨åãã以ä¸ã®ããã«æ¸ãæããã
ServerName <%= node['hostname'] %>
ãããä½ãæå³ãããã¯æ³åä»ãã¨æãã®ã§èª¬æã¯çç¥ã
default.rb ã«ä»¥ä¸ã追è¨ã
service "httpd" do supports :status => true, :restart => true, :reload => true end template "/etc/httpd/conf/httpd.conf" do notifies :restart, 'service[httpd]' end
ãã㯠httpd ã¨ãããµã¼ãã¹ã®å®ç¾©ããã¦ãhttpd.conf ãä¸ã§ä½ã£ãhttpd.conf.erb ã®å 容ã«ç½®ãæãã¦ãhttpd ãµã¼ãã¹ãåèµ·åãããã¨ããå 容ã®Recipeã
ããã§ããä¸åº¦ chef-solo ãå®è¡ããã¨ãæå¾ ããåä½ãå®è¡ãããã¯ãã
æ§æè¦ç´ ã®èª¬æ
ä¸ã«åºã¦ãããããª
- cookbook_file
- package
- template
- service
ã¨ããã®ã¯ãå ¨ã¦ Resource ã¨å¼ã°ãããChefã§ã¯Recipeã®ä¸ã§æ§ã ãªResourceã使ã£ã¦ãNodeã®è¨å®ãè¡ãªã£ã¦ããããã®ä»ã«ã©ã®ãããªãªã½ã¼ã¹ããããã¯ãこちらã®ããã¥ã¡ã³ããåç §ãæ°ãå¤ãã®ã§ä¸åº¦ã«å ¨é¨è¦ãããã¨ãããå¿ è¦ãªãã®ãé 次調ã¹ã¦ããã°è¯ãã¨æãã
ãã®å¾ãããã¨
ããã¾ã§ããã°ãChefã®åºæ¬çãªå 容ã¯ç解ã§ããã¯ãã»ã»ã»
ãã®å¾ã¯ããã®ä»ã®Resourceã®ä½¿ãæ¹ããä»åã»ã¨ãã©èª¬æãã¦ããªãAttributeãData bagãªã©ã«ã¤ãã¦èª¿ã¹ã¦ã¿ãã¨ããããã
ãã®å¾ã«ãKnife Soloã¨ããã®ã使ã£ã¦ãããããNodeãå¤ããã°Chef Serverã¨Workstationãæ§ç¯ãã¦ãæ¬æ ¼çãªChefç°å¢ãæ§ç¯ããã¨ããé¸æè¢ãããã
ã¾ã¨ã
ä»åã®è¨äºã§ã¯ãæåã«Chefã®ã¢ã¼ããã¯ãã£ã«ã¤ãã¦ç°¡åã«ã¤ãã¦èª¬æãããChefãã¹ã¿ã³ãã¢ãã¼ã³ã§å®è¡ããChef Soloã®ç°å¢ãæ§ç¯ããç°¡åãªã¬ã·ãã®ä½æãéãã¦ãããã¤ãã®Resourceã®åºæ¬çãªä½¿ãæ¹ãå¦ãã ã
Chefã¯ããã¥ã¡ã³ãã¯æ´åããã¦ããããä»çµã¿ãçµæ§è¤éã§ãªã®ã§ããããç解ãã¦ããªãã¨ããã¥ã¼ããªã¢ã«çãªããã¥ã¡ã³ããèªãã§ãä½ã®ãã¥ã¼ããªã¢ã«ãªã®ãããã£ã±ãåãããã«è©°ã¾ã£ã¦ãã¾ãäºãå¤ããã¾ãã¯Chef Soloã§åºæ¬çãªä»çµã¿ãç解ãã¦ããã¨ããã®å¾ã®å¦ç¿ãã¹ã ã¼ãºã ã¨æãã