puppet使用了有一段時間了,以前寫的手順書一直未發佈到blog上來,今天正好有空,寫下一點筆記。公司在用的服務器有500多臺,基本都爲CentOS,版本有5和6兩種,管理起來很不方便,尤爲是部署監控,其中有大量重複性工做,使用puppet能夠方便不少。html
安裝前,簡介固然是必定要有的啦,簡單介紹下吧。puppet是基於客戶端和服務器端的C/S架構,基於ruby開發。因此,你要明白,安裝puppet,就須要安裝配置ruby。web管理界面相似於redmine的安裝,使用apache的passenger模塊整合。mysql
rpm –ivh puppetlabs-release-5-6.noarch.rpm rpm –ivh puppet-dashboard-1.2.23-1.el5.noarch.rpm yum install puppet-server puppetdb puppetdb-termius(後面兩個能夠不裝)
二、Install ruby、mysql、apache_passenger moduleweb
參見安裝 redmine文檔。rpm –ivh puppetlabs-release-5-6.noarch.rpm yum install puppet /etc/puppet/puppet.conf 修改以下內容,值爲puppet服務器的hostname PUPPET_SERVER=server.example.com 執行 /etc/init.d/puppet start
或者不修改配置文件,直接puppet agent –server=server.example.comsql
puppet cert list –all
查看模塊位置數據庫
puppet config print modulepath
查看報告apache
Puppet agent –t –summarize
六、Certificate Registervim
客戶端agent啓動時候會給服務器發送證書申請puppet cert sign station3.example.com
七、 Certificate Canclecentos
(1)註銷證書puppet cert revoke station3.example.com(只是讓證書失效)
puppet cert clean station3.example.com (刪除證書)
重啓puppetmaster安全
此時,station3.exmaple.com不能鏈接到puppet serverrm -f /var/lib/puppet/ssl/certs/station3.example.com.pem rm -f /var/lib/puppet/ssl/certificate_requests/station3.example.com.pem
而後重啓puppet,在服務器端執行puppet cert list就能看見從新申請證書。ruby
(3)自動註冊證書vim /etc/puppet/autosign.conf
*.exmaple.com
這樣全部來自example.com域上的全部客戶端就自動註冊了。
八、 puppet dashboardCREATE DATABASE dashboard_production CHARACTER SET utf8; CREATE USER 'dashboard'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON dashboard.* TO 'dashboard'@'localhost'; FLUSH PRIVILEGES;
(3)編輯 /usr/share/puppet-dashboard/config/database.yml
(4)修改時區 /usr/share/puppet-dashboard/config/environment.rbvim /etc/httpd/conf.d/puppet.conf LoadModule passenger_module /usr/local/ruby/lib/ruby/gems/1.8/gems/passenger-3.0.18/ext/apache2/mod_passenger.so PassengerRoot /usr/local/ruby/lib/ruby/gems/1.8/gems/passenger-3.0.18 PassengerRuby /usr/local/ruby/bin/ruby Listen 3001 <VirtualHost *:3001> ServerName server.example.com # !!! Be sure to point DocumentRoot to 'public'! DocumentRoot /usr/share/puppet-dashboard/public <Directory /usr/share/puppet-dashboard/public > # This relaxes Apache security settings. AllowOverride all # MultiViews must be turned off. Options -MultiViews </Directory> </VirtualHost>
這樣puppet就跟redmine同樣用apache的方式啓動了。
(6)初始化數據庫cd /usr/share/puppet-dashboard/
rake RAILS_ENV=production db:migrate
(7) 導入reports(默認在/var/lib/puppet/reports目錄下)
cd /usr/share/puppet-dashboard/
rake RAILS_ENV=production reports:import REPORT_DIR= /var/lib/puppet/reports
(8)Delayed Job Workers
cd /usr/share/puppet-dashboard/ env RAILS_ENV=production script/delayed_job -p dashboard -n 4 -m start(開始分析reports) ps -ef|grep delayed_job|grep -v grep(查看delayed_job 進程) env RAILS_ENV=production script/delayed_job -p dashboard -n 4 -m stop(中止分析)
注意這個進程不要停掉,要一直存在,因此麼,有時候重啓服務器會忘記,乾脆寫入到/etc/rc.local中
既然puppet是C/S架構的,因此還得在每臺服務器上部署客戶端,可是500多臺服務器,不可能手工的一臺一臺去部署,天然經過腳本的方式。
(1)免認證
對於500臺及以上的服務器集羣,應用之間的耦合度很是高,並且爲了管理方便,通常都有操做系統層級的互信,也就是ssh免認證。
固然,有人會說這樣會有內網安全的隱患,若是控制了一臺服務器,那麼整個內網都將淪陷。是的,一點沒錯。安全跟便利自己就是相互矛盾的,我認爲對於IDC服務器集羣架構的安全防禦主要仍是從防火牆訪問限制和權限控制上着手,要既能保證業務正常運做也能保證服務器自己的安全。
(2)hosts文件
因爲是服務器集羣,全部服務器之間的信任通常都是經過/etc/hosts文件記錄其餘服務器hostname跟IP的映射關係。
基於內網中服務器之間的免認證,咱們可使用腳本將安裝腳本推送到全部服務器上,而後再執行安裝腳本,這樣就是實現了puppet客戶端的自動安裝。
安裝腳本,install_puppet.sh
#!/bin/bash version5=0 version6=0 [ -f /etc/init.d/puppet ]&& /etc/init.d/puppet restart [ -f /etc/sysconfig/puppet ]&& exit version5=`/bin/cat /etc/issue|head -1|grep '5.'|wc -l` if [ $version5 = 1 ];then rpm -ivh http://yum.puppetlabs.com/el/5/products/i386/puppetlabs-release-5-6.noarch.rpm yum -y install puppet puppet agent --server server.example.com [ -f /sbin/chkconfig ]&&`chkconfig puppet on` #echo "centos 5" else version6=`/bin/cat /etc/issue|head -1|grep '6.'|wc -l` if [ $version6 = 1 ];then rpm -ivh http://yum.puppetlabs.com/el/6/products/i386/puppetlabs-release-6-6.noarch.rpm yum -y install puppet puppet agent --server server.example.com [ -f /sbin/chkconfig ]&&`chkconfig puppet on` #echo "centos 6" fi fi
推送腳本push.pl,基於/etc/hosts文件中的記錄。
#!/usr/bin/perl -w if (@ARGV) { foreach (@ARGV) { if ($ARGV[0] =~ "all") { open(FILE,"</etc/hosts")||die"cannot open the file: $!\n"; while (<FILE>) { if ($_ =~ /^10/) { my @host=split; print "########It's coping file to $host[1]########\n"; system("/usr/bin/rsync install_puppet.sh $host[0]:/"); system("/usr/bin/ssh $host[0] /install_puppet.sh"); } } close FILE; } else { print "########It's coping file to $_########\n"; system("/usr/bin/rsync install_puppet.sh $_:/"); system("/usr/bin/ssh $_ /install_puppet.sh"); } } } else { print "1.Usage: $0 hostname1 hostname2 ... \n"; print "2.Usage: $0 all\n"; }
這樣執行將兩個腳本放在同一目錄,而後執行./push.pl all,而後就不用管了,全部服務器都自動部署對應版本的puppet客戶端了。