1. 概述 puppet是一個開源的軟件自動化配置和部署工具,它使用簡單且功能強大,正得到了越來越多地關注,現在很多大型IT公司均在使用puppet對集羣中的軟件進行管理和部署,如google利用puppet管理超過6000臺地mac桌面電腦(2007年數據)。 本文主要介紹puppet安裝方法,設計架構及使用方法。 2. 設計架構 puppet是基於c/s架構的。服務器端保存着所有對客戶端服務器的配置代碼,在puppet裏面叫做manifest. 客戶端下載manifest之後,可以根據manifest對服務器進行配置,例如軟件包管理,用戶管理和文件管理等等。 如上圖所示,puppet的工作流程如下:(1)客戶端puppetd調用facter,facter探測出主機的一些變量,例如主機名,內存大 小,ip地址等。pupppetd 把這些信息通過ssl連接發送到服務器端; (2)服務器端的puppetmaster 檢測客戶端的主機名,然後找到manifest裏面對應的node配置, 並對該部分內容進行解析,facter送過來的信息可以作爲變量處理,node牽涉到的代碼才解析,其他沒牽涉的代碼不解析。解析分爲幾個階段,語法檢 查,如果語法錯誤就報錯。如果語法沒錯,就繼續解析,解析的結果生成一箇中間的“僞代碼”,然後把僞代碼發給客戶端;(3)客戶端接收到“僞代碼”,並且 執行,客戶端把執行結果發送給服務器;(4)服務器端把客戶端的執行結果寫入日誌。 puppet工作過程中有兩點值得注意,第一,爲了保證安全,client和master之間是基於ssl和證書的,只有經master證書認證的 client可以與master通信;第二,puppet會讓系統保持在你所期望的某種狀態並一直維持下去,如檢測某個文件並保證其一直存在,保證ssh 服務始終開啓,如果文件被刪除了或者ssh服務被關閉了,puppet下次執行時(默認30分鐘),會重新創建該文件或者啓動ssh服務。
環境:
2臺Ubuntu 10.04
安裝步驟:
1、編輯/etc/host以修改主機名,因爲puppet是基於證書的,證書中包含主機名
2、 配置apt 源才能獲取最新的puppet
- $ sudo echo "deb http://apt.puppetlabs.com/ lucid main" >> /etc/apt/sources.list
- $ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 4BD6EC30
- $ sudo apt-get update
3、安裝服務端(master)
- $sudo apt-get install puppet puppetmaster facter
4、安裝客戶端(agent上)
- $sudo apt-get install puppet facter
5、配置文件
- [agent]
- # These are needed when the puppetmaster is run by passenger
- # and can safely be removed if webrick is used.
- #ssl_client_header = SSL_CLIENT_S_DN
- #ssl_client_verify_header = SSL_CLIENT_VERIFY
- server = slave-85.cd.ta-mp.com
puppet.conf
Puppet的主配置文件,配置文件爲/etc/puppet/puppet.conf
具體配置參數,參見:
http://docs.puppetlabs.com/references/stable/configuration.html#configuration-files
fileserver.conf
puppet文件服務器的配置文件。用path配置文件路徑,allow/deny配置訪問權限,具體參見:http://docs.puppetlabs.com/guides/file_serving.html
master配置
- [master]
- # These are needed when the puppetmaster is run by passenger
- # and can safely be removed if webrick is used.
- ssl_client_header = SSL_CLIENT_S_DN
- ssl_client_verify_header = SSL_CLIENT_VERIFY
agent 配置
- [agent]
- # These are needed when the puppetmaster is run by passenger
- # and can safely be removed if webrick is used.
- #ssl_client_header = SSL_CLIENT_S_DN
- #ssl_client_verify_header = SSL_CLIENT_VERIFY
- server = server.com
6、啓動
- sudo service puppetmaster restart
7、 認證
master操作
- sudo puppet cert list --all #查詢key
- sudo puppet cert -l #查看簽名待處理請求
- sudo puppet cert -s -a #通過所有請求
- sudo puppet cert sign servername 進行簽名
agent操作
- sudo puppet agent --test 第一次運行生成key
當簽名完成後在進行測試
- $ sudo puppet agent --test
- Info: Retrieving plugin
- Info: Caching catalog for agent1.com
- Info: Applying configuration version '1358219592'
- Finished catalog run in 0.15 seconds