三種注冊方式
Puppet注冊方式基本上有三種:手動注冊,自動注冊和預簽名注冊
1.手動注冊
手動注冊是由Agent端先發起證書申請請求,然後由Puppet server端確認證書方可注冊成功,這種注冊方式安全系數中等,逐一注冊(puppet cert --sign certname)在節點數量較大的情況下是比較麻煩的,效率也低,批量注冊(puppet cert --sign --all)效率很高,一次性便可注冊所有的Agent的請求,但是這種方式安全系數較低,因為錯誤的請求也會被注冊上。
2.自動注冊
這種注冊方式簡單來講是通過Puppet master端的ACL列表進行控制的,安全系統較低,也就是說符合預先定義的ACL列表中的所有節點請求不需要確認都會被自動注冊上,也就是說你只需要知道ACL列表要求,其次能和PuppetMaster端通信便可輕易注冊成功。當然,它的最大優點就是效率非常高.
(1)查詢認證情況
復制代碼代碼如下:
[email protected]:puppet# puppet cert --list --all
+ "agent.domain.com" (SHA256) 3F:8E:AE:B8:04:2B:51:9B:7A:B3:1E:86:C0:21:3E:81:D6:2A:55:A4:17:15:CA:5E:7A:8F:95:EC:D3:83:41:C0
+ "localhost" (SHA256) E4:F5:F3:A9:99:E9:4D:11:53:87:BE:47:95:4C:98:48:58:2D:3D:80:7E:9C:D9:C2:36:93:56:B2:EA:A0:F1:7B
+ "puppet.domain.com" (SHA256) 5A:E1:80:AA:76:B6:81:22:55:B7:28:4B:AB:7C:B9:87:A8:DD:7E:3A:31:DF:0C:5A:61:8F:4B:D2:16:A4:B6:BF (alt names: "DNS:puppet", "DNS:puppet.domain.com")
(2)在master上清除客戶端已經agent注冊信息的證書
復制代碼代碼如下:
[email protected]:puppet# puppet cert --clean agent.domain.com
Notice: Revoked certificate with serial 7
Notice: Removing file Puppet::SSL::Certificate agent.domain.com at '/var/lib/puppet/ssl/ca/signed/agent.domain.com.pem'
Notice: Removing file Puppet::SSL::Certificate agent.domain.com at '/var/lib/puppet/ssl/certs/agent.domain.com.pem'
(3)在agent.domain.com端刪除注冊過的證書
復制代碼代碼如下:
[email protected]:puppet# puppet cert --clean agent.domain.com
Notice: Revoked certificate with serial 7
Notice: Removing file Puppet::SSL::Certificate agent.domain.com at '/var/lib/puppet/ssl/ca/signed/agent.domain.com.pem'
Notice: Removing file Puppet::SSL::Certificate agent.domain.com at '/var/lib/puppet/ssl/certs/agent.domain.com.pem'
(4)在Puppet master端編寫ACL列表
復制代碼代碼如下:
[email protected]:puppet# cat autosign.conf
*.domain.com
[email protected]:puppet# /etc/init.d/puppetmaster restart
Stopping puppetmaster: [ OK ]
Starting puppetmaster: [ OK ]
(5)客戶端申請注冊證書.
復制代碼代碼如下:
[email protected]:ssl# puppet agent --test
Info: Creating a new SSL key for agent.domain.com
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.domain.com
Info: Certificate Request fingerprint (SHA256): FD:70:31:87:C6:44:EC:8D:18:0D:F5:10:E3:CE:5B:DC:EA:31:BD:BC:8C:C7:B2:80:F7:7E:2C:F2:4E:FB:12:90
Info: Caching certificate for agent.domain.com
Info: Caching certificate_revocation_list for ca
Info: Caching certificate for ca
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for agent.domain.com
Info: Applying configuration version '1418292313'
Notice: /Stage[main]/Test/File[/tmp/agent.txt]/ensure: defined content as '{md5}fc3ff98e8c6a0d3087d515c0473f8677'
Notice: Finished catalog run in 0.13 seconds
(6)服務端查看證書.
復制代碼代碼如下:
[email protected]:puppet# puppet cert --list --all
+ "agent.domain.com" (SHA256) FE:04:96:32:46:A4:54:BF:A9:4F:20:CA:EF:7E:F7:C6:A6:88:34:4A:D9:7E:50:54:FA:C0:10:29:87:F9:1C:6E
+ "client.domain.com" (SHA256) E3:B4:46:90:DF:85:37:77:48:BB:F9:FD:9F:13:DE:52:2F:00:1C:71:A3:BC:C2:E2:A5:34:4F:01:DB:27:02:F5
+ "localhost" (SHA256) E4:F5:F3:A9:99:E9:4D:11:53:87:BE:47:95:4C:98:48:58:2D:3D:80:7E:9C:D9:C2:36:93:56:B2:EA:A0:F1:7B
+ "puppet.domain.com" (SHA256) 5A:E1:80:AA:76:B6:81:22:55:B7:28:4B:AB:7C:B9:87:A8:DD:7E:3A:31:DF:0C:5A:61:8F:4B:D2:16:A4:B6:BF (alt names: "DNS:puppet", "DNS:puppet.domain.com")
3.預簽名認證
預簽名注冊是在agent端未提出申請的情況下,預先在puppet master端生成agent端的證書,然後復制到節點對應的目錄下即可注冊成功,這種方式安全系數最高,但是操作麻煩,需要提前預知所有節點服務器的certname名稱,其次需要將生成的證書逐步copy到所有節點上去。不過,如果你的系統中安裝了kickstart或者cobbler這樣的自動化工具,倒是可以將證書部分轉換成腳本集成到統一自動化部署中.注:生產環境中建議此方式進行注冊,既安全又可靠.
(1)查詢認證情況
復制代碼代碼如下:
[email protected]:puppet# puppet cert --list --all
+ "agent.domain.com" (SHA256) 3F:8E:AE:B8:04:2B:51:9B:7A:B3:1E:86:C0:21:3E:81:D6:2A:55:A4:17:15:CA:5E:7A:8F:95:EC:D3:83:41:C0
+ "localhost" (SHA256) E4:F5:F3:A9:99:E9:4D:11:53:87:BE:47:95:4C:98:48:58:2D:3D:80:7E:9C:D9:C2:36:93:56:B2:EA:A0:F1:7B
+ "puppet.domain.com" (SHA256) 5A:E1:80:AA:76:B6:81:22:55:B7:28:4B:AB:7C:B9:87:A8:DD:7E:3A:31:DF:0C:5A:61:8F:4B:D2:16:A4:B6:BF (alt names: "DNS:puppet", "DNS:puppet.domain.com")
(2)在master上清除客戶端已經agent注冊信息的證書
復制代碼代碼如下:
[email protected]:puppet# puppet cert --clean agent.domain.com
Notice: Revoked certificate with serial 7
Notice: Removing file Puppet::SSL::Certificate agent.domain.com at '/var/lib/puppet/ssl/ca/signed/agent.domain.com.pem'
Notice: Removing file Puppet::SSL::Certificate agent.domain.com at '/var/lib/puppet/ssl/certs/agent.domain.com.pem'
(3)在agent.domain.com端刪除注冊過的證書
復制代碼代碼如下:
[email protected]:puppet# puppet cert --clean agent.domain.com
Notice: Revoked certificate with serial 7
Notice: Removing file Puppet::SSL::Certificate agent.domain.com at '/var/lib/puppet/ssl/ca/signed/agent.domain.com.pem'
Notice: Removing file Puppet::SSL::Certificate agent.domain.com at '/var/lib/puppet/ssl/certs/agent.domain.com.pem'
(4)puppet server端預先生成agent證書
復制代碼代碼如下:
puppetca --generate agent.domain.com
(5)agent節點生成目錄結構
復制代碼代碼如下:
puppet agent --test
(6)puppet master端copy證書到agent.domain.com上
復制代碼代碼如下:
[email protected]:puppet#scp /var/lib/puppet/ssl/private_keys/agent.domain.com.pem agent.domain.com:/var/lib/puppet/ssl/private_keys/
[email protected]:puppet#scp /var/lib/puppet/ssl/certs/agent.domain.com.pem agent.domain.com:/var/lib/puppet/ssl/certs/
[email protected]:puppet#scp /var/lib/puppet/ssl/certs/ca.pem agent.domain.com:/var/lib/puppet/ssl/certs/ca.pem
常用命令
1.puppet master
puppet master 默認是以Ruby內建的WEBRick在後台運行的守護進程,同樣也可以采用最常用的Web服務器apache和nginx替換WEBRick以提升性能.puppet master主要功能是編譯配置文件,文件,模版,節點的自定義插件.
復制代碼代碼如下:
[email protected]:nodes# puppet master --help
puppet master [-D|--daemonize|--no-daemonize] [-d|--debug] [-h|--help]
[-l|--logdest syslog|<FILE>|console] [-v|--verbose] [-V|--version]
[--compile <NODE-NAME>]
* --daemonize: #-D發送到後台守護進程,默認選項
* --no-daemonize: #不發送到後台守護進程
* --debug: #完整調試
* --help: #輸出幫助
* --logdest: #日志發送方式,默認是syslog
* --verbose: #顯示詳細信息
* --version: #打印puppet版本
* --compile: #以JSON的方式輸出編譯的catalog
使用--getconfig輸出默認配置文件
復制代碼代碼如下:
[email protected]:puppet# puppet master --genconfig > puppet.conf
puppet不啟用後台守護進程的方式運行.
復制代碼代碼如下:
[email protected]:puppet master --no-daemonize --verbose
2.puppet agent
puppet agent 在每個節點以守護進程方式運行,通常每30分鐘向master請求一次,以確認新的信息並詢問是否有變更.然後負責運行編譯好的catalog代碼
復制代碼代碼如下:
[email protected]:tmp# puppet agent --help
puppet agent [--certname <NAME>] [-D|--daemonize|--no-daemonize]
[-d|--debug] [--detailed-exitcodes] [--digest <DIGEST>] [--disable [MESSAGE]] [--enable]
[--fingerprint] [-h|--help] [-l|--logdest syslog|eventlog|<FILE>|console]
[--masterport <PORT>] [--no-client] [--noop] [-o|--onetime] [-t|--test]
[-v|--verbose] [-V|--version] [-w|--waitforcert <SECONDS>]
使用"--noop"參數,puppet運行catelog,但不執行配置
[email protected]:tmp# puppet agent --noop
3.puppet apply
puppet apply 是puppet運行命令,主要在檢測manifests時或在沒有網絡連接的情況下使用.不同於puppet agent,puppet apply在運行時不會連接master
復制代碼代碼如下:
[email protected]:tmp# puppet apply --help
puppet apply [-h|--help] [-V|--version] [-d|--debug] [-v|--verbose]
[-e|--execute] [--detailed-exitcodes] [-L|--loadclasses]
[-l|--logdest syslog|eventlog|<FILE>|console] [--noop]
[--catalog <catalog>] [--write-catalog-summary] <file>
(1) 將輸出信息輸出到日志文件
復制代碼代碼如下:
[email protected]:manifests# puppet apply -l /tmp/init.pp init.pp
[email protected]:manifests# cat /tmp/init.pp
Fri Dec 12 16:17:46 +0800 2014 Puppet (notice): Compiled catalog for puppet.domain.com in environment production in 0.04 seconds
Fri Dec 12 16:17:47 +0800 2014 Puppet (notice): Finished catalog run in 0.04 seconds
4.puppet cert
它用於管理本地證書,查看未簽名證書,簽署證書,廢除證書,清除證書.
復制代碼代碼如下:
puppet cert <action> [-h|--help] [-V|--version] [-d|--debug] [-v|--verbose]
[--digest <digest>] [<host>]
常用操作:
clean #清除證書
fingerprint #打印證書指紋
generate #生成客戶端證書
list #查看認證客戶端列表
print #打印主機證書的全文信息
revoke #廢除已認證的主機
sign #簽署認證
verify #驗證本地指定的認證
命令參數:
--all #執行所有操作,包括'sign','clean', 'list', and 'fingerprint'
--digest #設置證書指紋加密的方式
--debug #啟用完整調試模式|
--verbose #顯示詳細信息
--version #顯示版本
(1)查看請求認證的客戶端列表
復制代碼代碼如下:
[email protected]:nodes# puppet cert list
(2)為主機agent.domin.com簽署驗證
復制代碼代碼如下:
[email protected]:nodes# puppet cert sign agent.domain.com
(3)列出所有簽名和未簽名的證書
復制代碼代碼如下:
[email protected]:nodes# puppet cert list --all
+ "agent.domain.com" (SHA256) 3C:82:6A:E2:9B:8B:8F:8A:ED:C9:83:EB:64:47:6C:91:E5:8E:86:A6:B3:D7:1D:E5:4E:39:4D:04:5A:21:C5:86 #符號+表示已經簽署過認證
"client.domain.com" (SHA256) E3:B4:46:90:DF:85:37:77:48:BB:F9:FD:9F:13:DE:52:2F:00:1C:71:A3:BC:C2:E2:A5:34:4F:01:DB:27:02:F5
(4)給所有未簽署認證的請求頒發認證:
復制代碼代碼如下:
[email protected]:nodes# puppet cert sign --all
(5)查看所有已簽署認證的客戶端列表
復制代碼代碼如下:
[email protected]:nodes# puppet cert list --all
+ "agent.domain.com" (SHA256) 3C:82:6A:E2:9B:8B:8F:8A:ED:C9:83:EB:64:47:6C:91:E5:8E:86:A6:B3:D7:1D:E5:4E:39:4D:04:5A:21:C5:86
5.puppet kick
它用於連接到agent客戶端主動運行puppet agent --test命令.類似主動觸發配置