<51cto文檔上傳功能較弱,讀者可留言索取puppet word文檔,tks>
在掌握《集中管理利器-puppet快速入門-上》的基本功學習後,我們可以進行接下來的學習
Puppet配置
文件管理 file
文件服務器寫法:
/etc/puppet/ fileserver.conf 定義
http://docs.puppetlabs.com/references/latest/type.html#user
http://docs.puppetlabs.com/references/latest/type.html#group
用戶管理
http://docs.puppetlabs.com/references/latest/type.html#file
命令執行
實例:
###命令執行 /etc/puppet/manifests/site.pp 配置 file {"/tmp/mysql_test/mysql_test.tgz": ##將pmaster /tmp/files/mysql_test.tgz文件下發到agent /tmp/mysql_test/目錄下 source => "puppet://pmaster.example.com/files/mysql_test.tgz", } exec { "unzip tgz packget": command => "tar -xvf /tmp/mysql_test/mysql_test.tgz", ###所有命令必須爲全路徑或者path參數指定命令搜索路徑 path => "/usr/bin:/usr/sbin:/bin:/sbin", cwd => "/tmp/mysql_test" ##命令執行的路徑爲: /tmp/mysql_test/ creates => "/etc/my.cnf" #當/etc/my.cnf不存在的時候,纔會執行該命令 tries => 2, #重試次數 try_sleep => 3, #重試間隔 s爲單位 } |
常用命令詮釋:
1. command 2. creates 3. cwd 4. environment 5. group 6. logoutput 7. onlyif 8. path 9.timeout 10.tries 11.try_sleep 12.user 更多請參見: http://docs.puppetlabs.com/references/latest/type.html#exec |
Cron管理
實例:
cron { "sh /tmp/a.sh": command => "/bin/sh /tmp/a.sh", user=> root, minute => '*/3' #ensure => "absent"; ##cron刪除 } |
命令用法:
puppet –genconfig#查看當前配置 service puppetmasterd start #啓動puppetmaster service puppet start ##啓動客戶端 客戶端的運行報告在服務器端:/var/lib/puppet/reports/ Agent /etc/hosts中添加主機信息 puppetmasterd –genconfig > puppet.conf puppet master --verbose --no-daemon agent 連接server puppet agent --server=pmaster --no-daemonize --verbose 使用—waitforcert 參數改變agent等待時間 puppetmasterd --configprint modulepath ##打印默認路徑 連接並對agent進行驗證,我們需要對agent發送到master的證書進 puppet cert –list ##顯示等待簽名的服務器 puppet cert --sign node1.example.com ##簽名 puppert cert –sign –all #對所有等待的證書進行簽名 |
服務器控制客戶端立即運行
Puppet kick 官網不造成使用,只檢查客戶端返回狀態,不檢查命令執行結果,新版本會棄用
Agent配置:
puppet.conf
[agent]
listen = true
auth.conf 紅色部分爲新增
path /run
auth any
method save
allow pmaster.example.com
# this one is not stricly necessary, but ithas the merit
# to show the default policy which is denyeverything else
path /
auth any
demo方式啓動agent
service puppet restart ###啓動成功不代表成功了,netstat確認端口被監聽,puppet這塊功能有待完善…
Master遠程確認8139端口可通
Client確認文件是否被重新生成
class類的嘗試
配置文件作如下變更:
Mysql單獨起一個模塊配置
[root@pmaster puppet]# tree manifests/ manifests/ |-- init.pp |-- nodes | `-- nodes.pp |-- site.pp |-- site.pp_normal `-- site.ppaa 1 directory, 5 files [root@pmaster puppet]# pwd /etc/puppet [root@pmaster puppet]# tree modules/ modules/ |-- mysql | |-- manifests | | |-- config.pp | | |-- init.pp | | |-- init.ppa | | |-- install.pp | | `-- service.pp | `-- template | `-- my.cnf.erb `-- test `-- manifests `-- init.pp 5 directories, 7 files [root@pmaster puppet]# cat modules/mysql/manifests/config.pp class mysql::config{ file {"/tmp/mysql_test/mysql_test.tgz": ##將pmaster /tmp/files/mysql_test.tgz文件下發到agent /tmp/mysql_test/目錄下 source => "puppet://pmaster.example.com/files/mysql_test.tgz", } } [root@pmaster puppet]# cat modules/mysql/manifests/init.pp class mysql::mysql{ include mysql::install,mysql::config } [root@pmaster puppet]# cat modules/mysql/manifests/service.pp class mysql::service{ service{"mysql": ensure => running, hasstatus => true, hasrestart => true, enable => true, name => "mysql", require => Package["mysql"], #subscribe => File["/etc/my.cnf"], } } [root@pmaster puppet]# cat modules/mysql/manifests/install.pp class mysql::install{ exec { "unzip tgz packget": command => "tar -xvf /tmp/mysql_test/mysql_test.tgz", ###所有命令必須爲全路徑或者path參數指定命令搜索路徑 path => "/usr/bin:/usr/sbin:/bin:/sbin", cwd => "/tmp/mysql_test", ##命令執行的路徑爲: /tmp/mysql_test/ creates => "/etc/my.cnf", #當/etc/my.cnf不存在的時候,纔會執行該命令 tries => 2, #重試次數 try_sleep => 3, #重試間隔 s爲單位 } } |
高級擴展:
Master kick 主動推送配置到agent
*******************************************************************************************
* 爲最大限度不影響讀者感官: *
* http://fengzhilinux.blog.51cto.com/1343279/1320317另起欄目,也請大家多支持 *
*******************************************************************************************