puppet puppet模塊、file模塊

轉載:http://blog.51cto.com/ywzhou/1577356

作用:通過puppet模塊自動控制客戶端的puppet配置,當需要修改客戶端的puppet配置時不用在客戶端一一設置。

1、服務端配置puppet模塊

(1)模塊清單

[root@puppet ~]# tree /etc/puppet/modules/puppet/
/etc/puppet/modules/puppet/
├── files
├── manifests
│   ├── config.pp
│   ├── init.pp
│   ├── install.pp
│   ├── params.pp
│   └── service.pp
└── templates└── puppet.conf.erb

(2)定義參數類

[root@puppet ~]# vi /etc/puppet/modules/puppet/manifests/params.pp
class puppet::params {$puppetserver = "puppet.ewin.com"case $operatingsystemmajrelease{5: {                #定義centos5系列的參數$puppet_release = '3.7.1-1.el5'$facter_release = '2.2.0-1.el5'}6: {                #定義centos6系列的參數$puppet_release = '3.7.1-1.el6'      #定義軟件版本$facter_release = '2.2.0-1.el6'      #定義軟件版本}default: {fail("Module puppet is not supported on ${::operatingsystem}")}}
}

(3)定義安裝類

[root@puppet ~]# vi /etc/puppet/modules/puppet/manifests/install.pp
class puppet::install {package { "puppet":ensure => $puppet::params::puppet_release,}package { "facter":ensure => $puppet::params::facter_release,}
}
說明:根據系統版本(centos5或centos6)來安裝指定版本的puppet和facter

(4)定義配置類

[root@puppet ~]# vi /etc/puppet/modules/puppet/manifests/config.pp
class puppet::config {file { "/etc/puppet/puppet.conf":ensure  => present,content => template("puppet/puppet.conf.erb"), #文件內容來源于模板owner   => "root",group   => "root",mode    => '0644',require => Class["puppet::install"], #要求先完成install.ppnotify  => Class["puppet::service"], #通知并觸發service.pp}
}
說明:將配置模板傳送到客戶端的puppet.conf,設置用戶、組、權限

(5)定義配置模板

[root@puppet ~]# vi /etc/puppet/modules/puppet/template/puppet.conf.erb
### config by  puppet ###
[main]logdir = /var/log/puppetrundir = /var/run/puppetssldir = $vardir/ssl
[agent]classfile = $vardir/classes.txtlocalconfig = $vardir/localconfigserver = <%= scope.lookupvar('puppet::params::puppetserver') %>  #參數調用格式<%= 參數 %>report = truepluginsync = falseruninterval = 10 #puppet 客戶端默認連接到puppetmaster的時間間隔,默認30分鐘,這里測試設為10秒,將會生成大量報告,建議測試完后改回1800
說明:模板調用了params.pp中的參數$puppetserver

(6)定義服務類

[root@puppet ~]# vi /etc/puppet/modules/puppet/manifests/service.pp
class puppet::service {service { "puppet":ensure     => running,    #確保服務puppet處于運行狀態hasstatus  => true,       #是否支持service puppet status命令查看狀態hasrestart => true,       #是否支持service puppet restart命令重啟服務enable     => true,       #是否開機啟動服務require    => Class["puppet::install"],}
}

(7)定義puppet主類

[root@puppet ~]# vi /etc/puppet/modules/puppet/manifests/init.pp
class puppet {include puppet::params,puppet::install,puppet::config,puppet::service
}

(8)定義節點文件,調用模塊

[root@puppet ~]# vi /etc/puppet/manifests/centostest.pp

node "centostest.ewin.com" {

include ntp, yum, puppet

}

(9)應用節點文件

[root@puppet ~]# vi /etc/puppet/manifests/site.pp
import "centostest.pp"

2、測試:軟件安裝版本、配置文件、服務啟動

(1)查看已安裝版本

[root@centostest ~]# facter | grep operatingsystemmajrelease
operatingsystemmajrelease => 6
[root@centostest ~]# rpm -aq|grep puppet
puppet-3.7.3-1.el6.noarch
[root@centostest ~]# rpm -aq|grep facter
facter-2.3.0-1.el6.x86_64

(2)查看服務狀態

[root@centostest ~]# /etc/init.d/puppet stop
Stopping puppet agent:                                     [確定]
[root@centostest ~]# /etc/init.d/puppet status
puppet 已停
[root@centostest ~]# chkconfig --list | grep puppet
puppet          0:關閉  1:關閉  2:關閉  3:關閉  4:關閉  5:關閉  6:關閉

(3)查看配置文件

[root@centostest ~]# cat /etc/puppet/puppet.conf 
[main]# The Puppet log directory.# The default value is '$vardir/log'.logdir = /var/log/puppet# Where Puppet PID files are kept.# The default value is '$vardir/run'.rundir = /var/run/puppet# Where SSL certificates are kept.# The default value is '$confdir/ssl'.ssldir = $vardir/ssl
[agent]# The file in which puppetd stores a list of the classes# associated with the retrieved configuratiion.  Can be loaded in# the separate ``puppet`` executable using the ``--loadclasses``# option.# The default value is '$confdir/classes.txt'.classfile = $vardir/classes.txt# Where puppetd caches the local configuration.  An# extension indicating the cache format is added automatically.# The default value is '$confdir/localconfig'.localconfig = $vardir/localconfig

(4)客戶端執行測試

[root@centostest ~]# puppet agent --server puppet.ewin.com --test --noop
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for centostest.ewin.com
Info: Applying configuration version '1415246721'
Notice: /Stage[main]/Puppet::Install/Package[facter]/ensure: current_value 2.3.0-1.el6, should be 2.2.0-1.el6 (noop) #說明:版本將變成2.2.0-1.el6
Notice: /Stage[main]/Puppet::Install/Package[puppet]/ensure: current_value 3.7.3-1.el6, should be 3.7.1-1.el6 (noop) #說明:版本將變成3.7.1-1.el6
Notice: Class[Puppet::Install]: Would have triggered 'refresh' from 2 events
Notice: /Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content:  #說明:生成puppet.conf配置文件內容
--- /etc/puppet/puppet.conf 2014-11-04 06:23:12.000000000 +0800
+++ /tmp/puppet-file20141106-34117-1abwj46-0  2014-11-06 12:04:04.724000002 +0800
@@ -1,25 +1,12 @@
-[main]
-    # The Puppet log directory.
-    # The default value is '$vardir/log'.
-    logdir = /var/log/puppet
-
-    # Where Puppet PID files are kept.
-    # The default value is '$vardir/run'.
-    rundir = /var/run/puppet
-
-    # Where SSL certificates are kept.
-    # The default value is '$confdir/ssl'.
-    ssldir = $vardir/ssl
-
-[agent]
-    # The file in which puppetd stores a list of the classes
-    # associated with the retrieved configuratiion.  Can be loaded in
-    # the separate ``puppet`` executable using the ``--loadclasses``
-    # option.
-    # The default value is '$confdir/classes.txt'.
-    classfile = $vardir/classes.txt
-
-    # Where puppetd caches the local configuration.  An
-    # extension indicating the cache format is added automatically.
-    # The default value is '$confdir/localconfig'.
-    localconfig = $vardir/localconfig
+### config by  puppet ###
+[main]
+    logdir = /var/log/puppet
+    rundir = /var/run/puppet
+    ssldir = $vardir/ssl
+[agent]
+    classfile = $vardir/classes.txt
+    localconfig = $vardir/localconfig
+    server = puppet.ewin.com
+    report = true
+    pluginsync = false
+    runinterval = 10
\ No newline at end of file
#說明:每行前的-表示刪除行,+表示添加行
Notice: /Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content: current_value {md5}58e2f9765e2994db8e8ab19a3513356e, should be {md5}fa6ae34360e0b6b7755165fc8e950a76 (noop)
Info: /Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]: Scheduling refresh of Class[Puppet::Service] #說明:配置文件的改變將觸發service.pp
Notice: Class[Puppet::Service]: Would have triggered 'refresh' from 1 events
Info: Class[Puppet::Service]: Scheduling refresh of Service[puppet]
Notice: Class[Puppet::Config]: Would have triggered 'refresh' from 1 events
Notice: /Stage[main]/Puppet::Service/Service[puppet]/ensure: current_value stopped, should be running (noop) #說明:服務當前是關閉的,將變成運行
Info: /Stage[main]/Puppet::Service/Service[puppet]: Unscheduling refresh on Service[puppet]
Notice: Class[Puppet::Service]: Would have triggered 'refresh' from 1 events
Notice: Stage[main]: Would have triggered 'refresh' from 3 events
Notice: Finished catalog run in 0.70 seconds

(5)真正執行puppet agent(不帶--noop參數)

[root@centostest ~]# puppet agent --server puppet.ewin.com --test
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for centostest.ewin.com
Info: Applying configuration version '1415247249'
Notice: /Stage[main]/Puppet::Install/Package[facter]/ensure: ensure changed '2.3.0-1.el6' to '2.2.0-1.el6'
Error: Could not update: Execution of '/usr/bin/yum -d 0 -e 0 -y downgrade puppet-3.7.1-1.el6' returned 1: Error Downloading Packages:puppet-3.7.1-1.el6.noarch: failure: puppet-3.7.1-1.el6.noarch.rpm from puppetlabs-products: [Errno 256] No more mirrors to try.
Wrapped exception:
Execution of '/usr/bin/yum -d 0 -e 0 -y downgrade puppet-3.7.1-1.el6' returned 1: Error Downloading Packages:puppet-3.7.1-1.el6.noarch: failure: puppet-3.7.1-1.el6.noarch.rpm from puppetlabs-products: [Errno 256] No more mirrors to try.
Error: /Stage[main]/Puppet::Install/Package[puppet]/ensure: change from 3.7.3-1.el6 to 3.7.1-1.el6 failed: Could not update: Execution of '/usr/bin/yum -d 0 -e 0 -y downgrade puppet-3.7.1-1.el6' returned 1: Error Downloading Packages:puppet-3.7.1-1.el6.noarch: failure: puppet-3.7.1-1.el6.noarch.rpm from puppetlabs-products: [Errno 256] No more mirrors to try.
Notice: /Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]: Dependency Package[puppet] has failures: true
Warning: /Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]: Skipping because of failed dependencies
Notice: /Stage[main]/Puppet::Service/Service[puppet]: Dependency Package[puppet] has failures: true
Warning: /Stage[main]/Puppet::Service/Service[puppet]: Skipping because of failed dependencies
Notice: Finished catalog run in 171.49 seconds
報錯:YUM安裝失敗,無法下載軟件包,在客戶端yum clean up再yum list恢復倉庫后重試
[root@centostest ~]# puppet agent --server=puppet.ewin.com --test
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for centostest.ewin.com
Info: Applying configuration version '1415247249'
Notice: /Stage[main]/Puppet::Install/Package[puppet]/ensure: ensure changed '3.7.3-1.el6' to '3.7.1-1.el6'
Notice: /Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content: 
--- /etc/puppet/puppet.conf 2014-09-16 04:33:01.000000000 +0800
+++ /tmp/puppet-file20141106-35765-10dpf4t-0  2014-11-06 15:04:50.422305001 +0800
@@ -1,25 +1,12 @@
-[main]
-    # The Puppet log directory.
-    # The default value is '$vardir/log'.
-    logdir = /var/log/puppet
-
-    # Where Puppet PID files are kept.
-    # The default value is '$vardir/run'.
-    rundir = /var/run/puppet
-
-    # Where SSL certificates are kept.
-    # The default value is '$confdir/ssl'.
-    ssldir = $vardir/ssl
-
-[agent]
-    # The file in which puppetd stores a list of the classes
-    # associated with the retrieved configuratiion.  Can be loaded in
-    # the separate ``puppet`` executable using the ``--loadclasses``
-    # option.
-    # The default value is '$confdir/classes.txt'.
-    classfile = $vardir/classes.txt
-
-    # Where puppetd caches the local configuration.  An
-    # extension indicating the cache format is added automatically.
-    # The default value is '$confdir/localconfig'.
-    localconfig = $vardir/localconfig
+### config by  puppet ###
+[main]
+    logdir = /var/log/puppet
+    rundir = /var/run/puppet
+    ssldir = $vardir/ssl
+[agent]
+    classfile = $vardir/classes.txt
+    localconfig = $vardir/localconfig
+    server = puppet.ewin.com
+    report = true
+    pluginsync = false
+    runinterval = 10
\ No newline at end of file
Info: Computing checksum on file /etc/puppet/puppet.conf
Info: /Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]: Filebucketed /etc/puppet/puppet.conf to puppet with sum 58e2f9765e2994db8e8ab19a3513356e
Notice: /Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content: content changed '{md5}58e2f9765e2994db8e8ab19a3513356e' to '{md5}fa6ae34360e0b6b7755165fc8e950a76'
Info: /Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]: Scheduling refresh of Class[Puppet::Service]
Info: Class[Puppet::Service]: Scheduling refresh of Service[puppet]
Notice: /Stage[main]/Puppet::Service/Service[puppet]/ensure: ensure changed 'stopped' to 'running'
Info: /Stage[main]/Puppet::Service/Service[puppet]: Unscheduling refresh on Service[puppet]
Notice: Finished catalog run in 222.24 seconds

(6)查看客戶端日志

[root@centostest ~]# tailf /var/log/message
Nov  6 12:12:50 centostest puppet-agent[34357]: Retrieving pluginfacts
Nov  6 12:12:50 centostest puppet-agent[34357]: Retrieving plugin
Nov  6 12:12:51 centostest puppet-agent[34357]: Caching catalog for centostest.ewin.com
Nov  6 12:12:52 centostest puppet-agent[34357]: Applying configuration version '1415247249'
Nov  6 12:13:29 centostest yum[34565]: Installed: 1:facter-2.2.0-1.el6.x86_64
Nov  6 12:13:31 centostest puppet-agent[34357]: (/Stage[main]/Puppet::Install/Package[facter]/ensure) ensure changed '2.3.0-1.el6' to '2.2.0-1.el6'
Nov  6 12:15:43 centostest puppet-agent[34357]: Could not update: Execution of '/usr/bin/yum -d 0 -e 0 -y downgrade puppet-3.7.1-1.el6' returned 1: Error Downloading Packages:
Nov  6 12:15:43 centostest puppet-agent[34357]:   puppet-3.7.1-1.el6.noarch: failure: puppet-3.7.1-1.el6.noarch.rpm from puppetlabs-products: [Errno 256] No more mirrors to try.
Nov  6 12:15:43 centostest puppet-agent[34357]: Wrapped exception:
Nov  6 12:15:43 centostest puppet-agent[34357]: Execution of '/usr/bin/yum -d 0 -e 0 -y downgrade puppet-3.7.1-1.el6' returned 1: Error Downloading Packages:
Nov  6 12:15:43 centostest puppet-agent[34357]:   puppet-3.7.1-1.el6.noarch: failure: puppet-3.7.1-1.el6.noarch.rpm from puppetlabs-products: [Errno 256] No more mirrors to try.
Nov  6 12:15:43 centostest puppet-agent[34357]: (/Stage[main]/Puppet::Install/Package[puppet]/ensure) change from 3.7.3-1.el6 to 3.7.1-1.el6 failed: Could not update: Execution of '/usr/bin/yum -d 0 -e 0 -y downgrade puppet-3.7.1-1.el6' returned 1: Error Downloading Packages:
Nov  6 12:15:43 centostest puppet-agent[34357]: (/Stage[main]/Puppet::Install/Package[puppet]/ensure)   puppet-3.7.1-1.el6.noarch: failure: puppet-3.7.1-1.el6.noarch.rpm from puppetlabs-products: [Errno 256] No more mirrors to try.
Nov  6 12:15:43 centostest puppet-agent[34357]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]) Dependency Package[puppet] has failures: true
Nov  6 12:15:43 centostest puppet-agent[34357]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]) Skipping because of failed dependencies
Nov  6 12:15:43 centostest puppet-agent[34357]: (/Stage[main]/Puppet::Service/Service[puppet]) Dependency Package[puppet] has failures: true
Nov  6 12:15:43 centostest puppet-agent[34357]: (/Stage[main]/Puppet::Service/Service[puppet]) Skipping because of failed dependencies
Nov  6 12:15:43 centostest puppet-agent[34357]: Finished catalog run in 171.49 seconds

以上日志是第一次執行puppet agent,安裝facter成功,但下載puppet-3.7.1失敗

Nov  6 15:01:08 centostest puppet-agent[35765]: Retrieving pluginfacts
Nov  6 15:01:08 centostest puppet-agent[35765]: Retrieving plugin
Nov  6 15:01:10 centostest puppet-agent[35765]: Caching catalog for centostest.ewin.com
Nov  6 15:01:10 centostest puppet-agent[35765]: Applying configuration version '1415247249'
Nov  6 15:04:49 centostest yum[35972]: Installed: puppet-3.7.1-1.el6.noarch
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Install/Package[puppet]/ensure) ensure changed '3.7.3-1.el6' to '3.7.1-1.el6'
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) 
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) --- /etc/puppet/puppet.conf#0112014-09-16 04:33:01.000000000 +0800
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) +++ /tmp/puppet-file20141106-35765-10dpf4t-0#0112014-11-06 15:04:50.422305001 +0800
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) @@ -1,25 +1,12 @@
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) -[main]
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) -    # The Puppet log directory.
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) -    # The default value is '$vardir/log'.
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) -    logdir = /var/log/puppet
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) -
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) -    # Where Puppet PID files are kept.
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) -    # The default value is '$vardir/run'.
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) -    rundir = /var/run/puppet
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) -
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) -    # Where SSL certificates are kept.
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) -    # The default value is '$confdir/ssl'.
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) -    ssldir = $vardir/ssl
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) -
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) -[agent]
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) -    # The file in which puppetd stores a list of the classes
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) -    # associated with the retrieved configuratiion.  Can be loaded in
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) -    # the separate ``puppet`` executable using the ``--loadclasses``
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) -    # option.
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) -    # The default value is '$confdir/classes.txt'.
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) -    classfile = $vardir/classes.txt
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) -
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) -    # Where puppetd caches the local configuration.  An
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) -    # extension indicating the cache format is added automatically.
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) -    # The default value is '$confdir/localconfig'.
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) -    localconfig = $vardir/localconfig
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) +### config by  puppet ####015
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) +[main]#015
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) +    logdir = /var/log/puppet#015
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) +    rundir = /var/run/puppet#015
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) +    ssldir = $vardir/ssl#015
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) +[agent]#015
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) +    classfile = $vardir/classes.txt#015
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) +    localconfig = $vardir/localconfig#015
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) +    server = puppet.ewin.com#015
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) +    report = true#015
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) +    pluginsync = false#015
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) +    runinterval = 10
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) \ No newline at end of file
Nov  6 15:04:50 centostest puppet-agent[35765]: Computing checksum on file /etc/puppet/puppet.conf
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]) Filebucketed /etc/puppet/puppet.conf to puppet with sum 58e2f9765e2994db8e8ab19a3513356e
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) content changed '{md5}58e2f9765e2994db8e8ab19a3513356e' to '{md5}fa6ae34360e0b6b7755165fc8e950a76'
Nov  6 15:04:50 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]) Scheduling refresh of Class[Puppet::Service]
Nov  6 15:04:50 centostest puppet-agent[35765]: (Class[Puppet::Service]) Scheduling refresh of Service[puppet]
Nov  6 15:04:52 centostest puppet-agent[36125]: Reopening log files
Nov  6 15:04:52 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Service/Service[puppet]/ensure) ensure changed 'stopped' to 'running'
Nov  6 15:04:52 centostest puppet-agent[35765]: (/Stage[main]/Puppet::Service/Service[puppet]) Unscheduling refresh on Service[puppet]
Nov  6 15:04:52 centostest puppet-agent[35765]: Finished catalog run in 222.24 seconds
Nov  6 15:04:52 centostest puppet-agent[36125]: Starting Puppet client version 3.7.1
Nov  6 15:04:52 centostest puppet-agent[36125]: Run of Puppet configuration client already in progress; skipping  (/var/lib/puppet/state/agent_catalog_run.lock exists)
Nov  6 15:05:06 centostest puppet-agent[36135]: Finished catalog run in 0.46 seconds

以上是重新獲取YUM倉庫后,第二次執行puppet agent的日志, 成功將puppet-3.7.3降為3.7.1版本,因此最好一開始指定好puppet版本安裝。

(7)查看客戶端測試結果

查看已安裝版本:

[root@centostest ~]# rpm -aq|grep facter
facter-2.2.0-1.el6.x86_64
[root@centostest ~]# rpm -aq|grep puppet
puppet-3.7.1-1.el6.noarch

查看服務狀態:

[root@centostest ~]# /etc/init.d/puppet status
puppet (pid  36125) 正在運行...
[root@centostest ~]# chkconfig --list | grep puppet
puppet          0:關閉  1:關閉  2:啟用  3:啟用  4:啟用  5:啟用  6:關閉

查看配置文件:

[root@centostest ~]# cat /etc/puppet/puppet.conf
### config by  puppet ###
[main]logdir = /var/log/puppetrundir = /var/run/puppetssldir = $vardir/ssl
[agent]classfile = $vardir/classes.txtlocalconfig = $vardir/localconfigserver = puppet.ewin.comreport = truepluginsync = falseruninterval = 10
結論:軟件版本成功轉變成指定版本;服務啟動并添加到開機啟動中;配備文件成功從模板獲取,參數應用成功。

3、測試配置文件的變更影響

客戶端修改配置文件導致puppet服務重啟:

[root@centostest ~]# echo "#add a line" >> /etc/puppet/puppet.conf
[root@centostest ~]# tailf /var/log/message
Nov  6 15:33:57 centostest puppet-agent[57545]: (/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content) content changed '{md5}29acb66e2f297a5cf2ff6cbe731998f5' to '{md5}bb6d66a4b72890ef1bfa048c0cf179d8'
Nov  6 15:33:57 centostest puppet-agent[56826]: Caught HUP; calling restart
Nov  6 15:33:57 centostest puppet-agent[57545]: (/Stage[main]/Puppet::Service/Service[puppet]) Triggered 'refresh' from 1 events
Nov  6 15:33:57 centostest puppet-agent[57545]: Finished catalog run in 1.10 seconds
Nov  6 15:33:58 centostest puppet-agent[56826]: Caught HUP; calling restart
Nov  6 15:33:58 centostest puppet-agent[56826]: Restarting with '/usr/bin/puppet agent'
Nov  6 15:33:59 centostest puppet-agent[57782]: Reopening log files
Nov  6 15:34:00 centostest puppet-agent[57782]: Starting Puppet client version 3.7.1
Nov  6 15:34:02 centostest puppet-agent[57784]: Finished catalog run in 0.63 seconds

結論:成功改變配置文件內容,觸發puppet服務重啟,接下來是agent啟動的信息。

4、file資源

file {'nginx.conf': ensure => file,    #定義類型:文件file或目錄directorymode   => '0640',  #權限owner  => root,    #屬于用戶group  => root,    #屬于用戶組
}

其他參數

{ensure       => present|absent|file|directory|link, #present檢查文件是否存在,如果存在則不創建backup       => , #通過filebucket備份文件,可備份到其他設備checksum     => , #檢查文件是否被修改,默認檢測法為MD5,其他有md5lite\mtime\ctime\nonectime        => , #只讀屬性,文件的更新時間mtime        => , #只讀屬性content      => , #文件的內容 force        => , #強制刪除文件、軟鏈接及目錄,確保ensure=absentowner        => , #指定文件的用戶名或用戶IDgroup        => , #指定文件的用戶組名或組IDignore       => , #忽略指定的匹配文件,可以匹配目錄結構link         => , #軟鏈接,類似于ln命令mode         => , #文件權限配置path         => '/tmp/test',#文件路徑,使用雙引號,可用標題代替purge        => , #清空目錄中未在manifest中定義的文件或目錄,必須與recurse=>true使用recurse      => true|false|inf|remote, #遞歸目錄recurselimit => , #遞歸的目錄的深度,值為數字replace      => true|false, #是否允許覆蓋文件內容,默認為true(覆蓋)source       => '/home/123.txt'|'http://'|'puppet:///', #源文件,本地路徑或URL路徑sourceselect => firest|all, #可設置多個source源文件,本參數指定只復制每一個有效文件還是全部文件到目標target       => '/tmp/testlink', #指定目錄,配合ensure => link使用type         => , #只讀狀態檢查文件類型
}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/389374.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/389374.shtml
英文地址,請注明出處:http://en.pswp.cn/news/389374.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

數據可視化及其重要性:Python

Data visualization is an important skill to possess for anyone trying to extract and communicate insights from data. In the field of machine learning, visualization plays a key role throughout the entire process of analysis.對于任何試圖從數據中提取和傳達見…

熊貓數據集_熊貓邁向數據科學的第三部分

熊貓數據集Data is almost never perfect. Data Scientist spend more time in preprocessing dataset than in creating a model. Often we come across scenario where we find some missing data in data set. Such data points are represented with NaN or Not a Number i…

Pytorch有關張量的各種操作

一&#xff0c;創建張量 1. 生成float格式的張量: a torch.tensor([1,2,3],dtype torch.float)2. 生成從1到10&#xff0c;間隔是2的張量: b torch.arange(1,10,step 2)3. 隨機生成從0.0到6.28的10個張量 注意&#xff1a; (1).生成的10個張量中包含0.0和6.28&#xff…

mongodb安裝失敗與解決方法(附安裝教程)

安裝mongodb遇到的一些坑 浪費了大量的時間 在此記錄一下 主要是電腦系統win10企業版自帶的防火墻 當然還有其他的一些坑 一般的問題在第6步驟都可以解決&#xff0c;本教程的安裝步驟不夠詳細的話 請自行百度或谷歌 安裝教程很多 我是基于node.js使用mongodb結合Robo 3T數…

【洛谷算法題】P1046-[NOIP2005 普及組] 陶陶摘蘋果【入門2分支結構】Java題解

&#x1f468;?&#x1f4bb;博客主頁&#xff1a;花無缺 歡迎 點贊&#x1f44d; 收藏? 留言&#x1f4dd; 加關注?! 本文由 花無缺 原創 收錄于專欄 【洛谷算法題】 文章目錄 【洛谷算法題】P1046-[NOIP2005 普及組] 陶陶摘蘋果【入門2分支結構】Java題解&#x1f30f;題目…

web性能優化(理論)

什么是性能優化&#xff1f; 就是讓用戶感覺你的網站加載速度很快。。。哈哈哈。 分析 讓我們來分析一下從用戶按下回車鍵到網站呈現出來經歷了哪些和前端相關的過程。 緩存 首先看本地是否有緩存&#xff0c;如果有符合使用條件的緩存則不需要向服務器發送請求了。DNS查詢建立…

python多項式回歸_如何在Python中實現多項式回歸模型

python多項式回歸Let’s start with an example. We want to predict the Price of a home based on the Area and Age. The function below was used to generate Home Prices and we can pretend this is “real-world data” and our “job” is to create a model which wi…

充分利用UC berkeleys數據科學專業

By Kyra Wong and Kendall Kikkawa黃凱拉(Kyra Wong)和菊川健多 ( Kendall Kikkawa) 什么是“數據科學”&#xff1f; (What is ‘Data Science’?) Data collection, an important aspect of “data science”, is not a new idea. Before the tech boom, every industry al…

文本二叉樹折半查詢及其截取值

using System;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Collections;using System.IO;namespace CS_ScanSample1{ /// <summary> /// Logic 的摘要說明。 /// </summary> …

nn.functional 和 nn.Module入門講解

本文來自《20天吃透Pytorch》 一&#xff0c;nn.functional 和 nn.Module 前面我們介紹了Pytorch的張量的結構操作和數學運算中的一些常用API。 利用這些張量的API我們可以構建出神經網絡相關的組件(如激活函數&#xff0c;模型層&#xff0c;損失函數)。 Pytorch和神經網絡…

10.30PMP試題每日一題

SC>0&#xff0c;CPI<1&#xff0c;說明項目截止到當前&#xff1a;A、進度超前&#xff0c;成本超值B、進度落后&#xff0c;成本結余C、進度超前&#xff0c;成本結余D、無法判斷 答案將于明天和新題一起揭曉&#xff01; 10.29試題答案&#xff1a;A轉載于:https://bl…

02-web框架

1 while True:print(server is waiting...)conn, addr server.accept()data conn.recv(1024) print(data:, data)# 1.得到請求的url路徑# ------------dict/obj d["path":"/login"]# d.get(”path“)# 按著http請求協議解析數據# 專注于web業…

ai驅動數據安全治理_AI驅動的Web數據收集解決方案的新起點

ai驅動數據安全治理Data gathering consists of many time-consuming and complex activities. These include proxy management, data parsing, infrastructure management, overcoming fingerprinting anti-measures, rendering JavaScript-heavy websites at scale, and muc…

從Text文本中讀值插入到數據庫中

/// <summary> /// 轉換數據&#xff0c;從Text文本中導入到數據庫中 /// </summary> private void ChangeTextToDb() { if(File.Exists("Storage Card/Zyk.txt")) { try { this.RecNum.Visibletrue; SqlCeCommand sqlCreateTable…

Dataset和DataLoader構建數據通道

重點在第二部分的構建數據通道和第三部分的加載數據集 Pytorch通常使用Dataset和DataLoader這兩個工具類來構建數據管道。 Dataset定義了數據集的內容&#xff0c;它相當于一個類似列表的數據結構&#xff0c;具有確定的長度&#xff0c;能夠用索引獲取數據集中的元素。 而D…

鐵拳nat映射_鐵拳如何重塑我的數據可視化設計流程

鐵拳nat映射It’s been a full year since I’ve become an independent data visualization designer. When I first started, projects that came to me didn’t relate to my interests or skills. Over the past eight months, it’s become very clear to me that when cl…

Django2 Web 實戰03-文件上傳

作者&#xff1a;Hubery 時間&#xff1a;2018.10.31 接上文&#xff1a;接上文&#xff1a;Django2 Web 實戰02-用戶注冊登錄退出 視頻是一種可視化媒介&#xff0c;因此視頻數據庫至少應該存儲圖像。讓用戶上傳文件是個很大的隱患&#xff0c;因此接下來會討論這倆話題&#…

BZOJ.2738.矩陣乘法(整體二分 二維樹狀數組)

題目鏈接 BZOJ洛谷 整體二分。把求序列第K小的樹狀數組改成二維樹狀數組就行了。 初始答案區間有點大&#xff0c;離散化一下。 因為這題是一開始給點&#xff0c;之后詢問&#xff0c;so可以先處理該區間值在l~mid的修改&#xff0c;再處理詢問。即二分標準可以直接用點的標號…

從數據庫里讀值往TEXT文本里寫

/// <summary> /// 把預定內容導入到Text文檔 /// </summary> private void ChangeDbToText() { this.RecNum.Visibletrue; //建立文件&#xff0c;并打開 string oneLine ""; string filename "Storage Card/YD" DateTime.Now.…

DengAI —如何應對數據科學競賽? (EDA)

了解機器學習 (Understanding ML) This article is based on my entry into DengAI competition on the DrivenData platform. I’ve managed to score within 0.2% (14/9069 as on 02 Jun 2020). Some of the ideas presented here are strictly designed for competitions li…