Pupet自動化管理環境部署記錄(二)

另一種查看認證的方法:

[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

 

以下文章點擊率最高

Loading…

     

如果這文章對你有幫助,請掃左上角微信支付-支付寶,給於打賞,以助博客運營