éçºã¡ã¢#5 : Amazon Linux 㧠knife-solo ã使ã£ã¦ chef-solo å®è¡
éçºã¡ã¢ãã®5ã§ãã表é¡ã©ãã EC2 ã¤ã³ã¹ã¿ã³ã¹ã® Amazon Linux 㧠knife-solo ã使ã話ã
開発メモ#4 : EC2スナップショットとの差分は chef-solo で解決 - naoyaのはてなダイアリー ã§ãchef-solo ã使ã£ã¦ EC2 ã®ç°å¢ç®¡çããã¦ããã¨æ¸ãã¾ããããã¡ chef-solo ã®å®è¡ã¯ capistrano like 㪠perl ã®ãããã¤ãã¼ã« Cinnamon ã«ä»»ãã¦ãããã¨ããæ¨ãè¿°ã¹ã¾ããã
ãã件ã®ãããã¤ãã¼ã«ä»»ãã 㨠chef-solo å®è¡ã®åº¦ã«ã¬ãã¸ããªçµç±ã§ã¬ã·ãããµã¼ãã¼å´ã«è»¢éããå¿ è¦ããããèªå㯠github ã使ã£ã¦ããã®ã§ github ã« push ãã¦ãµã¼ãã¼å´ã§ fetchc ãããããããã¤ãã¼ã«ããã®è¾ºããã£ã¦ãããã¨ã¯è¨ããã¬ã·ãã®åä½ç¢ºèªã®ããã«ã¡ããã¨åããã¨ãä¿è¨¼ããã¦ããªãã¬ã·ããã¬ãã¸ããªã« push ããå¿ è¦ããã£ã¦è¯ããªããªã¨æãããã«ãªãã¾ããã
knife-solo
chef ã«å梱ããã¦ãã chef ã®ç®¡çã³ãã³ã knifeããã®ãã©ã°ã¤ã³ã«å½ãã knife-solo ã使ãã¨ããã¼ã«ã«ã§ä½ã£ãã¬ã·ãããªã¢ã¼ãã« sync ãã¦ãªã¢ã¼ãå´ã§ chef-solo ãå®è¡ãã¦ãããããããªã github ãçµç±ããªãã¦ããã
## æå ã® OSX # knife-solo ã¤ã³ã¹ãã¼ã« % gem install knife-solo # chefã¬ãã¸ããªãä½ã % knife solo init chef-repo % cd chef-repo # ãªã¢ã¼ãã§ã® chef-solo å®è¡ç°å¢ãæ´ãã % knife solo prepare [email protected]-1 # ãã¼ã«ã«ã®ã¬ã·ãã転éããªã¢ã¼ã㧠chef-solo å®è¡ % knife cook [email protected]-1
ãªãã¨ããã ãã§ãããã¾ããchef-client ã chef-server ã使ãã¾ã§ããªããã© chef-solo ã®ãµã¼ãã¼ãµã¤ãã§ã®å®è¡ãç°¡åã«ãããï¼ã¨ããç¶æ³ã«ããããã¦ã¾ããã
・・・ãªã®ã§ãããæ®å¿µãªãã knife solo prepare 㨠cook 㯠Amazon Linux ã§ã¯ãã®ã¾ã¾åããªãã®ã§ããã
$ knife solo prepare [email protected]-1 ERROR: RuntimeError: Distro not recognized from looking at /etc/issue. Please fork https://github.com/matschaffer/knife-solo and add support for your distro.
ãããªæãã®ã¨ã©ã¼ã«ãªããã°ã°ã©ããªãã£ã®ããã«è¼ã£ãã¦ããã¾ãããã
2/4 20:20 追è¨
knife solo prepare 㯠chef-solo ãå®è¡å¯è½ãã©ããã調ã¹ã¦ãããããã§ãªããã°å®è¡å¯è½ã«ãªããã調æ´ãã・・・ã¨ãããã¨ããã¾ããè¦ããã«ãchef-solo ãå ¥ã£ã¦ãªãã£ããã¤ã³ã¹ãã¼ã«ããããã®æã¤ã³ã¹ãã¼ã«ãããã®ã¯ Omnibus Chef Packaging ã¨ãããã¼ã¸ã§ã³ã® chef ã§ãruby ãã¤ããªãã®ã»ãçµã¿è¾¼ã¿ã®ç¬ç«ã§åã chef ã«ãªãã¾ãã
knife solo cook 㯠Omnibus Chef Packaging ã§å ¥ã£ã chef-solo ã® PATH ãªã©ãèæ ®ã㦠chef-solo ãå®è¡ãã¾ãã
knife-solo ãä¿®æ£ãã
ã¨ãããã㧠knife-solo ã Amazon Linux ã§ãåãããã«ããããå½ã¦ã¾ãã
knife-solo ã®ãã¼ã¸ã§ã³ã¯
- 2æ4æ¥ç¾å¨ github ã®ã¬ãã¸ããªã¯ãã¼ã¸ã§ã³ 0.2.0.pre1
- gem install ã§å ¥ã stable 㯠0.1.0
ã¨ãªã£ã¦ã¾ãããåè ã¯ãã¾ãåããªãã£ãã®ã§å¾è ã«ããããå½ã¦ã¦ä½¿ãã¾ããgit tag 㧠v0.1.0 ãã¤ãã¦ãã®ã§ãããæåã
% git clone [email protected]:matschaffer/knife-solo.git % cd knife-solo % git checkout -b amazonlinux v0.1.0
diff ã¯ä»¥ä¸ãè¦ããã«ã/etc/issue ãè¦ã¦ãã£ã¹ããªãã¥ã¼ã·ã§ã³ãå¤å®ããã«ããã Amazon Linux ã® /etc/issue ã¯é¢åã¿ã¦ãªãã£ãã®ããè¦ãããã«ãã¦ããã ãã
diff --git a/lib/knife-solo/bootstraps/linux.rb b/lib/knife-solo/bootstraps/linux.rb index a171f27..74961ac 100644 --- a/lib/knife-solo/bootstraps/linux.rb +++ b/lib/knife-solo/bootstraps/linux.rb @@ -104,6 +104,8 @@ module KnifeSolo::Bootstraps {:type => "yum_omnibus", :version => "RHEL5"} when %r{Scientific Linux.*? 6} {:type => "yum_omnibus", :version => "RHEL6"} + when %r{Amazon Linux} + {:type => "yum_omnibus", :version => "Amazon"} when %r{SUSE Linux Enterprise Server 1[12]} {:type => "omnibus", :version => "SLES11"} when %r{openSUSE 1[12]}
å¤æ´ãæ¸ãã ãããããæ¸ã¿ã® knife-solo ãå ¥ããã
% rake install
ããã§ç¡äº knife solo prepare ãåãããã«ãªãã¾ãã
EC2 㧠knife solo
knife solo prepare ã§ã¯ãchef-solo ã®å®è¡ç°å¢ãæ´ã£ã¦ãããã©ããã調ã¹ã¦ãªããã° chef-solo ãã®ãã®ãã¤ã³ã¹ãã¼ã«ããã¨ããã¾ã§é¢åã¿ã¦ããã¾ããå¾ã£ã¦ãknife solo prepare ããã° EC2 ã¤ã³ã¹ã¿ã³ã¹ãç«ã¡ä¸ããç´å¾ãã chef-solo ã使ããããããã ssh ãã°ã¤ã³ã㦠rubygems ã chef ãã¤ã³ã¹ãã¼ã«ãããããå¿ è¦ããªãã
ç«ã¡ä¸ãã¦ãã knife solo prepare & cook ãããã¨ã§ãç°å¢æ§ç¯ãå®å ¨ã«èªååã§ããããã§ããªããã©ã¤ããã§ã³ã¸ã³ã°ã§ããã
ã¡ãã£ã¨ãã®æ§åãå®è·µãã¹ããå¹¾ã¤ã EC2 ã®åæç°å¢æ§ç¯ãèªååãã¦ã¿ã¾ãããã
- t1.micro ã¤ã³ã¹ã¿ã³ã¹ã¯ã¹ã¯ããé åããªãã®ã§ã2GB ã®ãããä½ã
- yum ã® EPEL ã¬ãã¸ããªãæå¹åãã
- sysstat, mosh ãªã©ã EPEL ããã¤ã³ã¹ãã¼ã«ãã
ã¨ããã¾ã§ãã£ã¦ã¿ã¾ãã
ã¾ã㯠knife solo init 㧠chef ã¬ãã¸ããªãä½ããgit init ããã
% knife solo init chef-repo % cd chef-repo % git init % git add . % git commit -m 'first commit'
ã¹ã¯ããé åãä½ãã¬ã·ããä½æãããããã®è¾ºãåèã«ã
% knife cookbook create mkswap -o site-cookbooks
site-cookbooks/mkswap/receipes/default.rb ã¯ä»¥ä¸ã®æãã
bash 'create swapfile' do not_if { File.exists?('/swap.img') } code <<-EOC dd if=/dev/zero of=/swap.img bs=1M count=2048 && chmod 600 /swap.img mkswap /swap.img EOC end mount '/dev/null' do # swap file entry for fstab action :enable # cannot mount; only add to fstab device '/swap.img' fstype 'swap' end bash 'activate swap' do code 'swapon -ae' end
次㯠yum ã® EPEL æå¹åãã¬ã·ããèªåã§æ¸ãã¦ããããã©ãããã¯ã³ãã¥ããã£ã§é
å¸ããã¦ããã®ã使ã£ã¡ããããknife cookbook site vendor yum
ã§ãcookbook 以ä¸ã«ãã¦ã³ãã¼ããããããªããsite vendor ãå®è¡ããã®ã«ã¯ http://community.opscode.com/ ã¸ã®ç»é²ãå¿
è¦ãç»é²ãã¦ãããã£ã¼ã«ãã¼ã¸ãã private key ãåå¾ã㦠~/.chef/naoya.pem ã¨ãã«ä¿åããã¹ãã(ä¿åãã¹ããã¹ã¯ ~/.chef/knife.rb ã«è¨å®ããã¦ã¾ãã)
% knife cookbook site vendor yum
ãã¨ã¯ sysstat 㨠mosh ãå ¥ããã¬ã·ããä½ããä»å¾ãã以å¤ã«ãåºæ¬çãªããã±ã¼ã¸ãå ¥ããããã®ã¬ã·ãã¨ãã¦æ¡å¼µãããã¨ãèãåå㯠base_packages ã«ãã¾ããã
% knife cookbook create base_packages -o site-coookbooks
ã¬ã·ãã¯ä»¥ä¸ãç°¡åã
%w{sysstat mosh}.each do |pkg| package pkg do action :install end end
ããã§ã¬ã·ãã¯æã£ããEC2 ã®ãã¤ã¯ãã¤ã³ã¹ã¿ã³ã¹ãç«ã¡ä¸ãã¦å®äºããã prepareã
% knife solo prepare [email protected]-1
ã¡ãªã¿ã«éå»ã«ãè¨åããéããèªå㯠EC2 ã¤ã³ã¹ã¿ã³ã¹ã®ãã¹ãå管ç㯠ec2ssh ã使ã£ã¦ã¾ãããããã3åç®ãª!
prepare ããã¨ãnodes 以ä¸ã« chef-test.ap-northeast-1.json ã¨ããããã¹ãåããã¡ã¤ã«åã«ãã json ãã¡ã¤ã«ãã§ãã¦ãããä¸èº«ã
{ "recipes":[ "mkswap", "yum::epel", "base_packages" ] }
ã¨æ¸ãæããããã§æºåã¯å®äºããããchef-solo å®è¡ã*1
% knife cook [email protected]-1
ã¹ã¯ãããä½ãã㦠EPEL ãæå¹ã«ãªã£ã¦ãsysstat ã mosh ãå ¥ã£ãã¯ããæ¤è¨¼ãã¦ã¿ããã
% mosh chef-test.ap-northeast-1 $ free total used free shared buffers cached Mem: 608740 404352 204388 0 15192 341780 -/+ buffers/cache: 47380 561360 Swap: 2097148 300 2096848 $ sar 1 1000 Linux 3.2.30-49.59.amzn1.x86_64 (ip-10-152-95-236) 2013å¹´02æ04æ¥ _x86_64_ (1 CPU) 09æ42å32ç§ CPU %user %nice %system %iowait %steal %idle 09æ42å33ç§ all 0.00 0.00 0.00 1.00 0.00 99.00 09æ42å34ç§ all 0.00 0.00 0.00 0.00 0.00 100.0
âªä¸æã«ç¼ãã¾ãããï¼
æå¾ã«ã¬ã·ãã git commit ãã¦å®äºã§ããã¡ãªã¿ã«åæé 㯠vagrant ã§ã使ããã®ã§ãvagrant å´ã§åä½ç¢ºèªãã¦åé¡ãªãã£ãã EC2 ã«é©ç¨ï½¥ï½¥ï½¥ã¿ãããªãã¨ãã§ãã¾ãããvagrant ã«ã¤ãã¦ã¯ã¾ãå¾æ¥æ¸ãã¾ãã
ã¦ãªããã§ãAmazon Linux ã knife-solo ãçéãããã¨ãããã£ãã®ã§ Cinnamon ã¨ã®é£æºé¨åã knife-solo ã使ãããã«æ¸ãæãã¦ãããã¼âã¨ãªãäºå®ã§ãã
*1:è¨å®ã¯ solo.rb ãããã©ã«ãã§ä½¿ããã¾ã