puppet
簡介
puppet是一種Linux、Unix平臺的集中配置管理系統,所謂配置管理系統,就是管理機器裏面諸如文件,用戶,進程,軟件包這些資源,其設計目標是簡化對這些資源的管理以及妥善處理資源間的依賴關係
puppet使用一種描述性語言來定義配置項,配置項中被稱爲」資源」,描述性語言能夠聲明你的配置的狀態---好比聲明一個軟件包應該被安裝或者一個服務應該被啓動
用puppet,能夠運行一個服務器端,而後每一個客戶端經過ssl證書鏈接服務器,獲得本機器的配置列表,而後更加列表的來完成配置工做,因此若是硬件配置好,在一天以內配置好上千上萬臺機器是很容易實現的事情,前提得大部分機器配置相似
在大規模的生成環境中,若是隻有一臺puppetmaster會忙不過來的,由於puppet是用ruby寫的,ruby是解析型語言,每一個客戶端來訪 問,都要解析一次,當客戶端多了就忙不過來,因此須要擴展成一個服務器組。puppetmaster能夠看做一個web服務器,實際上也是由ruby提供 的web服務器模塊來作的。所以能夠利用web代理軟件來配合puppetmaster作集羣設置
puppe項目主要開發者是Luke Kanies,目前是puppet labs CEO,puppet遵循GPLv2版權協議。從1997年開始Kanies參與UNIX的系統管理工做,Puppet的開發源於這些經驗。由於對已有的配置工具不甚滿意,從2001年到2005年間,Kanies開始在Reductive實驗室從事工具的開發。很快,Reductive實驗室發佈了他們的旗艦產品——
來張牛人靚照
與Luke Kanies談Puppet工具:http://article.yeeyan.org/view/neilalaer/4629
puppet
系統架構
Puppet是開源的基於Ruby的系統配置管理工具,puppet是一個C/S結構, 固然,這裏的C能夠有不少,所以,也能夠說是一個星型結構. 全部的puppet客戶端同一個服務器端的puppet通信.
每一個puppet
客戶端每半小時(
能夠設置)
鏈接一次服務器端, 下載最新的配置文件,而且嚴格按照配置文件來配置服務器. 配置完成之後,puppet客戶端能夠反饋給服務器端一個消息. 若是出錯,也會給服務器端反饋一個消息. 下圖展現了一個典型的puppet配置的數據流動狀況
puppet
工做流程
1) 客戶端經過facter收集客戶端信息併發送至服務端
2) 鏈接服務端並請求catalog日誌
3) 請求節點(node)的信息
4) 從服務器端接收節點(node)的實例
5) 編譯代碼(包括語法檢查等工做)
6) 查詢是否有exported 虛擬資源
7) 若有,則從數據庫接收虛擬資源
8) 接收完整的catalog日誌
9) 存儲catalog日誌到數據庫
10) 客戶端接收完整的catalog日誌
實驗效果圖:
實驗環境:
puppetmaster
192.168.50.55 server.viong.com
puppet
192.168.50.56 client1.viong.com
centos x64 5.5
最小化安裝+
Developtool
安裝步驟:
因爲centos最小化安裝,須要yum一些經常使用工具
安裝NTP同步時間,統一master和client上的時間
crontables(用來安裝、卸裝、或列舉用來驅動 cron 守護進程的表格的程序)默認是安裝的,可vixie-cron軟件包是cron的主程序
wget下載安裝文件
VI只默認安裝了vim-minimal-7.x,因此不管是輸入vi或者 vim查看文件,syntax功能都沒法正常啓用。所以須要用yum安裝另外兩個組件:vim-common-7.x和vim-enhanced- 7.x ,yum vim-enhanced-會自動下載關聯vim-common
telnet只安裝client,便於測試網絡連通性
[root@puppet soft]# chkconfig --level 35 ntpd on
#天天凌晨5點10分同步time.nist.gov,並將 Linux 時間寫入 BIOS時
[root@localhost ~]# service crond restart
[root@localhost ~]# ntpdate pool.ntp.org; hwclock –w
29 Feb 15:22:47 ntpdate[15867]: step time server 196.25.1.1 offset 98.750417 sec
Puppet 要求全部機器有完整的域名(
FQDN),若是沒有 DNS 服務器提供域名的話,能夠在兩臺機器上設置主機名(注意要先設置主機名再安裝 Puppet,因安裝 Puppet 時會把主機名寫入證書,客戶端和服務端通訊須要這個證書):
[root@puppet puppet-2.7.14]#echo "192.168.50.56 client1.viong.com" >>/etc/hosts
[root@puppet puppet-2.7.14]#hostname server.viong.com
[root@puppet puppet-2.7.14]# vi /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=server.viong.com
GATEWAY=192.168.50.1
--------------------------------------------------------------------------------------------------默認DNS設置過,個別童鞋有報錯沒法認證記得查詢一下
[root@puppet puppet-2.7.14]#vi /etc/resolv.conf
; generated by /sbin/dhclient-script
#search localdomain
#註釋掉這行,否則形成後面沒法認證
nameserver 8.8.8.8
修改完以上文件,退出從新登陸
--------------------------------------------------------------------------------------------------
安裝ruby
因爲puppet是由ruby語言編寫,因此要安裝ruby環境及庫文件,命令幫助文件
[root@puppet soft]# yum install ruby ruby-libs ruby-rdoc
安裝facter
facter是一個系統盤點工具,收集主機的一些資料,好比CPU,主機IP等,它收集到值發送給puppet服務器端,服務器端就能夠根據不一樣的條件來對不一樣的節點機器生成不一樣的puppet配置文件
安裝puppet以前必須先安裝facter
[root@puppet soft]# tar -zxvf facter-1.6.8.tar.gz
[root@puppet soft]# cd facter-1.6.8
[root@puppet facter-1.6.8]# ruby install.rb
安裝puppet
[root@puppet facter-1.6.8]# cd ..
[root@puppet soft]# wget http://downloads.puppetlabs.com/puppet/puppet-2.7.14.tar.gz
[root@puppet soft]# tar -zxvf puppet-2.7.14.tar.gz
[root@puppet soft]# cd puppet-2.7.14
[root@puppet puppet-2.7.14]# ruby install.rb
複製配置文件
[root@puppet puppet-2.7.14]# cp conf/redhat/fileserver.conf /etc/puppet/
[root@puppet puppet-2.7.14]# cp conf/redhat/puppet.conf /etc/puppet/
[root@puppet puppet-2.7.14]# cp conf/redhat/server.init /etc/init.d/puppetmaster
設置puppetmaster
爲服務,並自動啓動
確認puppetmaster是否有執行權限
[root@puppet puppet-2.7.14]# ll /etc/init.d/puppetmaster
-rwxr-xr-x 1 root root 3936 06-05 18:19 /etc/init.d/puppetmaster
[root@puppet puppet-2.7.14]# chkconfig --add puppetmaster
[root@puppet puppet-2.7.14]# chkconfig --level 35 puppetmaster on
建立puppet
賬號
1)確認是否生成清單文件夾
[root@puppet soft]# ll /etc/puppet/
總計 32
-rw-r--r-- 1 root root 2552 06-05 01:29 auth.conf
-rwxr-xr-x 1 root root 381 2012-06-05 fileserver.conf
drwxr-xr-x 2 root root 4096 2012-06-05 manifests
-rwxr-xr-x 1 root root 853 2012-06-05 puppet.conf
manifests目錄:用來存放puppet的腳本文件的,必須包含init.pp文件,一般狀況下能夠把腳本都寫入到這個一個文件中,但爲了便於管理,最好是按照功能或者項目分開存放
2)確認系統生成puppet用戶
[root@puppet puppet-2.7.14]# cat /etc/passwd |grep puppet
puppet:x:500:500::/home/puppet:/bin/bash
3)保證/var/lib/puppet/rrd目錄存在且屬主是puppet
[root@puppet puppet-2.7.14]# ll /var/lib/puppet/
總計 72
drwxr-x--- 2 puppet puppet 4096 06-05 18:49 bucket
drwxr-xr-x 2 root
root 4096 06-05 18:49 facts
drwxr-xr-x 2 root
root 4096 06-05 18:49 lib
drwxr-x--- 2 puppet puppet 4096 06-05 18:49 reports
drwxr-x--- 2 puppet puppet 4096 06-05 18:49 rrd
drwxr-x--- 2 puppet puppet 4096 06-05 18:49 server_data
drwxrwx--x 8 puppet root
4096 06-05 18:50 ssl
drwxr-xr-t 2 root
root 4096 06-05 18:49 state
drwxr-x--- 2 puppet puppet 4096 06-05 18:49 yaml
查看是否安裝成功
[root@server ~]# netstat -ntpl|grep 8140
tcp
0 0 0.0.0.0:8140 0.0.0.0:* LISTEN 2993/ruby [root@server ~]# ps -ef|grep puppet|grep -v grep
puppet
2993 1 0 10:57 ? 00:00:00 /usr/bin/ruby /usr/sbin/puppetmasterd
iptable
安全設置
默認iptable配置以下:
# Firewall configuration written by system-config-securitylevel
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p 50 -j ACCEPT
-A RH-Firewall-1-INPUT -p 51 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp --dport 5353 -d 224.0.0.251 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT
修改成:
# Firewall configuration written by system-config-securitylevel
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8140 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT
客戶端
[root@puppet puppet-2.7.14]# echo "192.168.50.55 server.viong.com" >>/etc/hosts
[root@puppet puppet-2.7.14]#hostname
client1.viong.com
[root@puppet puppet-2.7.14]# vi /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME= client1.viong.com
GATEWAY=192.168.50.1
在客戶端安裝ruby facter puppet
的步驟參考服務端配置
特別說明:請注意客戶端和服務器端版本要一致。若是版本不一致的話,那麼高版本的只能是puppet server,另外一臺只能做爲puppet客戶端,也就是說puppet 服務端的版本能夠大於或者等於客戶端版本,不能夠小於
其中區別一些以下:
[root@puppet puppet-2.7.14]# cp conf/redhat/client.init /etc/init.d/puppet
[root@puppet puppet-2.7.14]# chkconfig --level 35 puppet on
[root@puppet puppet-2.7.14]# puppetd --mkusers
Could not prepare for execution: Got 1 failure(s) while initializing: change from absent to present failed: Could not create user puppet: Execution of '/usr/sbin/useradd -g puppet -M puppet' returned 6: useradd: unknown group puppet
#手動建立puppet用戶與組
[root@puppet puppet-2.7.14]# groupadd puppet;useradd -g puppet -M puppet
[root@puppet puppet-2.7.14]# service puppet start
測試解析與puppetmaster
端口是否暢通
[root@puppet puppet-2.7.14]# telnet server.viong.com 8140
Trying 192.168.50.55...
Connected to server.viong.com.
Escape character is '^]'.
Connection closed by foreign host
[root@client1 puppet-2.7.14]# puppetd --test --server server.viong.com
info: Creating a new SSL key for client1.viong.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 client1.viong.com
info: Certificate Request fingerprint (md5): 6F:6A:45:D9:14:28:D1:5B:05:3B:4F:0B:9A:51:D1:71
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
# puppetd --test --server server.viong.com命令是指puppetd 從 server.viong.com去讀取
puppet配置文件. 第一次鏈接,雙方會進行ssl證書的驗證,這是一個新的客戶端,在服務器端那裏尚未被認證,所以須要在服務器端進行證書認證
如下這步批准證書是在服務端操做
查看固然待批准證書列表
[root@server ~]# puppetca –l
client1.viong.com (B0:85:72:E6:7D:63:EA:CC:BD:0C:E4:F1:70:89:24:70)
批准當前證書
[root@server ~]# puppetca -s client1.viong.com
notice: Signed certificate request for client1.viong.com
notice: Removing file Puppet::SSL::CertificateRequest client1.viong.com at
'/var/lib/puppet/ssl/ca/requests/client1.viong.com.pem'
查看驗證簽名,
注意前面的+
號,說明已經簽名
[root@server ~]# puppetca -a --list
+ server.viong.com (43:33:D3:A0:26:C4:E9:89:66:A6:DC:54:20:90:E9:4D) (alt names:
DNS:puppet, DNS:puppet.viong.com, DNS:server.viong.com)
--------------------------------------------------------------------------------------------------
若是要批准所有證書
puppetca -s -a
也能夠在puppetmaster端的puppet.conf加入這行:
autosign = true
服務端就自動簽證書
--------------------------------------------------------------------------------------------------
回到客戶端操做,從服務端取回已批准的證書
[root@client1 puppet-2.7.14]# puppetd --test --server server.viong.com
warning: peer certificate won't be verified in this SSL session
info: Caching certificate for client1.viong.com
info: Caching certificate_revocation_list for ca
info: Caching catalog for client1.viong.com
info: Applying configuration version '1338897814'
info: Creating state file /var/lib/puppet/state/state.yaml
notice: Finished catalog run in 0.02 seconds
驗證證書是否正確
服務端:
[root@server ~]# md5sum /var/lib/puppet/ssl/ca/signed/client1.viong.com.pem
8529a6f2d42c1b492c016fe870b744b6 /var/lib/puppet/ssl/ca/signed/client1.viong.com.pem
客戶端:
[root@client1 puppet-2.7.14]# md5sum /var/lib/puppet/ssl/certs/client1.viong.com.pem
8529a6f2d42c1b492c016fe870b744b6 /var/lib/puppet/ssl/certs/client1.viong.com.pem
------------------------------------------------------------------------------------------------
出現修改主機名問題引發沒法認證,須要從新申請證書,操做如下兩個步驟:
服務端:
[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/
------------------------------------------------------------------------------------------------
功能測試
服務端:
創建pp文件測試
puppet的第一個執行的代碼是在/etc/puppet/manifest/site.pp
所以這個文件必須存在,並且其餘的代碼也要經過代碼來調用.
[root@server ~]# vim /etc/puppet/manifests/site.pp
node default {
file {"/tmp/viong.txt":
content=>"good,test pass!\n";}
上面的代碼對默認連入的puppet客戶端執行一個操做,在/tmp目錄生成一個viong.txt文件,內容是good,test pass! 並自動回車換行
初次建立pp
文件,須要重啓puppetmaster
[root@server ~]# service puppetmaster restart
中止 puppetmaster:
[肯定]
啓動 puppetmaster:
[肯定]
客戶端:
[root@client1 puppet-2.7.14]# puppetd --test --server server.viong.com
info: Caching catalog for client1.viong.com
info: Applying configuration version '1338897814'
notice: /Stage[main]//Node[default]/File[/tmp/viong.txt]/ensure: defined content as '{md5}9a3f5438e1d35a72d853974203de4254'
notice: Finished catalog run in 0.03 seconds
成功的話就會顯示puppet反饋一些調試信息,並在/tmp目錄下建立了 /tmp/viong.txt文件.
[root@client1 puppet-2.7.14]# cat /tmp/viong.txt
good,test pass!
==============================================================
設置客戶端的守護進程
info: Caching catalog for client1.viong.com
info: Applying configuration version '1338897814'
notice: Finished catalog run in 0.03 seconds
--server 服務端FQDN –-verbose 輸出冗餘信息 –-waitforcert 超時100
本人以爲使用cron或者手動運行puppet比較符合需求,或者以腳本方式,當master有改變再執行編寫的腳本
先整理到這裏,資源管理這塊涉及到不少內容須要花時間慢慢咀嚼.
整理一篇文章挺辛苦,此次發佈遇到一些問題,謝謝邵程程幫忙解決了,有問題請你們提出來,謝謝
參考文檔:
http://www.slideshare.net/myw58/puppet-7159486
愛好puppet研究能夠加sky 發佈 puppet QQ羣:179750784
----------------viong 2012.06.06