廢話不多說了,下面記錄下Puppet在Centos下的部署過程:
puppet是什么
puppet是一種基於ruby語言開發的Lnux、Unix、windows平台的集中配置管理系統。它使用自有的puppet描述語言,可管理配置文件file、用戶user、cron任務、軟件包、系統服務等系統實體。
puppet把這些系統實體稱之為資源,puppet設計目標是簡化對這些資源的管理以及妥善處理資源間的依賴關系。
puppet依賴於C/S(客戶端/服務器)的部署架構。它需要在puppet服務器上安裝puppet-server軟件包(以下簡稱master),在需要管理的目標主機上安裝puppet客戶端軟件(以下簡稱agent)。
當agent連接上master后,定義在master端的配置文件會被編譯,然后在agent上運行。每個agent默認30分鍾會連接一次master,確認配置信息的更新情況。但是這種方式在很多場景下不是很符合系統管理員的要求,所以很多系統管理員也會將agent通過crontab(任務計划)來管理,這樣會更加靈活一些。
puppet優點
puppet的語法允許你創建一個單獨的腳本,用來在你所有的目標主機上建立一個用戶。所有的目標主機會依次使用適合本地系統的語法來解釋和執行這個模塊。如果這個配置是在Red Hat服務器上執行的話,建立用戶使用useradd命令,如果這個配置是在FreddBSD服務器上執行的話,則使用adduser命令。
puppet另外一個卓越的地方就是它的靈活性。源於開源軟件的天性,你可以自由地獲得puppet的源代碼。如果你遇到問題並且有能力處理的話,你可以修改或加強puppet的代碼使其適用於你的環境,然后解決這個問題。
puppet也是易於擴展的。定制軟件包的支持功能和特殊的系統環境配置能夠快速簡單地添加至puppet的安裝程序中。
1)基本安裝
機器信息(centos6.8) IP地址 主機名 角色 182.48.115.233 Master-node Master 182.38.115.235 Agent-node1 Agent 182.38.115.235 Agent-node2 Agent 182.38.115.235 Agent-node3 Agent 准備工作(在Master和Agent上都要准備的) 1)關閉selinux 2)關閉iptables,這是為了避免各種麻煩,你可以通過打開端口,而不需要關閉iptables 3)設置host文件,由於puppet需要用FQDN,一般實驗環境都是沒有dns,所以通過hosts文件設置 4)設置ntp,同步時間,這個也是必須的。 5)設置源,根據你希望使用的版本,設置不同的源.我是啟用了EPEL和Puppet官方的源 0)關閉selinux和防火牆(Master和Agent都要做) [root@Master-node ~]# setenforce 0 [root@Master-node ~]# /etc/init.d/iptables stop 1)綁定hosts(Master和Agent都要做) [root@Master-node ~]# cat /etc/hosts ...... 182.48.115.233 Master-node 182.48.115.235 Agent-node1 182.48.115.236 Agent-node2 182.48.115.237 Agent-node3 [root@Agent-node1 ~]# cat /etc/hosts 182.48.115.235 Agent-node1 182.48.115.233 Master-node [root@Agent-node2 ~]# cat /etc/hosts 182.48.115.235 Agent-node2 182.48.115.233 Master-node [root@Agent-node3 ~]# cat /etc/hosts 182.48.115.235 Agent-node3 182.48.115.233 Master-node 2)同步時間(Master和Agent端都要做) [root@Master-node ~]# yum -y install ntp [root@Master-node ~]# ntpdate ntp.api.bz 3)安裝Puppet Puppet 不在CentOS的基本源中,需要加入PuppetLabs 提供的官方源(Master和Agent都要操作) [root@Master-node ~]# wget http://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-1.noarch.rpm [root@Master-node ~]# yum install puppetlabs-release-6-1.noarch.rpm [root@Master-node ~]# yum update -----------Master端----------- [root@Master-node ~]# yum install -y ruby facter puppet-server 啟動 [root@Master-node ~]# service puppet start [root@Master-node ~]# service puppetmaster start 設為自動開機 [root@Master-node ~]# chkconfig puppet on [root@Master-node ~]# chkconfig puppetmaster on ----------Agent端----------- [root@Agent-node1 ~]# yum install -y ruby facter puppet 啟動 [root@Agent-node1 ~]# service puppet start 設置開機自啟動 [root@Agent-node1 ~]# chkconfig puppet on 配置puppet [root@Agent-node1 ~]# vim /etc/puppet/puppet.conf //底部添加下面一行 ..... server = Master-node [root@Agent-node1 ~]# /etc/init.d/puppet restart
從日志中我們可以看出第一次啟動master端時,puppet服務會在本地創建認證中心,給自己授權證書和key,這個我們可以在/var/lib/puppet/ssl看到那些證書和key。如下:
[root@Master-node ~]# tail -f /var/log/messages ...... Jul 25 15:02:13 puppet01 puppet-master[23689]: Signed certificate request for ca Jul 25 15:02:14 puppet01 puppet-master[23689]: Master-node has a waiting certificate request Jul 25 15:02:14 puppet01 puppet-master[23689]: Signed certificate request for Master-node Jul 25 15:02:14 puppet01 puppet-master[23689]: Removing file Puppet::SSL::CertificateRequest Master-node at '/var/lib/puppet/ssl/ca/requests/Master-node.pem' Jul 25 15:02:14 puppet01 puppet-master[23689]: Removing file Puppet::SSL::CertificateRequest Master-node at '/var/lib/puppet/ssl/certificate_requests/Master-node.pem' Jul 25 15:02:14 puppet01 puppet-master[23727]: Reopening log files Jul 25 15:02:14 puppet01 puppet-master[23727]: Starting Puppet master version 3.8.7 Jul 25 15:03:00 puppet01 puppet-master[23727]: puppet02.bkjk.cn has a waiting certificate request [root@Master-node ~]# ll /var/lib/puppet/ssl total 28 drwxr-xr-x 5 puppet puppet 4096 Jul 25 15:02 ca drwxr-xr-x 2 puppet puppet 4096 Jul 25 15:02 certificate_requests drwxr-xr-x 2 puppet puppet 4096 Jul 25 15:02 certs -rw-r--r-- 1 puppet puppet 967 Jul 25 15:02 crl.pem drwxr-x--- 2 puppet puppet 4096 Jul 25 15:02 private drwxr-x--- 2 puppet puppet 4096 Jul 25 15:02 private_keys drwxr-xr-x 2 puppet puppet 4096 Jul 25 15:02 public_keys 這個目錄和/etc/puppet/puppet.conf文件中配置的ssldir路徑有關系 也可以查看master端給自己授權的證書文件 [root@Master-node ~]# ll /var/lib/puppet/ssl/ca/signed total 4 -rw-r--r-- 1 puppet puppet 2029 Jul 25 15:02 Master-node.pem
2)建立master和agent之間的認證關系(三種注冊方式)
Agent需要向服務器端發出請求, 讓服務器對客戶端進行管理. 這其實是一個證書簽發的過程. 第一次運行puppet客戶端的時候會生成一個SSL證書並指定發給Puppet服務端,
服務器端如果同意管理客戶端,就會對這個證書進行簽發。
Agent在第一次連接master的時候會向master申請證書,如果沒有master沒有簽發證書,那么puppet agent和master的連接是否建立成功的,agent會持續等待master簽發證書,
並會每隔2分鍾去檢查master是否簽發證書。
Puppet注冊方式基本上有三種:自動注冊、手動注冊和預簽名注冊。
--------------------------------------------------------------------------------------------------------------------------------------
一、手動注冊(批量效率高)
手動注冊是由Agent端先發起證書申請請求,然后由Puppetserver端確認認證方可注冊成功,這種注冊方式安全系數中等,逐一注冊(puppet cert --sign certnmame)
在節點數量較大的情況下是比較麻煩的,效率也低,批量注冊(puppet cert --sign --all)效率很高,一次性便可注冊所有的Agent的請求,但是這種方式安全系數較低,
因為錯誤的請求也會被注冊上。
1)需要先在Agent節點申請注冊(三台Agent節點機都要操作)
由於已經Agent的puppet.conf文件里設置了server地址,因此下面向Master請求認證的命令中不需要跟服務端地址。
否則需要在下面的命令中添加Master服務端地址,即添加"--server Master-node"
[root@Agent-node1 ~]# puppet agent --test
Info: Creating a new SSL key for agent-node1
Info: Caching certificate for ca
Info: csr_attributes file loading from /etc/puppet/csr_attributes.yaml
Info: Creating a new SSL certificate request for agent-node1
Info: Certificate Request fingerprint (SHA256): E0:B4:04:52:46:C0:D4:38:92:7B:EA:90:3A:5E:EF:D8:6E:85:D3:61:77:6A:34:10:24:0F:15:B6:1A:9C:13:EC
Info: Caching certificate for ca
Exiting; no certificate found and waitforcert is disabled
2)Master服務器端確定認證
現在Master服務器端查看認證情況
[root@Master-node ~]# puppet cert --list
"agent-node1" (SHA256) E0:B4:04:52:46:C0:D4:38:92:7B:EA:90:3A:5E:EF:D8:6E:85:D3:61:77:6A:34:10:24:0F:15:B6:1A:9C:13:EC
"agent-node2" (SHA256) FD:FC:10:22:48:BD:17:3C:6E:3E:C5:A1:32:6A:CD:E8:E7:47:33:F9:F2:34:45:C9:59:57:B1:0D:13:10:FE:37
"agent-node3" (SHA256) 55:C0:CA:EF:F1:1A:3F:E2:53:0D:A8:F6:32:EB:8C:D8:B2:C8:51:9F:0A:4B:4C:0A:78:C5:57:E6:49:02:FC:90
[root@Master-node ~]# puppet cert --list --all //加--all參數,就能查看到puppet給自己簽發的本地證書了
"agent-node1" (SHA256) E0:B4:04:52:46:C0:D4:38:92:7B:EA:90:3A:5E:EF:D8:6E:85:D3:61:77:6A:34:10:24:0F:15:B6:1A:9C:13:EC
"agent-node2" (SHA256) FD:FC:10:22:48:BD:17:3C:6E:3E:C5:A1:32:6A:CD:E8:E7:47:33:F9:F2:34:45:C9:59:57:B1:0D:13:10:FE:37
"agent-node3" (SHA256) 55:C0:CA:EF:F1:1A:3F:E2:53:0D:A8:F6:32:EB:8C:D8:B2:C8:51:9F:0A:4B:4C:0A:78:C5:57:E6:49:02:FC:90
+ "master-node" (SHA256) DB:81:FB:58:D7:FF:DC:17:3C:C2:4D:7B:2E:DF:35:C2:F5:4D:B8:D2:AE:9D:EF:E0:73:44:11:07:C4:C2:72:23
以上結果中:
左邊有+號的,表示已經簽發,puppet首先會給自己簽發一個本地證書;客戶端的證書前沒+號,這就等待服務端簽發。
接着Master服務端簽發證書,及注冊Agent節點
[root@Master-node ~]# puppet cert --list agent-node1
[root@Master-node ~]# puppet cert --list agent-node2
[root@Master-node ~]# puppet cert --list agent-node3
[root@Master-node ~]# puppet cert --sign --all //上面三個命令是分別給單獨的一個Agent頒發證書,效率低下!可以使用這個命令代替,表示簽發所有Agent的證書
再次查看認證情況,發現已經都認證了(左邊都有+號了)
[root@Master-node ~]# puppet cert --list --all
+ "agent-node1" (SHA256) 86:61:2A:99:38:54:E3:FD:E0:8F:40:D4:2D:75:83:6F:64:B6:36:E1:B0:97:0D:B5:82:9C:69:95:D2:95:98:92
+ "agent-node2" (SHA256) 63:BF:AA:C2:C5:1E:A6:64:47:72:85:B3:4B:32:3E:07:C3:70:8D:86:D3:86:53:1A:FF:F9:9E:93:46:46:CB:13
+ "agent-node3" (SHA256) 41:B1:A7:3C:E3:7D:47:32:21:4F:25:8A:5E:96:77:1A:E0:FE:45:C3:42:0C:BC:D7:0A:0A:D1:E9:BF:FA:E1:96
+ "master-node" (SHA256) DB:81:FB:58:D7:FF:DC:17:3C:C2:4D:7B:2E:DF:35:C2:F5:4D:B8:D2:AE:9D:EF:E0:73:44:11:07:C4:C2:72:23
另一種查看認證的方法:
[root@Master-node ~]# tree /var/lib/puppet/ssl/ //可以使用"yum install -y tree" 安裝tree命令
/var/lib/puppet/ssl/
├── ca
│ ├── ca_crl.pem
│ ├── ca_crt.pem
│ ├── ca_key.pem
│ ├── ca_pub.pem
│ ├── inventory.txt
│ ├── private
│ │ └── ca.pass
│ ├── requests
│ ├── serial
│ └── signed
│ ├── agent-node1.pem
│ ├── agent-node2.pem
│ ├── agent-node3.pem
│ └── master-node.pem
├── certificate_requests
├── certs
│ ├── ca.pem
│ └── master-node.pem
├── crl.pem
├── private
├── private_keys
│ └── master-node.pem
└── public_keys
└── master-node.pem
最后在Agent端進行motd模塊測試(即客戶端取回通過的證書)
[root@Agent-node1 ~]# puppet agent --test //--test也可以替換為-t
Info: Caching certificate for agent-node1
Info: Caching certificate_revocation_list for ca
Info: Caching certificate for agent-node1
Warning: Unable to fetch my node definition, but the agent run will continue:
Warning: undefined method `include?' for nil:NilClass
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for agent-node1
Info: Applying configuration version '1495876267'
Info: Creating state file /var/lib/puppet/state/state.yaml
Notice: Finished catalog run in 0.06 seconds
-------------------------------------------------------------------------------
也可以直接使用命令"puppet agent --no-daemonize --onetime --verbose --debug",打印證書申請過程中的詳細信息
--no-daemonize 前台輸出日志
--verbose 輸入更加詳細的日志
--debug 更加詳細的日志,排錯的時候使用
--test 表示測試,就帶一個–test參數就可以
-------------------------------------------------------------------------------
-------------------------------證書管理------------------------------
當出現問題需要重新申請證書或重新安裝puppet時使用,需要注銷證書和刪除證書
注銷證書既是要證書過期(--revoke)
[root@Master-node ~]# puppet cert --revoke agent-node1
Notice: Revoked certificate with serial 10
[root@Master-node ~]# puppet cert --list --all //如下,過期的證書簽名是"-"號
+ "agent-node2" (SHA256) 63:BF:AA:C2:C5:1E:A6:64:47:72:85:B3:4B:32:3E:07:C3:70:8D:86:D3:86:53:1A:FF:F9:9E:93:46:46:CB:13
+ "agent-node3" (SHA256) 41:B1:A7:3C:E3:7D:47:32:21:4F:25:8A:5E:96:77:1A:E0:FE:45:C3:42:0C:BC:D7:0A:0A:D1:E9:BF:FA:E1:96
+ "master-node" (SHA256) DB:81:FB:58:D7:FF:DC:17:3C:C2:4D:7B:2E:DF:35:C2:F5:4D:B8:D2:AE:9D:EF:E0:73:44:11:07:C4:C2:72:23
- "agent-node1" (SHA256) 86:61:2A:99:38:54:E3:FD:E0:8F:40:D4:2D:75:83:6F:64:B6:36:E1:B0:97:0D:B5:82:9C:69:95:D2:95:98:92 (certificate revoked)
[root@Master-node ~]# puppet cert --revoke --all //注銷所有證書
上面只是讓證書失效,客戶端連接會失敗,並沒有刪除證書文件。
刪除證書(--clean)
[root@Master-node ~]# puppet cert --clean agent-node1 //刪除agent-node1證書
[root@Master-node ~]# puppet cert --clean --all //刪除所有證書
證書簽名的過期或刪除需要重啟puppetmaster服務后才能生效。
[root@Master-node ~]# /etc/init.d/puppetmaster restart
Stopping puppetmaster: [ OK ]
Starting puppetmaster: [ OK ]
重啟后,puppet會給自己自動簽發一個本地證書
[root@Master-node ~]# puppet cert --list --all
+ "master-node" (SHA256) 25:13:02:B7:01:44:08:E9:A0:C6:66:4F:A9:A9:93:2E:7E:E6:ED:E9:91:85:7B:65:E3:ED:26:FB:C6:7C:B6:56
注意刪除證書到重新請求證書的流程:
在Master端刪除證書(puppet cert --clean agent-node1)
在Agent端刪除注冊過的證書文件:rm -rf /var/lib/puppet/ssl/*
在Agent端重新請求證書(puppet agent ----test )
-----------------------------------------------------------------------------------------------------------------------------------------------
二、自動注冊(安全系數低,效率高)
這種注冊方式簡單來講是通過Puppetmaster端的ACL列表進行控制的,安全系統較低,也就是說符合預先定義的ACL列表中的所有節點請求不需要確認都會被自動注冊上,
也就是說你只需要知道ACL列表要求,其次能和PuppetMaster端通信便可輕易注冊成功。當然,它的最大優點就是效率非常高。
1)清除Master端已經注冊的agent的證書
[root@Master-node ~]# puppet cert --clean agent-node1 //可以一個個的針對單個agent節點進行清除
[root@Master-node ~]# puppet cert --clean --all //也可以清除所有agent節點的證書
2)在agent端刪除注冊的所有信息,包括證書。這個很重要!!當在PupperMaster端刪除agent的證書后,一定要登錄對應的agent節點上執行下面的操作:刪除注冊過的證書,
否則再次注冊就會報錯失敗!
[root@Agent-node1 ~]# rm -rf /var/lib/puppet/ssl/*
3)在master端編寫ACL列表
設置master自動簽發所有的證書
[root@Master-node ~]# vim /etc/puppet/puppet.conf //在文件底部添加下面內容
[main]
autosign = true
autosign = /etc/puppet/autosign.conf
[root@Master-node ~]# vim /etc/puppet/autosign.conf //設置下面內容,*表示允許所有域下的主機注冊本Master端的證書
*
[root@Master-node ~]# /etc/init.d/puppet restart
[root@Master-node ~]# service puppetmaster restart
[root@Master-node ~]# puppet cert --list --all
+ "master-node" (SHA256) 47:D4:F5:FE:73:62:0B:51:BD:E6:BD:A5:1C:7E:04:75:72:80:5C:32:9C:E2:01:46:39:EA:3B:D9:F6:FC:A7:CE
接着在所有的Agent節點申請證書
[root@Agent-node1 ~]# puppet agent --test
Info: Creating a new SSL key for agent-node1
Info: Caching certificate for ca
Info: csr_attributes file loading from /etc/puppet/csr_attributes.yaml
Info: Creating a new SSL certificate request for agent-node1
Info: Certificate Request fingerprint (SHA256): 79:F5:6B:9B:0C:38:68:B7:A6:C3:9E:E4:7E:19:76:8B:61:35:CA:D0:66:E4:81:B4:15:09:DB:24:ED:3F:E2:3F
Info: Caching certificate for agent-node1
Info: Caching certificate_revocation_list for ca
Info: Caching certificate for ca
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for agent-node1
Info: Applying configuration version '1495879417'
Notice: Finished catalog run in 0.05 seconds
然后在Master端查看證書是否已經自動注冊上了。如下,發現已經自動注冊了
[root@Master-node ~]# puppet cert --list --all
+ "agent-node1" (SHA256) EE:EE:FE:C8:41:8D:C4:42:59:59:84:FB:A3:CA:F7:20:8A:94:F5:70:5A:2F:1E:A3:D3:48:B4:70:2F:2C:76:AA
+ "agent-node2" (SHA256) 00:C7:14:7D:1B:2F:D9:5D:B9:F5:A1:24:89:FE:65:C2:CF:C7:76:58:CC:61:4F:07:4D:89:22:B2:9B:33:EF:C5
+ "agent-node3" (SHA256) 7C:24:5D:9A:BD:C6:A4:33:04:21:9E:9D:BA:F2:5F:1B:01:84:E1:C4:6C:95:2F:12:A9:7C:BE:3E:E8:48:BD:38
+ "master-node" (SHA256) 99:8A:53:84:A4:BA:38:39:72:77:E5:11:47:1B:C2:29:BE:67:07:03:5D:08:8C:A3:85:49:3F:EF:B4:9A:C4:C3
最后在Agent節點測試
[root@Agent-node1 ~]# puppet agent --test
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for agent-node1
Info: Applying configuration version '1495879417'
Notice: Finished catalog run in 0.07 seconds
-----------------------------------------------------------------------------------------------------------------------------------------------
三、預簽名注冊(推薦生產環境中使用此方式進行注冊,既安全又可靠!)
預簽名注冊是在agent端未提出申請的情況下,預先在puppet master端生成agent端的證書,然后把證書復制到agent節點對應的目錄下即可注冊成功,這樣可以避
免自動簽名的危險。這種方式安全系數最高,但是操作麻煩,需要提前預知所有節點服務器的certname名稱,其次需要將生成的證書逐步copy到所有節點上去。
不過,如果你的系統中安裝了kickstart或者cobbler這樣的自動化工具,倒是可以將證書部分轉換成腳本集成到統一自動化部署中
1)清除Master端已經注冊的agent的證書
[root@Master-node ~]# puppet cert --clean --all //清除所有注冊過的證書,也可以指定某個Agent節點的證書清除
[root@Master-node ~]# puppet cert --list --all //查看證書是否已清除
[root@Master-node ~]# /etc/init.d/puppetmaster restart
2)在agent端刪除注冊的所有信息,包括證書。
[root@Agent-node1 ~]# rm -rf /var/lib/puppet/*
3)在Master端刪除自動注冊ACL列表
[root@Master-node ~]# mv /etc/puppet/autosign.conf /etc/puppet/autosign.conf.bak
4)在Master端預先生成Agent證書(這個只能針對agent端的節點一個個的生成證書了)
[root@Master-node ~]# puppet cert generate agent-node1 //老版本使用命令"puppetca --generate agent-node1"
[root@Master-node ~]# puppet cert generate agent-node2
[root@Master-node ~]# puppet cert generate agent-node3
查看證書
[root@Master-node ~]# puppet cert --list --all
+ "agent-node1" (SHA256) E0:57:E4:D4:2A:10:46:68:E7:58:DE:3C:6A:2C:9F:82:7B:5F:BC:6E:F9:84:E7:A2:F3:E3:9D:02:5E:CB:EC:80
+ "agent-node2" (SHA256) F8:6F:55:37:8C:4D:D0:33:A5:EA:5E:2D:1A:EA:3E:52:27:9F:0A:65:E2:81:56:2E:7A:EF:67:8A:F6:37:8D:50
+ "agent-node3" (SHA256) 50:9E:80:75:D8:13:2D:A4:CB:04:6C:2E:70:11:90:53:97:37:07:0D:F0:AB:66:40:60:87:4C:51:74:1A:00:ED
+ "master-node" (SHA256) 2A:EB:D3:60:C4:F6:57:12:9B:2E:7E:E8:3A:B8:11:B6:A4:57:F4:F9:91:7D:E7:E9:25:64:DD:51:C8:26:8E:75
6)然后把Master端預先生成的證書copy到agent端的各個節點上
[root@Agent-node1 ~]# mkdir -p /var/lib/puppet/ssl/private_keys
[root@Agent-node1 ~]# mkdir -p /var/lib/puppet/ssl/certs
[root@Agent-node1 ~]# rsync -e "ssh -p22" -avpgolr 182.48.115.233:/var/lib/puppet/ssl/private_keys/agent-node1.pem /var/lib/puppet/ssl/private_keys/
[root@Agent-node1 ~]# rsync -e "ssh -p22" -avpgolr 182.48.115.233:/var/lib/puppet/ssl/certs/agent-node1.pem /var/lib/puppet/ssl/certs/
[root@Agent-node1 ~]# rsync -e "ssh -p22" -avpgolr 182.48.115.233:/var/lib/puppet/ssl/certs/ca.pem /var/lib/puppet/ssl/certs/
[root@Agent-node2 ~]# mkdir -p /var/lib/puppet/ssl/private_keys
[root@Agent-node2 ~]# mkdir -p /var/lib/puppet/ssl/certs
[root@Agent-node2 ~]# rsync -e "ssh -p22" -avpgolr 182.48.115.233:/var/lib/puppet/ssl/private_keys/agent-node2.pem /var/lib/puppet/ssl/private_keys/
[root@Agent-node2 ~]# rsync -e "ssh -p22" -avpgolr 182.48.115.233:/var/lib/puppet/ssl/certs/agent-node2.pem /var/lib/puppet/ssl/certs/
[root@Agent-node2 ~]# rsync -e "ssh -p22" -avpgolr 182.48.115.233:/var/lib/puppet/ssl/certs/ca.pem /var/lib/puppet/ssl/certs/
[root@Agent-node3 ~]# mkdir -p /var/lib/puppet/ssl/private_keys
[root@Agent-node3 ~]# mkdir -p /var/lib/puppet/ssl/certs
[root@Agent-node3 ~]# rsync -e "ssh -p22" -avpgolr 182.48.115.233:/var/lib/puppet/ssl/private_keys/agent-node3.pem /var/lib/puppet/ssl/private_keys/
[root@Agent-node3 ~]# rsync -e "ssh -p22" -avpgolr 182.48.115.233:/var/lib/puppet/ssl/certs/agent-node3.pem /var/lib/puppet/ssl/certs/
[root@Agent-node3 ~]# rsync -e "ssh -p22" -avpgolr 182.48.115.233:/var/lib/puppet/ssl/certs/ca.pem /var/lib/puppet/ssl/certs/
最后在各個Agent節點測試
[root@Agent-node1 ~]# puppet agent -t
Info: Caching certificate_revocation_list for ca
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for agent-node1
Info: Applying configuration version '1495896021'
Info: Creating state file /var/lib/puppet/state/state.yaml
Notice: Finished catalog run in 0.07 seconds
在Master端查看證書情況
[root@Master-node ~]# tree /var/lib/puppet/ssl/
/var/lib/puppet/ssl/
├── ca
│ ├── ca_crl.pem
│ ├── ca_crt.pem
│ ├── ca_key.pem
│ ├── ca_pub.pem
│ ├── inventory.txt
│ ├── private
│ │ └── ca.pass
│ ├── requests
│ ├── serial
│ └── signed
│ ├── agent-node1.pem
│ ├── agent-node2.pem
│ ├── agent-node3.pem
│ └── master-node.pem
├── certificate_requests
├── certs
│ ├── agent-node1.pem
│ ├── agent-node2.pem
│ ├── agent-node3.pem
│ ├── ca.pem
│ └── master-node.pem
├── crl.pem
├── private
├── private_keys
│ ├── agent-node1.pem
│ ├── agent-node2.pem
│ ├── agent-node3.pem
│ └── master-node.pem
└── public_keys
├── agent-node1.pem
├── agent-node2.pem
├── agent-node3.pem
└── master-node.pem
3)Puppet的Dashboard搭建
puppet dashboard是GUI(圖形用戶界面)方式管理puppet,可以分析puppet運行日志。
1)安裝mysql
[root@Master-node ~]# yum install -y mysql mysql-devel mysql-server
[root@Master-node ~]# vim /etc/my.cnf //在[mysqld]字段,增加下面一行內容
[mysqld]
......
max_allowed_packet = 32M
啟動服務
[root@Master-node ~]# /etc/init.d/mysqld start
[root@Master-node ~]# chkconfig mysqld on
設置mysql密碼為"password"
[root@Master-node ~]# mysqladmin -u root password 'password'
創建一個dashboard數據庫
[root@Master-node ~]# mysql -ppassword
mysql> CREATE DATABASE dashboard CHARACTER SET utf8;
mysql> CREATE USER 'dashboard'@'localhost' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON dashboard.* TO 'dashboard'@'localhost';
mysql> FLUSH PRIVILEGES;
2)安裝Passenger+Apache+Dashboard
使用Apache+Passenger部署高性能PuppetMaster,代替原來的WEBrick,提高並發性能
讓Apache支持ruby。通過ruby gem方式安裝passenger
[root@Master-node ~]# gem install passenger
若是升級ruby,參考源碼安裝升級:http://www.cnblogs.com/kevingrace/p/5752382.html
3)配置Dashboard
[root@Master-node ~]# vim /usr/share/puppet-dashboard/config/database.yml
........
production:
database: dashboard
username: dashboard
password: password
encoding: utf8
adapter: mysql
修改時區
[root@Master-node ~]# vim /usr/share/puppet-dashboard/config/environment.rb
.......
config.time_zone = 'Beijing'
4)初始化數據庫
[root@Master-node ~]# cd /usr/share/puppet-dashboard/
[root@Master-node puppet-dashboard]# rake RAILS_ENV=production db:migrate //rake是ruby下自帶的命令,可以使用find命令找出
5)配置Apache
配置passenger(選擇http服務軟件):
[root@Master-node ~]# passenger-install-apache2-module
[root@Master-node ~]# find / -name mod_passenger.so
/usr/local/ruby/lib/ruby/gems/2.4.0/gems/passenger-5.1.4/buildout/apache2/mod_passenger.so
[root@Master-node ~]# cp /usr/local/ruby/lib/ruby/gems/2.4.0/gems/passenger-5.1.4/buildout/apache2/mod_passenger.so /etc/httpd/modules/
整合Passenger和apache
[root@Master-node ~]# yum install curl-devel httpd-devel
[root@Master-node ~]# vim /etc/httpd/conf.d/passenger.conf
LoadModule passenger_module modules/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /usr/share/rubygems/gems/passenger-3.0.17
PassengerRuby /usr/bin/ruby
PassengerHighPerformance on
PassengerMaxPoolSize 12
PassengerPoolIdleTime 1500
PassengerStatThrottleRate 120
RailsAutoDetect On
</IfModule>
<VirtualHost *:80>
ServerName huanqiu.puppet.com
DocumentRoot "/usr/share/puppet-dashboard/public/"
<Directory "/usr/share/puppet-dashboard/public/">
Options None
AllowOverride AuthConfig
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/httpd/huanqiu.puppet.com_error.log
LogLevel warn
CustomLog /var/log/httpd/huanqiu.puppet.com_access.log combined
ServerSignature On
</VirtualHost>
啟動服務
[root@Master-node ~]# /etc/init.d/httpd start
[root@Master-node ~]# chkconfig httpd on
6)配置puppet
讓Dashboard使用Reports,現在默認agent是已經啟用Report的功能,所以就不需要設置agent,只需要設置Server端就可以!
[root@Master-node ~]# vim /etc/puppet/puppet.conf
.......
[master]
reports = store, http
reporturl = http://huanqiu.puppet.com:80/reports/upload
重啟puppetmaster 服務
[root@Master-node ~]# /etc/init.d/puppetmaster restart
這時候可以直接用 http://ip 訪問puppet Dashboard
