本文内容Chef集中配置管理工具实践之(1)环境部署
环境介绍OS:Ubuntu10.10Server64-bit//经过验证在12.04.1以及12.10上也成功实现部署。Servers:chef-server:10.6.1.170chef-workstation:10.6.1.171chef-client-1:10.6.1.172chef-client-2:10.6.1.173
1.安装配置ChefServer编辑hostsubuntu@chef-server:~$sudovim/etc/hosts
注意:将本机的hostname在/etc/hosts中添加一条IP解析记录,这一点非常重要。因为后面在安装chef-server的过程中,会首先安装rabbitmq-server,缺少该解析记录的话,会导致rabbitma-server启动失败,进而影响到所有其它chef-server软件包的正常安装,如果不清楚这一点的话,会给问题的排查带来很大的不便。
添加GPGKeyubuntu@chef-server:~$sudomkdir-p/etc/apt/trusted.gpg.dubuntu@chef-server:~$sudogpg--keyserverkeys.gnupg.net--recv-keys83EF826A
ubuntu@chef-server:~$sudogpg--exportpackages@opscode.com|sudotee/etc/apt/trusted.gpg.d/opscode-keyring.gpg>/dev/null
中的步骤。》
ubuntu@chef-server:~$sudoapt-getupdateubuntu@chef-server:~$sudoapt-getinstallopscode-keyring
更新现有系统ubuntu@chef-server:~$sudoapt-getupgrade
安装chef-server软件包ubuntu@chef-server:~$sudoapt-getinstallchefchef-server
安装完成后检查并确认以下端口:ChefServer-4000ChefServerWebUI-4040CouchDB-5984RabbitMQ-5672ChefSolr-8983
ubuntu@chef-server:~$sudonetstat-lntp
安装配置knife命令行工具ubuntu@chef-server:~$mkdir-p~/.chefubuntu@chef-server:~$sudocp/etc/chef/validation.pem/etc/chef/webui.pem~/.chefubuntu@chef-server:~$sudochown-R$USER~/.chef
ubuntu@chef-server:~$knifeconfigure-i
执行knife命令,检查是否能连接到指定的ChefServerubuntu@chef-server:~$knifeclientlist
ubuntu@chef-server:~$knifecookbooklist
ubuntu@chef-server:~$sudoapt-getinstallntp
为工作站安装并配置KnifeClientubuntu@chef-server:~$knifeclientcreatechef-workstation-d-a-f/home/ubuntu/.chef/chef-workstation.pem
ubuntu@chef-server:~$knifeclientshowchef-workstation
2.安装配置chef-workstation编辑hostsubuntu@chef-workstation:~$vim/etc/hosts
安装Ruby与其它依赖包ubuntu@chef-workstation:~$sudoapt-getinstallrubyruby-devlibopenssl-rubyrdocriirbbuild-essentialwgetssl-certcurl
安装ChefGemubuntu@chef-workstation:/tmp/rubygems-1.8.10$sudogeminstallchef--no-ri--no-rdoc
admin@ubuntu:/tmp/chef-workstation$sudogeminstall/tmp/chef-workstation/chef-11.8.2.gem--local--no-ri--no-rdoc
前提是把所有的gem都放到这个目录下了,再也不干这种事情了。
>
安装Gitubuntu@chef-workstation:~$sudoapt-get-yinstallgit-coreubuntu@chef-workstation:~$git--versiongitversion1.7.1
创建ChefRepository备注:Chef的大部分配置工作都是在Workstaion中的ChefRepository中完成的,不同的ChefRepository可以管理不同的ChefServer。ubuntu@chef-workstation:~$gitclonegit://github.com/opscode/chef-repo.git/opt/chef-local#可能会不工作,请参照note。
Cloninginto'/home/chef1/chef-repo'...Permissiondenied(publickey).fatal:Theremoteendhungupunexpectedly ubuntu@chef-workstation:~$cd/opt/chef-local/ubuntu@chef-workstation:/opt/chef-local$lsREADME.mdRakefilecertificateschefignoreconfigcookbooksdata_bagsenvironmentsroles 创建配置文件夹ubuntu@chef-workstation:/opt/chef-local$sudomkdir-p.chef 传输pem认证文件到Workstationubuntu@chef-workstation:/opt/chef-local$sudoscpubuntu@chef-server:/home/ubuntu/.chef/chef-workstation.pem.chef/ubuntu@chef-workstation:/opt/chef-local$sudoscpubuntu@chef-server:/home/ubuntu/.chef/validation.pem.chef/ ubuntu@chef-workstation:/opt/chef-local$ls.chef/chef-workstation.pemvalidation.pem ubuntu@chef-workstation:/opt/chef-local$sudoknifeconfigure ******************************************************** Youmustplaceyourclientkeyin:/home/admin/.chef/ubuntu.cs1cloud.internal.pemBeforerunningcommandswithKnife! ***** Youmustplaceyourvalidationkeyin:/home/admin/.chef/validation.pemBeforegeneratinginstancedatawithKnife! *****Configurationfilewrittento/home/admin/.chef/knife.rbadmin@ubuntu:~/.chef$knifeclientlistacm-dev12-n1-extchef-validatorchef-webuichef1chef2ubuntu.cs1cloud.internal ****************************************** 验证配置是否正确ubuntu@chef-workstation:~$sudontpdatechef-server 确认Knife工具能否连接到ChefServerubuntu@chef-workstation:~$knifeclientlist ubuntu@chef-workstation:~$knifeclientshowchef-validator 3.安装配置chef-client编辑hostsubuntu@chef-client-1:~$vim/etc/hosts Boostrap可以用来将目标节点初始化为一个Clientubuntu@chef-workstation:~$knifebootstrap--help 下面我们对chef-client-1进行初始化ubuntu@chef-workstation:~$sudoknifebootstrap10.6.1.172-xubuntu-Ppassword--sudo ***************************if/bin/bashisnotincludedin/etc/sudoersforclientwithRedhatOS*********** ************************Afteradding/bin/bashinto/etc/sudoersinclientOS,thengotfollowing**************** workstation会用sudo的方式在client端执行install.sh,最终会根据OS的类型(rl,ubuntu,suse,aix,etc)和版本,是否为64位拿到一个chef的rpm包, 这部分工作可以在client上事先安装好。 需要做的工作包括: 1)对应的chefRPMpackage 2)建立.chef目录(可能会在lps下面) 所以在cloud上这些工作完全可以包含在每个NE的qcow2的image里面。 整个的chefsetup过程将只包含: 1)chefserver(networklevel同一个,or用chefsolo的方式) 2)chefworkstation(这个需要一个) 3)添加client,创建client.pem.然后copy到 验证chef-client-1是否已经注册ubuntu@chef-workstation:~$knifeclientlist 从上面可以看出chef-client-1已经成功注册到了chef-server中,整个环境chef-workstation=>chef-server=>chef-client-1已经搭建成功。