chef-soloã¨gitã§CentOSã®ç°å¢æ§ç¯ãããããèªåå
ä¸ã®ä¸ãã¯ããã¸ã¼ã¯ã©ãã©ãé²åãã¦ãã¦ããã³ã£ããã§ãã
CentOSã§Webã¢ããªã®ãµã¼ãç°å¢ãä½ãå ´åãyumã³ãã³ããå®è¡ãã¦ãé©å®è¨å®ãã¡ã¤ã«ãä¿®æ£ãã¦ããã¼ã¢ã³ãªã©ãåèµ·åããã£ã¦ãªãã¨ãæ¯åãã£ã¦ããã®ã§ãããä»ã¯chefã«ãããµã¼ãæ§ç¯èªååãã§ããããã§ãã
ãã®chefãå©ç¨ããã«ã¯Rubyãã¤ã³ã¹ãã¼ã«ãã¦gemããchefã®ããã±ã¼ã¸ãã¤ã³ã¹ãã¼ã«ããå¿ è¦ããã£ãã®ã§ããããããæè¿Omunibusã¨ããã³ãã³ãä¸çºã§ã§ããä»çµã¿ãã§ãã¦æ´ã«ããã¡ãã«ãªãã¾ããã
ã¨ããããã§ãgitãªãã¸ããªã«chefã®cookbookãç½®ãã¦ç®¡çãããããã»ããã¢ãããããµã¼ãã¼ã«pullãchef-soloãå®è¡ãã¦ãç°å¢æ§ç¯ãèªååãã¦ãã¾ãæé ã®ãµã³ãã«ã以ä¸ã«ã¾ã¨ãã¦ã¿ã¾ããã
https://github.com/kohkimakimoto/chef-for-centos
chefãµã¼ããä¸è¦ã§ããªãã¨OSã¤ã³ã¹ãã¼ã«å¾ãã£ã6ã¹ãããã§ã»ããã¢ãããããã§ãã¾ãã¾ãã
æ§æã«ã¤ãã¦
ãã¦ä¸è¨ã®chefãªãã¸ããªã§ãããæ§æãåç´ã«ãããããè¨å®ãããµã¼ã(ãã¼ã)ä¸å°ãã¨ã«chefã®roleãåå¥ã«å®ç¾©ããããã«ãã¦ãã¾ããroleã¯æ¬æ¥ããã¤ãã®webãµã¼ãã¨ãdbãµã¼ãã¨ããè¤æ°ãã£ã¦åãå½¹å²ããã¤ãµã¼ãã®å ±éå®ç¾©ãè¨è¿°ããã®ã«ä½¿ãããã§ãããããã¦ãããã¦ãã¾ããã
å ãã¦ãchef-soloãã©ããããã·ã§ã«ã¹ã¯ãªãããæ¸ãã¦ãããã¹ãåã¨åãååã®roleã§chef-soloãå®è¡ãããããã«ãã¦ãã¾ãããããªæãã®ã¹ã¯ãªããã§ãã
#!/bin/bash
#
# Execute chef-solo with auto generated run_list that is relied on hostname.
#
CMD_NAME=${0##*/}
CMD_DIR=$(cd $(dirname $0);pwd)
REPO_DIR=$(cd ${CMD_DIR}/..;pwd)
HN=${HOSTNAME%%.*}
LANG=en
FILE_DATE=`date +%y%m%d%H%M%S%N`
RUN_LIST_FILE="/tmp/chef_solo_run_list.${FILE_DATE}.json"
#
# Update chef reopository directory using git pull.
#
cd ${REPO_DIR}
git pull
#
# Generate run_list json file using hostname. and then execute chef-solo command.
#
echo "{\"run_list\":[\"role[${HN}]\"]}" > ${RUN_LIST_FILE}
echo "Generated run list file. [${RUN_LIST_FILE}]"
chef-solo -c ${REPO_DIR}/config/solo.rb -j ${RUN_LIST_FILE}
/bin/rm -f ${RUN_LIST_FILE}
echo "Deleted run list file. [${RUN_LIST_FILE}]"
ãã®æ§æã®ã¡ãªããã¯ããµã¼ããã¨ã«ç°ãªãè¨å®ãããã¨ãããããroleã«æè»ã«è¨è¿°ã§ããã¨ããã§ããæ°ãã«ãµã¼ãã¼ã®è¿½å ããã£ãã¨ãããroleãã¡ã¤ã«ãä¸å追å ããã ãã§ãããã«å¯¾å¿ã§ãã¾ãããã¡ãããµã¼ãå°æ°ã100å°ã¨ãããã¨ãã®æ°ã ãroleãã¡ã¤ã«ãå¢ãã¦ãã¾ã£ã¦ç ©éã«ãªãã¨ã¯ãããããã©ãç¾å®ã¨ãã¦ãããªå°æ°ã®ãµã¼ãã管çããç«å ´ã«ç§ã¯ãªã(ãã£ã¦ã10æ°å°ããª)ã®ã§ãããã§ååãªã®ã§ãã
ã¾ãããã¹ãåã¨åãååã®roleã§chef-soloãå®è¡ããã¨ããç¸ããããã®ã§ãä¸è¨ã®ã©ããã¼ã¹ã¯ãªãããå©ç¨ããéããééã£ã¦ã»ãã®ãã¹ãç¨ã®è¨å®ã§chef-soloãå®è¡ãã¦ãã¾ãã®ãé¿ãããã¾ãã
æ¬æ¥ã®roleã®ä½¿ãæ¹ã§ããè¤æ°ã®ãµã¼ãéã®å ±éçãªå®ç¾©ã¯å¥éä¸è¨ã®ãããªbese.rbã¨ããå ±éé¨åã ãåãåºããroleãã¤ãã£ã¦ããµã¼ãåå¥ã®roleã®ä¸ããèªã¿è¾¼ãããã«è¨å®ãããã¨ã§å¯¾å¿ã§ãã¾ãã
base.rb - è¤æ°ãµã¼ãå ±éå®ç¾©ç¨role
name "base"
description ""
run_list(
"recipe[common]",
"recipe[selinux]",
"recipe[yum]",
"recipe[iptables]",
"recipe[httpd]",
"recipe[php]",
"recipe[mysql]"
)
default_attributes({
:role => "base",
})
web.rb - ãµã¼ãåå¥ã®role
name "web"
description ""
run_list(
"role[base]"
)
default_attributes({
:role => "web",
})
ãµã¼ããã¨ã«ç°ãªãè¨å®ï¼ãã¨ãã°ãã¹ãã®IPã¢ãã¬ã¹ã¨ããæå®ããã¨ããªã©ï¼ã¯ãµã¼ãåå¥ã®roleå ã®default_attributesã§è¨å®ãã¦ããã°ãrecipeãtemplateã§nodeã¨ããå¤æ°ããåç §ãå©ç¨ã§ãã¾ãã
ãµã³ãã«ã®å®è¡æé
https://github.com/kohkimakimoto/chef-for-centos
ãµã¼ãã®ãã¹ãåãä¿®æ£ããã
# vi /etc/sysconfig/network
以ä¸ã®ããã«ãããä»åã®ãµã³ãã«ã§ã¯webã¨ãããã¹ãååºå®ã
NETWORKING=yes HOSTNAME=web
ãµã¼ããåèµ·åãã¦ããã¹ãåãåæ ãããã
# reboot
Omnibusã使ã£ã¦chefãã¤ã³ã¹ãã¼ã«ã以ä¸ã®ã³ãã³ããå®è¡ããã ãã§OKã
# curl -L https://www.opscode.com/chef/install.sh | bash
ãªãOmunibuseã«ã¤ãã¦ã¯ãã¡ãã®è¨äºãåèã«ãã¦ãã ããã
http://www.opscode.com/blog/2012/06/29/omnibus-chef-packaging/
.gitãã¤ã³ã¹ãã¼ã«ãã
# yum install -y git
ãµã³ãã«ã®chefãªãã¸ããªãgithubããcloneãã
# git clone https://github.com/kohkimakimoto/chef-for-centos.git /var/chef
chef-soloã以ä¸ã®ã©ããã¼ã¹ã¯ãªããããå®è¡ããã
# sh /var/chef/bin/chef-host
以ä¸ã§çµããã§ãããã®ãµã³ãã«ã§ã¯ApacheãMySQLãPHPã¨ãã使ãéè¯ãªãã¸ããª(remi,epel)ã®ã»ããã¢ãããå®äºãã¾ãã