æ¨æ¥ã®ãChef 11 での client/server/knife のセットアップ手順(+α)ãã®ã¨ã³ããªã®ç¶ãã§ãã
Chef Serverã¨Clientã¯åºæ¬çã«RESTãªHTTP APIãä»ãã¦ããã¨ããè¡ãã®ã§ãããChefã«ã¯Server APIãGUI(ãã©ã¦ã¶)ã§æä½ã§ããchef-server-webuiãæ¨æºã§ã¤ãã¦ãã¾ãã
âã®æ¨æ¥ã®ã¨ã³ããªã§ã»ããã¢ããããç¶æ
ã ã¨ãåã®ç°å¢(CentOS 6ç³»)ã ã¨ä½¿ããªãã£ãã®ã§ã使ããç¶æ
ã¾ã§ã«è¨å®ããã¡ã¢ãæ®ãã¦ããã¾ãã
(ã¡ãªã¿ã«ãç§ã¯æ®æ®µã»ã¨ãã©WebUIã使ã£ã¦ãã¾ãã...)
åæ
- Chef Server 11ç³»ã®ãã¼ã¸ã§ã³
- æ¨æ¥ã®ã¨ã³ããªã®éããChef Serverã¯ã¤ã³ã¹ãã¼ã«ï¼åä½ç¢ºèªæ¸
- 使ã£ãChef Serverã®ç°å¢ã¯CentOS 6ç³»
- ãµã¼ãã¯ã¤ã³ã¿ã¼ãã«ãªå é¨ãããã¯ã¼ã¯ã«è¨ç½®
- å é¨DNSããªãã®ã§ãå é¨ãããã¯ã¼ã¯ã§ã¯èªåã§åå解決ãå¿ è¦
chef-server-webuiã¸ã®ã¢ã¯ã»ã¹
ã¾ãã¯ããã©ã¦ã¶ããWebUIã«ã¢ã¯ã»ã¹ãã¦ã¿ã¾ãã
âã®éãã®åæã§å
é¨DNSããªãç°å¢ãªã®ã§ãChef Serverã¸ã®ã¢ã¯ã»ã¹ã¯IPã¢ãã¬ã¹ãç´ã§æå®ãã¾ãã
ããã¨ä»¥ä¸ã®ãã°ã¤ã³ç»é¢ã表示ããããã¨æãã¾ãã
次ã«ãadminã¦ã¼ã¶ï¼ããã©ã«ããã¹ã¯ã¼ãã§ãã°ã¤ã³ãã¾ãã
åæãã¹ã¯ã¼ãã¯âã®ç»é¢å³é¨ã«è¨è¼ããã¦ããä»ã"/etc/chef-server/chef-server-running.json"ã®"web_ui_admin_default_password"ã«ãè¨è¼ããã¦ãã¾ãã
ãã°ã¤ã³ã§ããªãã»ã»ã»ï¼
ã»ã»ã»ããã¨ã"We're sorry, but something went wrong."ã®è¡¨ç¤ºã¨ã500(Internal Server Error)ãè¿ããããã°ã¤ã³ã§ãã¾ããã
ã¨ãããã¨ã§ãã°ãè¦ã¦ã¿ã¾ãããã
WebUIã¢ããªã®ãã°ãªã®ã§ã"/var/log/chef-server/chef-server-webui/current"ã確èªãã¦ãããã®ã§ãããChef 11ããã¯ã"chef-server-ctl tail"ã¨ããChef Serverãå¸ãå種ããã¯ã¨ã³ãã®ããã«ã¦ã§ã¢ã®ãã°ã俯ç°ãã¦ã¢ãã¿ãªã³ã°ã§ããã³ãã³ããåå¨ãã¾ãï¼
ã¨ããããã§ã
# chef-server-ctl tail
ã¨å®è¡ãããã1度ãã©ã¦ã¶ãããã°ã¤ã³ãã¦ã¿ã¾ãã
==> /var/log/chef-server/chef-server-webui/current <== 2013-05-27_05:59:01.21153 Started POST "/users/login_exec" for 127.0.0.1 at 2013-05-27 14:59:01 +0900 2013-05-27_05:59:01.21511 Processing by UsersController#login_exec as HTML 2013-05-27_05:59:01.21531 Parameters: {"utf8"=>"✓", "authenticity_token"=>"8wnCRT7r5abkQKHnzaD4FrTCd9fbysEqLi+H7Ye3kJ0=", "name"=>"admin", "commit"=>"login", "password"=>"[FILTERED]"} 2013-05-27_05:59:01.21638 [2013-05-27T14:59:01+09:00] WARN: Failed to read the private key /etc/chef-server/chef-webui.pem: #<Errno::EACCES: Permission denied - /etc/chef-server/chef-webui.pem> 2013-05-27_05:59:01.22081 Chef::Exceptions::PrivateKeyMissing: I cannot read /etc/chef-server/chef-webui.pem, which you told me to use to sign requests! 2013-05-27_05:59:01.22085 {:request_params=> 2013-05-27_05:59:01.22086 {"utf8"=>"✓", 2013-05-27_05:59:01.22087 "authenticity_token"=>"8wnCRT7r5abkQKHnzaD4FrTCd9fbysEqLi+H7Ye3kJ0=", 2013-05-27_05:59:01.22087 "name"=>"admin", 2013-05-27_05:59:01.22088 "commit"=>"login", 2013-05-27_05:59:01.22088 "password"=>"p@ssw0rd1", 2013-05-27_05:59:01.22089 "action"=>"login_exec", 2013-05-27_05:59:01.22089 "controller"=>"users"}} 2013-05-27_05:59:01.22090 2013-05-27_05:59:01.22090 /opt/chef-server/embedded/service/gem/ruby/1.9.1/gems/chef-11.4.0/lib/chef/rest.rb:430:in `rescue in load_signing_key' 2013-05-27_05:59:01.22091 /opt/chef-server/embedded/service/gem/ruby/1.9.1/gems/chef-11.4.0/lib/chef/rest.rb:420:in `load_signing_key' 2013-05-27_05:59:01.22091 /opt/chef-server/embedded/service/gem/ruby/1.9.1/gems/chef-11.4.0/lib/chef/rest.rb:66:in `initialize'
ãã°ã«ã¯ãã®ãããªæãã«ãã©ããããPermission denied - /etc/chef-server/chef-webui.pemããããããã¨ãããã
# ll /etc/chef-server/chef-webui.pem -rw-r----- 1 root chef_server 1679 May 27 13:55 /etc/chef-server/chef-webui.pem
該å½ãã¡ã¤ã«ã®ownerã¨permissionã®ç¢ºèªã
# id chef_server uid=498(chef_server) gid=100(users) groups=20278(chef_server),100(users)
ã§ãchef-server-webuiã®å®è¡ã¦ã¼ã¶ã®ç¢ºèªã
ãã¡ãã¨OSã§ã®ã°ã«ã¼ãã«ã¯æå±ãã¦ããããã§ããããã©ã¤ããªã°ã«ã¼ãã"users"ã«ãªã£ã¦ãã¦ãchef-server-webuiã稼åãã¦ããunicornããã»ã¹ã§ã¯ãã©ã¤ããªã°ã«ã¼ãããã»ããããã¦ããªãããããªãããªãã¨äºæ³ã(ããã¯æ¨æ¸¬ã§ã)
ã¨ãããã¨ã§ãUnicornããã»ã¹ã«æ£ããã°ã«ã¼ããè¨å®ãããã¨ããã®ã§ãããã¡ãã£ã¨Unicornåãä½ããã¦æ³£ãããã«ãªã£ãã®ã§ããã£ãã"/etc/chef-server/chef-webui.pem"ã®ownerã"chef_server"ã«å¤æ´ãã¦ããã¼ããã·ã§ã³ã440ã«ããä½æ¦ã決è¡ãããã¨ã«ããã(ï½´ï¾ï¾)
chef-serverèªä½ã®Cookbookãå¤æ´ãã
ã¯ã£ããè¨ãã¨ã"/etc/chef-server/chef-webui.pem"ã«ã¤ãã¦ã¯ãChef Serverã®Cookbookã§ã¯"recipes/bootstrap.rb"ã§ç®¡çããã¦ãã¾ãããããã¯æåã«1度æµããã¨ãåºæ¬çã«ã¯å¦çãããªãæãã«ãªã£ã¦ãã¾ãã(ver. 11.0.8)
ãªã®ã§ããã¡ã¤ã«ã®ãªã¼ãã¨ãã¼ããã·ã§ã³ã®å¤æ´ãªã®ã§ãchownã¨ãchmodã®ã³ãã³ãã使ãã°ããã®ã§ããããã£ãããªã®ã§åå¼·ãã¦ããCookbookããã¡ãã¨å¤æ´ãã¦ãããã¹ã姿ãè¨è¼ãã¦ã¿ã¾ãã
ã¨ããããã§ãã¾ãã¯"/etc/chef-server/chef-webui.pem"ã®ç¶æ
ãè¨è¼ãã¦ãã"/opt/chef-server/embedded/cookbooks/chef-server/recipes/bootstrap.rb"ã以ä¸ã®ããã«æ¸ãæãã¾ãã
# diff -u /opt/chef-server/embedded/cookbooks/chef-server/recipes/bootstrap.rb{.bak,} --- /opt/chef-server/embedded/cookbooks/chef-server/recipes/bootstrap.rb.bak 2013-05-27 16:06:08.869973685 +0900 +++ /opt/chef-server/embedded/cookbooks/chef-server/recipes/bootstrap.rb 2013-05-27 19:05:38.461985677 +0900 @@ -39,10 +39,10 @@ # servers need access to this key. chef_user = node['chef_server']['user']['username'] file "/etc/chef-server/chef-webui.pem" do - owner "root" + owner chef_user group chef_user - mode "0640" - not_if { File.exists?(bootstrap_status_file) } + mode "0440" + #not_if { File.exists?(bootstrap_status_file) } end file bootstrap_status_file do
ownerã¯attributeã§è¨å®ããã¦ãã"chef_user"ã«ãmodeã§ãã¼ããã·ã§ã³ãå¤æ´ãnot_ifã§bootstrap_status_fileãåå¨ãããå®è¡ãããªãããã«ãªã£ã¦ããã®ã§ããããã³ã¡ã³ãã¢ã¦ããã¾ãã
次ã«ã"/opt/chef-server/embedded/cookbooks/chef-server/recipes/default.rb"ã以ä¸ã®ããã«å¤æ´ãã¾ãã
# diff -u /opt/chef-server/embedded/cookbooks/chef-server/recipes/default.rb{.bak,} --- /opt/chef-server/embedded/cookbooks/chef-server/recipes/default.rb.bak 2013-05-27 16:05:33.397223454 +0900 +++ /opt/chef-server/embedded/cookbooks/chef-server/recipes/default.rb 2013-05-27 16:07:03.317974407 +0900 @@ -36,9 +36,9 @@ node.consume_attributes(ChefServer.generate_config(node['fqdn'])) end -if File.exists?("/var/opt/chef-server/bootstrapped") - node.set['chef_server']['bootstrap']['enable'] = false -end +#if File.exists?("/var/opt/chef-server/bootstrapped") +# node.set['chef_server']['bootstrap']['enable'] = false +#end # Create the Chef User include_recipe "chef-server::users"
ããã§ã¯ã"/var/opt/chef-server/bootstrapped"ãåå¨ããã°bootstrapãæµããªãããã«ã»ããããã¦ããé¨åãããã®ã§ããããã³ã¡ã³ãã¢ã¦ããã¾ãã
ã¡ãªã¿ã«ãrecipes/bootstrap.rbã®ä¸èº«ãè¦ã¦ããããã°ãããã¾ãããâãã³ã¡ã³ãã¢ã¦ããã¦ããbootstrap.rbã§å®ç¾©ããã¦ããåãªã½ã¼ã¹ã§ãä¸è¨åæ§ã®ãã¡ã¤ã«ãã§ãã¯ããã£ã¦ãã¾ãã®ã§ãããããå½±é¿ã¯ãªãã§ãã(ç®ã«è¦ãããã¡ãªããã¯ãä½è¨ãªãã§ãã¯å¦çãèµ°ããããã)
# chef-server-ctl reconfigure
ããã¾ã§å¤æ´ããããä¸è¨ã³ãã³ããå®è¡ããâã®å¤æ´ãé©ç¨ãã¾ãã
# ll /etc/chef-server/chef-webui.pem -r--r----- 1 chef_server chef_server 1679 May 27 13:55 /etc/chef-server/chef-webui.pem
ç¡äºãå¤æ´ããã¾ãããã
ãã¼ããã1åãã°ã¤ã³ãã¦ã¿ãã»ã»ã»é§èåèå
ããã¾ã§ã§ããã1度ãã©ã¦ã¶ã§ãã°ã¤ã³ãã¦ã¿ãããã¾ã ãã°ã¤ã³ã§ããã
ã¨ãããã¨ã§ããã£ãã¨åæ§ã«"chef-server-ctl tail"ã§ãã°ã®ç¢ºèªããã¦ã¿ã¾ãã
==> /var/log/chef-server/chef-server-webui/current <== 2013-05-27_07:36:17.89711 Started POST "/users/login_exec" for 127.0.0.1 at 2013-05-27 16:36:17 +0900 2013-05-27_07:36:18.04026 Processing by UsersController#login_exec as HTML 2013-05-27_07:36:18.04051 Parameters: {"utf8"=>"✓", "authenticity_token"=>"8wnCRT7r5abkQKHnzaD4FrTCd9fbysEqLi+H7Ye3kJ0=", "name"=>"admin", "commit"=>"login", "password"=>"[FILTERED]"} ==> /var/log/chef-server/erchef/current <== 2013-05-27_07:36:18.42529 2013-05-27_07:36:18.42532 =ERROR REPORT==== 27-May-2013::16:36:18 === 2013-05-27_07:36:18.42532 {no_such_key,[70,97,105,108,101,100,32,102,105,110,100,105,110,103,32,107,101, 2013-05-27_07:36:18.42533 121,32,"default"], 2013-05-27_07:36:18.42533 []} 2013-05-27_07:36:18.43753 2013-05-27_07:36:18.43756 =ERROR REPORT==== 27-May-2013::16:36:18 === 2013-05-27_07:36:18.43756 webmachine error: path="/users/admin" 2013-05-27_07:36:18.43757 {throw,{no_such_key,default}, 2013-05-27_07:36:18.43757 [{chef_wm_base,select_user_or_webui_key,2, 2013-05-27_07:36:18.43758 [{file,"src/chef_wm_base.erl"},{line,602}]}, 2013-05-27_07:36:18.43758 {chef_wm_base,verify_request_signature,2, 2013-05-27_07:36:18.43758 [{file,"src/chef_wm_base.erl"},{line,257}]}, 2013-05-27_07:36:18.43759 {chef_wm_base,is_authorized,2, 2013-05-27_07:36:18.43759 [{file,"src/chef_wm_base.erl"},{line,171}]}, 2013-05-27_07:36:18.43760 {webmachine_resource,resource_call,3, 2013-05-27_07:36:18.43760 [{file,"src/webmachine_resource.erl"}, 2013-05-27_07:36:18.43760 {line,166}]}, 2013-05-27_07:36:18.43761 {webmachine_resource,do,3, 2013-05-27_07:36:18.43761 [{file,"src/webmachine_resource.erl"}, 2013-05-27_07:36:18.43761 {line,125}]}, 2013-05-27_07:36:18.43762 {webmachine_decision_core,resource_call,1, 2013-05-27_07:36:18.43762 [{file,"src/webmachine_decision_core.erl"}, 2013-05-27_07:36:18.43764 {line,48}]}, 2013-05-27_07:36:18.43764 {webmachine_decision_core,decision,1, 2013-05-27_07:36:18.43765 [{file,"src/webmachine_decision_core.erl"}, 2013-05-27_07:36:18.43766 {line,186}]}, 2013-05-27_07:36:18.43766 {webmachine_decision_core,handle_request,2, 2013-05-27_07:36:18.43766 [{file,"src/webmachine_decision_core.erl"}, 2013-05-27_07:36:18.43767 {line,33}]}]} ==> /var/log/chef-server/chef-server-webui/current <== 2013-05-27_07:36:18.47964 [2013-05-27T16:36:18+09:00] ERROR: Server returned error for http://127.0.0.1:8000/users/admin, retrying 1/5 in 4s ==> /var/log/chef-server/erchef/erchef.log.1 <== 2013-05-27T07:36:18Z [email protected] ERR req_id=35Tn7CQcrbTSklWgbQYqZw==; status=500; method=GET; path=/users/admin; user=chef-webui; msg=[]; req_time=271; rdbms_time=194; rdbms_count=1 ==> /var/log/chef-server/erchef/current <== 2013-05-27_07:36:22.49102 2013-05-27_07:36:22.49107 =ERROR REPORT==== 27-May-2013::16:36:22 === 2013-05-27_07:36:22.49108 {no_such_key,[70,97,105,108,101,100,32,102,105,110,100,105,110,103,32,107,101, 2013-05-27_07:36:22.49109 121,32,"default"], 2013-05-27_07:36:22.49109 []}
ãµã¼ãããã£ã±ãããããï½
ã¨ãããã¨ã§ãChef Serverã¾ãããã»ã¨ãã©åæè¨å®ã®ã¾ã¾ã ã£ãã®ã§ã以ä¸ã®æ°ã«ãªã£ã¦ããç¹ãå¤æ´ãããã¨ã§ããç¨åº¦ç¶ºéºã«åãã¾ããã
Chef Serverã«å¯¾ããè¨å®ã®å¤æ´å®ç¾©
ã¡ãªã¿ã«ãChef Serverã®Cookbookã«å¯¾ãã¦Attributeã®å¤æ´å®ç¾©ãããå ´åã¯ã"/opt/chef-server/embedded/cookbooks/chef-server/attributes/default.rb"ã§ã¯ãªãã"/etc/chef-server/chef-server.rb"ã¨ãªãã¾ãã
ã¨ããããã§ã"/etc/chef-server/chef-server.rb"ãä½æãã以ä¸ãæ¿å
¥ãã¦ãã ããã
以ä¸ã®ãµã³ãã«ã§"172.xxx.xxx.xxx"ã¯ãChef Serverã®IPã¢ãã¬ã¹ãæãã¾ãã(ä»åã®åæã§IPã¢ãã¬ã¹ã§ã®ã¢ã¯ã»ã¹ã¨ãã¦ããããããã®ãããã¯ç°å¢ã«å¿ãã¦ä¿®æ£ãã¦ãã ããã)
bookshelf['vip'] = "172.xxx.xxx.xxx" bookshelf['url'] = "https://172.xxx.xxx.xxx"
ããã¯ãã¾ãã§ãããã¤ãã§ã«ãããã³ãã®nginxã§HTTPã«ã¢ã¯ã»ã¹ãããå ´åã«ãHTTPSã«ãªãã¤ã¬ã¯ããããããã«ä»¥ä¸ã®è¨å®ãå
¥ãã¦ããã¾ãã
lb['api_fqdn'] = "172.xxx.xxx.xxx" lb['web_ui_fqdn'] = "172.xxx.xxx.xxx" nginx['server_name'] = "172.xxx.xxx.xxx" nginx['url'] = "https://172.xxx.xxx.xxx"
ä¿®æ£ãçµããã°ãä¾ã«ãã£ã¦ä»¥ä¸ã³ãã³ããå®è¡ãã¦ãâã®è¨å®ãé©ç¨ãã¾ãã
# chef-server-ctl reconfigure
Chef Serverããã¯ã¨ã³ãã®ããã«ã¦ã§ã¢åèµ·å
ã¯ããè¨å®ãåæ ãããã°ãå種ããã«ã¦ã§ã¢ãåèµ·åãã¾ãã
ã¡ãªã¿ã«ãå種ããã«ã¦ã§ã¢ã®ç¾ç¶ã®ã¹ãã¼ã¿ã¹ã確èªããå ´åã¯ã以ä¸ã®"chef-server-ctl status"ã³ãã³ãã§ãã
# chef-server-ctl status run: bookshelf: (pid 11447) 49s; run: log: (pid 23125) 12976s run: chef-expander: (pid 11470) 48s; run: log: (pid 23019) 12982s run: chef-server-webui: (pid 11474) 48s; run: log: (pid 9753) 11145s run: chef-solr: (pid 11509) 46s; run: log: (pid 22933) 12988s run: erchef: (pid 12222) 6s; run: log: (pid 23230) 12970s run: nginx: (pid 12255) 5s; run: log: (pid 9933) 11129s run: postgresql: (pid 11535) 45s; run: log: (pid 22844) 12994s run: rabbitmq: (pid 11563) 45s; run: log: (pid 22511) 13010s
é話ä¼é¡ã
Chef Serverããã¯ã¨ã³ãã®åããã«ã¦ã§ã¢ã以ä¸ã³ãã³ã"chef-server-ctl restart"ã§åèµ·åãã¾ãã
# chef-server-ctl restart ok: run: bookshelf: (pid 12308) 1s ok: run: chef-expander: (pid 12331) 1s ok: run: chef-server-webui: (pid 12335) 0s ok: run: chef-solr: (pid 12358) 1s ok: run: erchef: (pid 12373) 0s ok: run: nginx: (pid 12401) 1s ok: run: postgresql: (pid 12421) 0s ok: run: rabbitmq: (pid 12430) 1s
ã¯ããåèµ·åã§ãã¾ããã
ããã§æ°ãåãç´ãã¦ããã©ã¦ã¶ããChef Server WebUIã«ã¢ã¯ã»ã¹ãããã°ã¤ã³ãã¦ã¿ã¦ãã ãããåé¡ãªããã°ã¤ã³ã§ããã¯ãã§ãã
æå¾ã«
ãããªæãã§ãå®éã«ãã°ãè¦ãªãããCookbookã®recipeã«æãå
¥ãã¦ã¿ãããattributeãå®ç¾©ãã¦ãã©ã¡ã¼ã¿ãå¤æ´ãã¦ã¿ã¾ããã
å®éã«ãã£ã¦ã¿ã¦ãerchefã¯ã¡ãã£ã¨ãã°ããããã¥ããã£ãããèºãããRecipeãèªãã ã(ãããã£ã¦æãå
¥ããããã¨ãããè¯ãã¨ããã§ãã)ãªã©ãå°ãæ·å±
ãé«ãæããããããã¾ããããä»åã®ç°å¢ãå°ãç¹æ®ã ã£ãã®ãããããªãã®ã§ã次ã¯Amazon EC2ã¨ãUbuntuã§ãåããã¦ã¿ããããªã¨æã£ã¦ãã¾ãã
ããã§ã¯ï¼ =͟͟͞͞(๑•̀=͟͟͞͞(๑•̀д•́=͟͟͞͞(๑•̀д•́๑)=͟͟͞͞(๑•̀д•́
å ¥éChef Solo - Infrastructure as Code
- ä½è : ä¼è¤ç´ä¹
- åºç社/ã¡ã¼ã«ã¼: ä¼è¤ç´ä¹
- çºå£²æ¥: 2013/03/11
- ã¡ãã£ã¢: Kindleç
- è³¼å ¥: 16人 ã¯ãªãã¯: 1,027å
- ãã®ååãå«ãããã° (19件) ãè¦ã
- ä½è : John Ewart
- åºç社/ã¡ã¼ã«ã¼: Packt Publishing
- çºå£²æ¥: 2013/02/22
- ã¡ãã£ã¢: ãã¼ãã¼ããã¯
- ãã®ååãå«ãããã°ãè¦ã