[root@lianglab puppet-2.7.14]# ll /var/lib/puppet/
總計 36
drwxr-x--- 2 puppet puppet 4096 06-15 12:30 bucket
drwxr-xr-x 2 root root 4096 06-15 12:30 facts
drwxr-xr-x 2 root root 4096 06-15 12:30 lib
drwxr-x--- 2 puppet puppet 4096 06-15 12:30 reports
drwxr-x--- 2 puppet puppet 4096 06-15 12:30 rrd
drwxr-x--- 2 puppet puppet 4096 06-15 12:30 server_data
drwxrwx--x 8 puppet root 4096 06-15 12:30 ssl
drwxr-xr-t 2 root root 4096 06-15 12:30 state
drwxr-x--- 2 puppet puppet 4096 06-15 12:30 yaml
====================================客戶端配置=========================================
[root@lianglab4 ~]# echo "10.13.89.165 lianglab.com" >> /etc/hosts
[root@lianglab4 ~]# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 lianglab4.com lianglab4 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
10.13.89.165 lianglab.com
[root@lianglab4 ~]#
[root@lianglab4 ~]# hostname
lianglab4.com
[root@lianglab4 ~]# cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=lianglab4.com
[root@lianglab4 ~]#
在客戶端安裝ruby facter puppet的步驟與服務端安裝同樣
yum install ruby ruby-libs ruby-rdoc
wget http://downloads.puppetlabs.com/facter/facter-1.6.8.tar.gz
tar -zxvf facter-1.6.8.tar.gz
cd facter-1.6.8
ruby install.rb
wget http://downloads.puppetlabs.com/puppet/puppet-2.7.14.tar.gz
tar -zxvf puppet-2.7.14.tar.gz
cd puppet-2.7.14
ruby install.rb
特別說明:請注意客戶端和服務器端版本要一致。若是版本不一致的話,那麼高版本的只能是puppet server,另外一臺只能做爲puppet客戶端,也就是說puppet 服務端的版本能夠大於或者等於客戶端版本,不能夠小於
其中區別一些以下:
[root@lianglab4 puppet-2.7.14]# cp conf/redhat/client.init /etc/init.d/puppet
[root@lianglab4 puppet-2.7.14]# chkconfig --add puppet
[root@lianglab4 puppet-2.7.14]# chkconfig --level 35 puppet on
[root@lianglab4 puppet-2.7.14]# groupadd puppet
[root@lianglab4 puppet-2.7.14]# useradd -g puppet -s /bin/false -M puppet
[root@lianglab4 puppet-2.7.14]#
測試解析與puppetmaster端口是否暢通
[root@lianglab4 puppet-2.7.14]# telnet lianglab.com 8140
Trying 10.13.89.165...
Connected to lianglab.com (10.13.89.165).
Escape character is '^]'.
Connection closed by foreign host.
[root@lianglab4 puppet-2.7.14]#
[root@lianglab4 puppet-2.7.14]# /etc/init.d/puppet start
啓動 puppet:Could not prepare for execution: Could not create PID file: /var/lib/puppet/run/agent.pid
[肯定]
[root@lianglab4 puppet-2.7.14]#
puppetd --test --server lianglab.com命令是指puppetd 從 lianglab.com去讀取
puppet配置文件. 第一次鏈接,雙方會進行ssl證書的驗證,這是一個新的客戶端,在服務器端那裏尚未被認證,所以須要在服務器端進行證書認證
如下這步批准證書是在服務端操做
A。咱們要向服務器申請證書
[root@lianglab4 puppet-2.7.14]# puppetd --test --server lianglab.com
warning: peer certificate won't be verified in this SSL session
info: Caching certificate for ca
warning: peer certificate won't be verified in this SSL session
warning: peer certificate won't be verified in this SSL session
info: Creating a new SSL certificate request for lianglab4.com
info: Certificate Request fingerprint (md5): 50:2D:89:E5:B8:6A:11:4A:6E:5D:AB:3F:47:21:A1:12
warning: peer certificate won't be verified in this SSL session
warning: peer certificate won't be verified in this SSL session
warning: peer certificate won't be verified in this SSL session
Exiting; no certificate found and waitforcert is disabled
[root@lianglab4 puppet-2.7.14]#
B:服務端接受申請
[root@lianglab puppet-2.7.14]# puppetca --list #查看當前待批准證書列表
lianglab4.com (50:2D:89:E5:B8:6A:11:4A:6E:5D:AB:3F:47:21:A1:12)
[root@lianglab puppet-2.7.14]#
[root@lianglab puppet-2.7.14]# puppetca -s lianglab4.com #批准當前證書
notice: Signed certificate request for lianglab4.com
notice: Removing file Puppet::SSL::CertificateRequest lianglab4.com at '/var/lib/puppet/ssl/ca/requests/lianglab4.com.pem'
[root@lianglab puppet-2.7.14]#
查看驗證簽名,注意前面的+號,說明已經簽名
[root@lianglab puppet-2.7.14]# puppetca -a --list
+ lianglab.com (71:46:13:EC:A1:FB:E2:43:57:6B:AA:14:CC:4B:0E:5E) (alt names: DNS:lianglab.com, DNS:puppet, DNS:puppet.com)
+ lianglab4.com (14:C3:F9:3C:7D:73:0B:08:CF:C4:1E:B6:71:7B:9C:A7)
[root@lianglab puppet-2.7.14]#
--------------------------------------------------------------------------------------------------
若是要批准所有證書
puppetca -s -a
也能夠在puppetmaster端的puppet.conf加入這行:
autosign = true
服務端就自動簽證書
--------------------------------------------------------------------------------------------------
C:回到客戶端操做,從服務端取回已批准的證書
[root@lianglab4 puppet-2.7.14]# puppetd --test --server lianglab.com
warning: peer certificate won't be verified in this SSL session
info: Caching certificate for
lianglab4.com
info: Caching certificate_revocation_list for ca
info: Caching catalog for
lianglab4.com
info: Applying configuration version '1371275671'
info: Creating state file /var/lib/puppet/state/state.yaml
notice: Finished catalog run in 0.15 seconds
[root@lianglab4 puppet-2.7.14]#
注意:上文中的紅色部分,生成證書時主界面會寫入證書,若是生成證書後再更改主機名證書就失效了。
並且請不要用cliens相似簡稱名字,而應該用lianglab4.com這樣全名申請證書,從新審批舊機器的新證書,
當申請到證書之後咱們對比下這兩個文件,他們的MD5值是同樣的。
驗證證書是否正確
服務端:
[root@lianglab puppet-2.7.14]# md5sum /var/lib/puppet/ssl/ca/signed/lianglab4.com.pem
4b059e3937cfee49ff98d5bd5557b2db /var/lib/puppet/ssl/ca/signed/lianglab4.com.pem
[root@lianglab puppet-2.7.14]#
客戶端:
[root@lianglab4 puppet]# md5sum /md5sum /var/lib/puppet/ssl/certs/lianglab4.com.pem
4b059e3937cfee49ff98d5bd5557b2db /var/lib/puppet/ssl/certs/lianglab4.com.pem
------------------------------------------------------------------------------------------------
其實申請證書的過程就是服務器端生成證書,併發送到客戶端的過程。
若是由於意外要從新給舊機器審批證書,咱們須要作如下兩點才能夠從新註冊。
出現修改主機名問題引發沒法認證,須要從新申請證書,操做如下兩個步驟:
puppetca --clean lianglab4.com #清除服務端的證書。
或者rm -rf /var/lib/puppet/ssl/ca/signed/lianglab4.com.pem刪除已經註冊給客戶機「client.gongchang.com」的證書;
rm -rf /var/lib/puppet/ssl/ #客戶端要刪掉ssl目錄。而後執行a、b、c三步。
服務端:
[root@server ca]# rm -rf /var/lib/puppet/ssl/ca/signed/client1.viong.com.pem
客戶端:
[root@client1 puppet-2.7.14]# rm -rf /var/lib/puppet/ssl/
------------------------------------------------------------------------------------------------
功能測試-------------------------------------------------------
在服務器端新建一個/etc/puppet/manifests/site.pp文件,新建pp文件測試,puppet的第一個執行的代碼是在/etc/puppet/manifest/site.pp所以這個文件必須存在,並且其餘的代碼也要經過代碼來調用.
[root@lianglab puppet-2.7.14]# vi /etc/puppet/manifests/site.pp
node default {
file {"/tmp/Puppet_test.txt": #這是文件路徑名;
content=>"This is test of PUPPET"; } #這是文件的內容;
}
上面的代碼對默認連入的puppet客戶端執行一個操做,在/tmp目錄生成一個Puppet_test.txt文件,內容是goThis is test of PUPPET! 並自動回車換行
初次建立pp文件,須要重啓puppetmaster
[root@lianglab puppet-2.7.14]# /etc/init.d/puppetmaster restart
中止 puppetmaster:[肯定]
啓動 puppetmaster:[肯定]
[root@lianglab puppet-2.7.14]#
[root@lianglab puppet-2.7.14]# puppet /etc/puppet/manifests/site.pp #執行此命令使site.pp配置生效;
warning: Implicit invocation of 'puppet apply' by passing files (or flags) directly
to 'puppet' is deprecated, and will be removed in the 2.8 series. Please
invoke 'puppet apply' directly in the future.
notice: /Stage[main]//Node[default]/File[/tmp/Puppet_test.txt]/ensure: defined content as '{md5}d395f8aa0b8a631c726a9a3f411093c6'
notice: Finished catalog run in 0.04 seconds
[root@lianglab puppet-2.7.14]#
咱們在回到客戶端執行命令會獲得以下提示信息:
[root@lianglab4 puppet]# puppetd --test --server lianglab.com
info: Caching catalog for lianglab4.com
info: Applying configuration version '1371277359'
notice: /Stage[main]//Node[default]/File[
/tmp/Puppet_test.txt]/ensure: defined content as '{md5}d395f8aa0b8a631c726a9a3f411093c6'
notice: Finished catalog run in 0.05 seconds
[root@lianglab4 puppet]#
[root@lianglab4 puppet]# cat /tmp/Puppet_test.txt
This is test of PUPPET
[root@lianglab4 puppet]#
設置客戶端的守護進程
[root@lianglab4 puppet]# service puppet stop
[root@lianglab4 puppet]# puppetd --test --server lianglab.com --verbose --waitforcert 100
info: Caching catalog for lianglab4.com
info: Applying configuration version '1371277359'
notice: Finished catalog run in 0.03 seconds
[root@lianglab4 puppet]#
--server 服務端FQDN –-verbose 輸出冗餘信息 –-waitforcert 超時100
部分狀況下puppet服務會沒法啓動,且提示puppet已經啓動,這個時候須要刪除一個文件:
[root@client ~]#/usr/sbin/puppetd --test --server master.gongchang.com
notice: Run of Puppet configuration client already in progress; skipping
[root@client ~]#rm /var/lib/puppet/state/puppetdlock
Puppet C/S環境搭建完畢。
文檔先整理到這來,資源管理這塊涉及到不少內容須要花時間慢慢研究的,
文章整理共計花費4個小時多,可是仍是挺順利的。