çè«
çè«çãªåºç€ããªããã°ãã©ãã«ããããŸããã ãŸã第äžã«ãPuppetã®ããã«Chefã¯ããšããšRubyã§æžãããŠããŠããã§ã«ãã®èšèªã話ãã°ãã©ã¹ã«ãªããšèšã䟡å€ããããŸãã ããã§ãªãå Žåã¯ãå°ãªããšãåºæ¬ãå匷ããå¿ èŠããããŸãã èšäºãJust Enough Ruby for Chefãããå§ããããšãã§ããŸãã èšèªã®åºæ¬ãç解ããã®ã«æ¬åœã«ååã§ãã
å ¬åŒwikiã§ã¯ãChefã®åŠç¿ãéå§ããããã«å¿ èŠãªãã¹ãŠã®æ å ±ãèŠã€ããããšãã§ããŸãïŒããã¥ã¡ã³ãã¯ãå瀟ã®ææ補åïŒEnterprise ChefãšHosted Chefã®èª¬æã«çŠç¹ãåœãŠãŠããŸãããªãŒãã³ãœãŒã¹Chefã«ã€ããŠèª¬æããŸãïŒã
ãŸããã¢ãŒããã¯ãã£ã®æŠèŠãèŠãŠãåºæ¬çãªæŠå¿µãç解ããå¿ èŠããããŸãã ãããã«ã€ããŠç°¡åã«èª¬æããããšããŸãã
ã€ã³ãã©
- Nodesã¯ãChefã§èšå®ããç©çãµãŒããŒãŸãã¯ä»®æ³ãµãŒããŒã§ãã
- ãµãŒããŒïŒChefãµãŒããŒïŒ-ã¯ã©ã€ã¢ã³ãïŒããŒãïŒããçŽæ¥ã¢ã¯ã»ã¹ãããChefãµãŒããŒããµãŒããŒã¯ããã€ãã®ã³ã³ããŒãã³ãã§æ§æãããŠããŸãã
- Web-UI-ãµãŒããŒã®Webã€ã³ã¿ãŒãã§ã€ã¹ãè¡šãRoRäžã®ã¢ããªã±ãŒã·ã§ã³ã
- Erchef-ãµãŒããŒã³ã¢ãChef11.xãèšè¿°ãããŠãããããErlangã¯Rubyã®ä»¥åã®ããŒãžã§ã³ãšå®å šã«äºææ§ããããŸãã
- æ¬æ£-ãæçæ¬ãã®ãªããžããªã
- Nginx-ãã³ãã«ãããŠããããã¹ãŠã®APIãªã¯ãšã¹ããééããŸãã
- PostgreSQL-ChefãµãŒããŒã«ãå«ãŸããŠãããæããã«æ å ±ã¹ãã¬ãŒãžã®åœ¹å²ãæãããŸãã
- ã¯ãŒã¯ã¹ããŒã·ã§ã³-Chef管çè ã®è·å Žãã€ãŸã ã¬ã·ããæçã®æ¬ãæºåãããã€ãã§ãããã³å šäœã管çããPCã
- ãã€ã-ãã€ãã®ãªãã·ã§ããšã¯ïŒ ãã€ãã¯ãã³ã³ãœãŒã«ããChefãæäœããããã®ã¡ã€ã³ããŒã«ã§ãã ããŒããšChefãµãŒããŒãå¶åŸ¡ããã®ã¯ããã€ããã®å©ããåããŠã§ãã
ã¬ã·ãã®æºå
- èªä¿¡ãæã£ãŠã¬ã·ãã調çããã«ã¯ããã¹ãŠã®çšèªãšå®çŸ©ãæ確ã«ç解ããå¿ èŠããããŸãã
- Cookie ïŒã¯ãã¯ããã¯ïŒã¯ãå±æ§ãã¬ã·ãããã³ãã¬ãŒããããã³ãã¡ã€ã«ã®ãªããžããªã§ãã
- å±æ§ïŒå±æ§ïŒ-ã¬ã·ããšããŒã«ã®äž¡æ¹ãä»ããŠããŒãã«èšå®ã§ããããã€ãã®æ§æãã©ã¡ãŒã¿ãŒã ããã§å±æ§ã䜿çšããæé ãç解ããããšããå§ãããŸãã
- ãã³ãã¬ãŒãïŒæ§æãã³ãã¬ãŒãïŒ-æ§æãéåžžã®ãã¡ã€ã«ããã³ãã©ã¡ãŒã¿ãŒåãããerb-templatesãšããŠé åžã§ããŸãã ç¹å®ã®é åºã®ãã³ãã¬ãŒããã©ã¡ãŒã¿ã®å€ã¯ãã¯ãã¯ããã¯ã®å±æ§ãŸãã¯ããŒã«ãã眮ãæããããŸãã
- ãã¡ã€ã«-ã¬ã·ãã䜿çšããŠãå®å ã®ãã¹ãšæš©éãæåã«èšè¿°ããããšã§é åžã§ãããã¡ã€ã«ã
- å®çŸ©-æ°èŠãŸãã¯æ¢åã®ãªãœãŒã¹ïŒãµãŒãã¹ãApacheä»®æ³ãã¹ããªã©ïŒããã³/ãŸãã¯ãããã«å¯Ÿããã¢ã¯ã·ã§ã³ãèšè¿°ããããã«äœ¿çšãããŸãã
- ã©ã€ãã©ãªïŒã©ã€ãã©ãªïŒ-ã¬ã·ãã®æ¡åŒµãšããŠãRubyã³ãŒããæ¿å ¥ãã以å€ã®äœç©ã§ããããŸããã
- ãªãœãŒã¹âãªãœãŒã¹ã¯ãã·ã¹ãã å ã®ä»»æã®ãªããžã§ã¯ãïŒãã¡ã€ã«ããŠãŒã¶ãŒãã°ã«ãŒãããµãŒãã¹ãªã©ïŒã§ãã
çè«ãå€ããå°ãªããæ確ã§ããã°ãç·Žç¿ãéå§ã§ããŸãã
ç·Žç¿ãã
Chef Serverãã€ã³ã¹ããŒã«ãã
Get Chef Webãµã€ãã§ããã£ã¹ããªãã¥ãŒã·ã§ã³ã®çŸåšã®ããŒãžã§ã³ã®Chef ServerãéžæããŸãã
CentOS 6.5ã«ãµãŒããŒãã€ã³ã¹ããŒã«ããUbuntu 12.04ã®äŸã䜿çšããŠç®¡çè ã¯ãŒã¯ã¹ããŒã·ã§ã³ãæ§æããŸãã
ãµãŒããŒã«ã¯ãå®å šä¿®é£Ÿãã¡ã€ã³åãïŒFQDNïŒãå¿ èŠã§ãã
ã€ãŸã / etc / hostnameã«ã¯ã次ã®åœ¢åŒã®ãšã³ããªãå¿ èŠã§ãïŒchef.example.ru
ã€ã³ã¹ããŒã«ã¯ãrootæš©éãæã€ãŠãŒã¶ãŒããè¡ãããŸãã
次ã«ãåæãµãŒããŒæ§æãå®è¡ããå¿ èŠããããŸããrpm -Uvh https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-server-11.0.10-1.el6.x86_64.rpm
ãã®ã³ãã³ãã¯ãChefãµãŒããŒãæ©èœããããã«å¿ èŠãªãã¹ãŠã®ã³ã³ããŒãã³ãïŒErchefãRabbitMQãnginxãPostgreSQLïŒãèŠæ±ããŸããchef-server-ctl reconfigure
ãã¹ãŠã®æ§æãå®äºããããChef Server Webã€ã³ã¿ãŒãã§ãŒã¹ããŒãžã«ç§»åã§ããŸãã
å³åŽã®åã«ãããã©ã«ãã®ãŠãŒã¶ãŒåãšãã¹ã¯ãŒãã衚瀺ãããŸãïŒadminïŒp @ ssw0rd1ã
[ãŠãŒã¶ãŒ]ã¿ãã§ãã¹ã¯ãŒããå€æŽããç§å¯ããŒãåçæããŸãïŒããŒã¯èªåçšã«ä¿åããå¿ èŠããããããã©ã«ãã§ã¯ã©ãã«ãä¿åãããŸããïŒïŒ
次ã«ããã¯ã©ã€ã¢ã³ããã¿ãã«ç§»åããŸããããã§ãã·ã§ãããªããŒã¿ãŒã®ããŒãåã¬ã³ããªã³ã°ããå¿ èŠããããŸãïŒèªåèªèº«ãšãµãŒããŒã«ä¿åããå¿ èŠããããŸããåŸã§å¿ èŠã«ãªããŸãïŒ
管çè ã®ã¯ãŒã¯ã¹ããŒã·ã§ã³ã«Chef ClientïŒãã€ãïŒãã€ã³ã¹ããŒã«ãã
ã€ã³ã¹ããŒã«ã¯1ã€ã®ã³ãã³ãã§å®è¡ã§ããŸãã
debãŸãã¯rpmããã±ãŒãžãããŠã³ããŒãããŠãæåã§ã€ã³ã¹ããŒã«ããŸããcurl -L https://www.opscode.com/chef/install.sh | sudo bash
ã¯ãã¯ããã¯ã䜿çšããã«ã¯ãgitã³ã³ãœãŒã«ã¯ã©ã€ã¢ã³ããå¿ èŠã§ãã
ãŸããRubyããŒãžã§ã³=> 1.9.1ãå¿ èŠã§ãã Ubuntu 12.04ã®å Žåã次ã®ããã«èšå®ãããŸããapt-get install git
Chefã®ãªããžããªããŒã¯ã¢ãããããŒã ãã£ã¬ã¯ããªã«è€è£œããŸããapt-get install ruby1.9.1
git clone git://github.com/opscode/chef-repo.git
ã¯ãŒã¯ã¹ããŒã·ã§ã³ãããã€ãã䜿çšããŠããŒã«ãªã©ã§ããŒãã管çã§ããããã«ããã«ã¯ã2ã€ã®ããŒãå¿
èŠã§ãã
- chef-validator.pem chefãµãŒããŒã®ç§å¯éµïŒã¯ã©ã€ã¢ã³ãããµãŒããŒãžã®APIãªã¯ãšã¹ããæ¿èªããããã«äœ¿çšïŒ
- user.pemã¯ããµãŒããŒã§ã®æ¿èªã®ããã®ç§å¯éµã§ãã
~/chef-repo/.chef/
ãã€ãã®ã»ããã¢ããã¯æ¬¡ã®ã³ãã³ãã§è¡ããŸãïŒ
ããã§ã¯ãç§å¯éµãžã®ãã¹ãšãCookieãå«ããã£ã¬ã¯ããªãžã®ãã¹ãæå®ããå¿ èŠããããŸãã ãã€ãèšå®ãã¡ã€ã«ãã/ chef-repo / .chef /ãã£ã¬ã¯ããªã«ããã次ã®ããã«ãªããŸããknife configure -i
cat /home/it/chef-repo/.chef/knife.rb
log_level :info log_location STDOUT node_name 'it' client_key '/root/Chef/chef-repo/.chef/it.pem' validation_client_name 'chef-validator' validation_key '/home/it/chef-repo/.chef/chef-validator.pem' chef_server_url 'https://chef.example.ru:443' syntax_check_cache_path '/home/it/chef-repo/.chef/syntax_check_cache' cookbook_path [ '/home/it/chef-repo/cookbooks', '/home/it/chef-repo/example' ] # knife[:editor] = 'vim' # knife
ãã€ãã®åäœã確èªããŸãã
ãã¹ãŠã®ã³ãã³ãã¯ãããŒã«ã«Chefãªããžããªã®ãã£ã¬ã¯ããªãŸãã¯ãµããã£ã¬ã¯ããªããå®è¡ããå¿ èŠããããŸããknife client list
ãã€ãã䜿çšããŠæåã®ãµãŒããŒãæ¥ç¶ãã
ãããè¡ãã«ã¯ãchefã¯ã©ã€ã¢ã³ããã€ã³ã¹ããŒã«ãããµãŒããŒã«æ°ãããŠãŒã¶ãŒãäœæããŠããŒãçæããknife bootstrapã³ãã³ãã䜿çšããŸãã
äžè¬ã«ãrootãšããŠsshçµç±ã§ãã¹ãã«æ¥ç¶ããŸãããrootã¢ã¯ã»ã¹ãå¶éãããŠããå Žåã¯ã管çïŒsudoïŒæš©éãæã€ãŠãŒã¶ãŒãæå®ããå¿ èŠããããŸããknife bootstrap test.example.ru
ãµãŒããŒãããŒãã®ãªã¹ãã«ããããšã確èªããŸããknife bootstrap test.example.ru --sudo -x admin -P Password
knife node list
test.example.ru
æåã®ã¯ãã¯ããã¯ãé©çšããŸããã
ããã§ãæåã®ããŒããæ¥ç¶ãããŸããã ããã§ãœããââãŠã§ã¢ãã€ã³ã¹ããŒã«ããChefã䜿çšããŠæ§æãå€æŽã§ããŸãã ããããæåã«ãæåã®ã¯ãã¯ããã¯ãäœæããããgithubã®Opscodeãªããžããªããå®æããã¯ãã¯ããã¯ãååŸããå¿ èŠããããŸãã 2çªç®ã®ãªãã·ã§ã³ã§ååã§ãã
ã¯ãããŒãå¿ èŠãªãã£ã¬ã¯ããªã«è¡ããŸããã
cd ~/chef-repo/cookbooks
ãããŠãäŸãã°chef-clientã®å Žåãæåã®Cookieãããã«è€è£œããŸãïŒ
git clone https://github.com/opscode-cookbooks/chef-client.git
metadata.rbãèŠããšããã®Cookieã®äŸåé¢ä¿ã®ãªã¹ãã衚瀺ãããŸãã
suggests 'bluepill' suggests 'daemontools' suggests 'runit' depends 'cron', '>= 1.2.0' depends 'logrotate', '>= 1.2.0'
ãŸããããããèªåèªèº«ã«ã¯ããŒã³ããŠããããµãŒããŒã«ã¯ããŒã³ããå¿
èŠããããŸãã
ãã®ã¯ãã¯ããã¯ããã¬ã·ããé©çšããã«ã¯ããŸããã¹ãŠã®äŸåé¢ä¿ãšãšãã«ãµãŒããŒãã¢ããããŒãããå¿ èŠããããŸãã
ããã§ããã¹ãããŒãã«chef-clientã¬ã·ããè¿œå ãããµãŒããŒãžã®ã¯ã©ã€ã¢ã³ãã¢ã¯ã»ã¹ã®æéãå€æŽã§ããŸããknife cookbook upload bluepill daemontools runit cron logrotate chef-client
ããŒãã®æ§æã¯json圢åŒã§è¡šç€ºãããŸãã ãµãŒããŒãžã®ããŒãã¢ã¯ã»ã¹ã®æéãæžãçããchef-clientã¬ã·ããå®è¡ãªã¹ãã«è¿œå ããŸããããknife node edit test.example.ru
{ "name": "test.example.ru", "chef_environment": "_default", "normal": { "chef_client": { "interval": "300" }, "tags": [ ] }, "run_list": [ "recipe[chef-client]" ] }
æåã®æçæ¬ãæžããŸããã
ãã¹ãã¬ã·ãçšã®ã¯ãã¯ããã¯ãäœæããŸãããã
knife cookbook create test
ãã¹ãŠã®ãµãŒããŒã«é
åžããããã±ãŒãžã®ãªã¹ãã«ãããã©ã«ãããã£ã¬ã¯ãã£ããè¿œå ããŸãã
vim ~/chef-repo/cookbooks/test/recipes/default.rb
%w{ntp mc htop iotop iftop atop vim-common wget curl rkhunter git awstats postfix}.each do |packages| package packages do action :install end end
ã¯ãã¯ããã¯ããµãŒããŒã«ã¢ããããŒãããŠããŒãã®å®è¡ãªã¹ãïŒå®è¡å¯èœãªã¬ã·ãã®ãªã¹ãïŒã«ç»é²ããã ãã§ãããããŒã«ãäœæããŠããã«ãã®ã¬ã·ããå«ããããšããå§ãããŸãã æ®å¿µãªãããå°ãªããšãepelãªããžããªãå¿
èŠã§ãã æ§æãã¡ã€ã«ãã¯ãã¯ããã¯ã«å
¥ããŠãæ§æã®ã³ããŒãã¬ã·ãã®yum.repos.dã«è¿œå ããããopscodeã®yum cookieã䜿çšã§ããŸãã
git clone https://github.com/opscode-cookbooks/yum.git
ãŸããyum-epelã¯ãã¯ããã¯ãããŠã³ããŒãããŸãïŒäœããã®çç±ã§ãææ°ã®ãªãªãŒã¹ã§ã¯ãã¡ã€ã³ã®ã«ãã®ã¬ã·ããå¥ã®ã¯ãã¯ããã¯ã§åŒ·èª¿ããããšã«ããŸããïŒã
git clone https://github.com/opscode-cookbooks/yum-epel.git
ãµãŒããŒã«æžç±ãã¢ããããŒãããŸãã
ããã§ããã¹ãã¬ã·ãã«yum-epelã¬ã·ããå«ããããšãã§ããŸããknife cookbook upload yum yum-epel
vim ~/chef-repo/cookbooks/test/recipes/default.rb
include_recipe âyum-epelâ %w{ntp mc htop iotop iftop atop vim nano wget curl rkhunter git awstats postfix}.each do |packages| package packages do action :install end end
ã¯ãã¯ããã¯ã®å±æ§ã§epel-repoã®ããã±ãŒãžäŸå€ãæå®ããããšãã§ããŸãã
vim ~/chef-repo/cookbooks/test/attributes/default.rb
default['yum']['epel']['exclude'] = âtest*â
ã¯ãã¯ããã¯ããµãŒããŒã«ã¢ããããŒãããããŒãã«ã¬ã·ããé©çšããŸãã
knife cookbook upload test
knife node edit test.example.ru
{ "name": "test.example.ru", "chef_environment": "_default", "normal": { "chef_client": { "interval": "300" }, "tags": [ ] }, "run_list": [ "recipe[chef-client]", ârecipe[test]â ] }
knife ssh name:test.example.ru "chef-client" -P r00tPassworD
ãããã£ãŠãChefã䜿çšããŠåããŠã®çµéšãåŸãŸããã ä»ãç§ã¯ãã¹ãŠãèŠããã»ã©è€éã§ã¯ãªãããšãæããã«ãªã£ããšæããŸãã äž»ãªããšã¯ããã«ãã ããããšã§ã¯ãããŸããã ããã«ããã€ãã®èšäºãèªãã§ãOpscodeãªããžããªããã¬ã·ããé©çšããŠã¿ãŠãã ããã ã¬ã·ããããã€ãæžããŠé©çšããŠãã ããã ãµãŒããŒã€ã³ãã©ã¹ãã©ã¯ãã£ã®èª¬æãChefã«ç¿»èš³ããŸãã ãµãŒããŒã®å±éé床ãäžæ¡é«ããªããè¿·æãªãšã©ãŒãå°ãªããªããããæ°æ¥ãŸãã¯æ°æ¥ããããŸãã ãããŠãèŠããŠãããŠãã ãããChefãåŠã¶æè¯ã®æ¹æ³ã¯ããã䜿ãå§ããããšã§ãã
æçšãªèšäºïŒ
å ¬åŒã·ã§ãWiki
Opscodeã¯ãã¯ããã¯ã³ã¬ã¯ã·ã§ã³
é åãšã·ã§ãã®å±æ§
Chef 11ã®è©³çŽ°ïŒå±æ§ã®å€æŽ
Chef 11ã®é倧ãªå€æŽ
ã·ã§ããŸãã¯æ§æ管çãšããŠã®æåã®çµéš
ChefãŸãã¯1000å°ã®ãµãŒããŒã管çããæ¹æ³
ãµãŒããŒã®æäŸããŸãã¯Opscode Chefã䜿çšããå±éã®éå§æ¹æ³
åå¿è åãã®ãµã€ãå šäœïŒ Chefãå§ããŸããã
Alexei Vasilievã«ããäžé£ã®èšäºïŒæ®å¿µãªããè±èªã®ã¿ïŒïŒ ã·ã§ããœãå ¥é