安裝目錄默認存為/etc/puppet,該目錄下的manifests存放manifest文件.其他可執行文件在
puppet: 用於執行用戶所寫獨立的mainfests文件
puppetd: 運行在被管理主機上的客戶端程序
puppetmasterd:運行在管理機上的伺服器程序
puppetca:puppet認證程序,主要用於對client的證書進行認證
puppetrun:用於連接客戶端,強制運行本地配置文件
file資源: 管理系統本地文件
設置文件許可權和屬主
管理文件內容,可以基於模板的內容管理
從遠程伺服器複製整個目錄到本地
參數
Backup:決定文件的內容在被修改前是否進行備份.
Checksum:檢查文件是否被修改
Content:把文件的內容設置為content 參數後面的字元串
Ensure
Force:作用是用在把一個目錄變成一個鏈接,可用的值是ture和false
Group
Ignore:當用recursion 方法複製一個目錄的時候,可以用
Links:定義操作符合鏈接文件. 可以設置的值是follow和manage; 文件拷貝的時候
Mode:
Owner:設置文件的屬主
Path:指定要管理文件的路徑,用引號引起來, 這也是一個資源的 namevar ,
Recurse:設置是否以及如何進行遞歸操作, 可以設置的值是 false,ture ,inf ,remote
Recurselimit:遞歸的深度,設置的值可以匹配
Source:拷貝一個文件覆蓋當前文件,用checksum來判斷是否有必要進行複製,可以設置的值是一個引用的完整的文件路徑,或者是URI,當前支持的
File資源測試用例
登陸puppet master,編輯默認manifest文件
- [root@master ~]# cd /etc/puppet/manifests/
- [root@master manifests]# vim site.pp
- node default {
- file {'file1':
- path => '/tmp/file1',
- ensure => present,
- mode => 0777,
- user => root,
- group => root,
- content => "Welcome to use Puppet.",
- }
- }
在puppet master應用該測試文件
- [root@master manifests]# puppet apply file1.pp
- notice: /Stage[main]//File[file1]/ensure: created
- notice: Finished catalog run in 0.04 seconds
檢查puppet master上是否生效
- [root@master manifests]# more /tmp/file1
- Welcome to use Puppet.
- [root@master manifests]# ll /tmp/file1
- -rwxrwxrwx 1 root root 22 2月 22 15:13 /tmp/file1
- [root@client1 puppet]# puppetd --server master.puppet --test
- notice: Ignoring --listen on onetime run
- info: Caching catalog for client1.centos
- info: Applying configuration version '1329902782'
- notice: /Stage[main]//Node[default]/File[file1]/ensure: created
- notice: Finished catalog run in 0.01 seconds
查看客戶端文件屬性
- [root@client1 puppet]# ls -l /tmp/file1
- -rwxrwxrwx 1 root root 22
2月 22 17:26 /tmp/file1 - [root@client1 puppet]# more /tmp/file1
- Welcome to use Puppet.
出現的問題1,報錯如下:
- [root@client3 ~]# puppetd --test --server master.puppet
- err: Could not retrieve catalog from remote server: Error 400 on SERVER: No support for http method POST
- warning: Not using cache on failed catalog
- err: Could not retrieve catalog; skipping run
- notice: /File[/var/puppet/state/last_run_summary.yaml]/content:
- --- /var/puppet/state/last_run_summary.yaml 2012-02-23 09:13:50.000000000 0800
- /tmp/puppet-file20120223-4772-1la6w5s-0 2012-02-23 09:14:59.000000000 0800
- @@ -3,4 3,4 @@
- puppet: 2.7.10
- config:
- time:
- - last_run: 1329959630
- \ No newline at end of file
- last_run: 1329959699
- \ No newline at end of file
出現這個報錯的原因是puppet的客戶端版本和伺服器的版本不一樣導致的,puppet master的版本是2.6.13,而puppet client的版本是2.7.10下面是檢查版本:
- [root@master ~]# puppetmasterd --version
- 2.6.13
安裝2.6.13的客戶端恢復
- [root@client3 ~]# fetch http://puppetlabs.com/downloads/puppet/puppet-2.6.13.tar.gz
- [root@client3 ~]# tar -zxvf puppet-2.6.13.tar.gz
- [root@client3 ~]# cd puppet-2.6.13
- [root@client3 ~/puppet-2.6.13]# ruby install.rb
- [root@client3 ~]# puppetd --version
- 2.6.13
出現的問題2,證書問題,報錯如下
- [root@client3 /var/lib/puppet]# puppetd --test --server master.puppet
- err: Could not request certificate: Retrieved certificate does not match private key; please remove certificate from server and regenerate it with the current key
- Exiting; failed to retrieve certificate and waitforcert is disabled
清楚伺服器端的證書,重新認證,如仍然報錯可以將客戶端的
- [root@master ssl]# puppetca --clean client3.freebsd
- notice: Revoked certificate with serial 7
- notice: Removing file Puppet::SSL::Certificate client3.freebsd at '/var/lib/puppet/ssl/ca/signed/client3.freebsd.pem'
- notice: Removing file Puppet::SSL::Certificate client3.freebsd at '/var/lib/puppet/ssl/certs/client3.freebsd.pem'
- [root@client3 ~]# cd /etc/puppet/
- [root@client3 /etc/puppet]# mv ssl ssl_bak
重新認證,客戶端恢復
- [root@client3 ~]# puppetd --test --server master.puppet
- info: Caching catalog for client3.freebsd
- info: Applying configuration version '1329961887'
- notice: Finished catalog run in 0.02 seconds
測試file資源的其他參數
- [root@master ~]# vim /etc/puppet/manifests/site.pp
- node default {
- file {'file1':
- path => '/tmp/file1',
- ensure => present,
- mode => 0777,
- #user => root,
- #group => root,
- content => "Welcome to use Puppet.",
- }
- file{ '/tmp/file2':
- ensure => directory,
- mode=>0644,
- }
- file{'/tmp/file3':
- ensure=>link,
- target=>'/tmp/file1',
- }
- }
客戶端測試配置
- [root@client1 ~]# puppetd --server master.puppet --test
- notice: Ignoring --listen on onetime run
- info: Caching catalog for client1.centos
- info: Applying configuration version '1329963133'
- notice: /Stage[main]//Node[default]/File[/tmp/file2]/ensure: created
- notice: /Stage[main]//Node[default]/File[/tmp/file3]/ensure: created
- notice: Finished catalog run in 0.03 seconds
查看生成文件信息
- [root@client1 ~]# ls -l /tmp/file*
- -rwxrwxrwx 1 root root 22 2月 22 17:26
/tmp/file1 - lrwxrwxrwx 1 root root 10 2月 23 10:12 /tmp/file3 -> /tmp/file1
- /tmp/file2:
- 總用量 0
本文出自 「Waydee的博客」 博客,請務必保留此出處http://waydee.blog.51cto.com/4677242/847118
[火星人 ] Puppet--文件自動化管理已經有379次圍觀