作用:通过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.ppclasspuppet::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("Modulepuppetisnotsupportedon${::operatingsystem}")}}}

(3)定义安装类

[root@puppet~]#vi/etc/puppet/modules/puppet/manifests/install.ppclasspuppet::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.ppclasspuppet::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###configbypuppet###[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.ppclasspuppet::service{service{"puppet":ensure=>running,#确保服务puppet处于运行状态hasstatus=>true,#是否支持servicepuppetstatus命令查看状态hasrestart=>true,#是否支持servicepuppetrestart命令重启服务enable=>true,#是否开机启动服务require=>Class["puppet::install"],}}

(7)定义puppet主类

[root@puppet~]#vi/etc/puppet/modules/puppet/manifests/init.ppclasspuppet{includepuppet::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.ppimport"centostest.pp"



2、测试:软件安装版本、配置文件、服务启动

(1)查看已安装版本

[root@centostest~]#facter|grepoperatingsystemmajreleaseoperatingsystemmajrelease=>6[root@centostest~]#rpm-aq|greppuppetpuppet-3.7.3-1.el6.noarch[root@centostest~]#rpm-aq|grepfacterfacter-2.3.0-1.el6.x86_64

(2)查看服务状态

[root@centostest~]#/etc/init.d/puppetstopStoppingpuppetagent:[确定][root@centostest~]#/etc/init.d/puppetstatuspuppet已停[root@centostest~]#chkconfig--list|greppuppetpuppet0:关闭1:关闭2:关闭3:关闭4:关闭5:关闭6:关闭

(3)查看配置文件

[root@centostest~]#cat/etc/puppet/puppet.conf[main]#ThePuppetlogdirectory.#Thedefaultvalueis'$vardir/log'.logdir=/var/log/puppet#WherePuppetPIDfilesarekept.#Thedefaultvalueis'$vardir/run'.rundir=/var/run/puppet#WhereSSLcertificatesarekept.#Thedefaultvalueis'$confdir/ssl'.ssldir=$vardir/ssl[agent]#Thefileinwhichpuppetdstoresalistoftheclasses#associatedwiththeretrievedconfiguratiion.Canbeloadedin#theseparate``puppet``executableusingthe``--loadclasses``#option.#Thedefaultvalueis'$confdir/classes.txt'.classfile=$vardir/classes.txt#Wherepuppetdcachesthelocalconfiguration.An#extensionindicatingthecacheformatisaddedautomatically.#Thedefaultvalueis'$confdir/localconfig'.localconfig=$vardir/localconfig

(4)客户端执行测试

[root@centostest~]#puppetagent--serverpuppet.ewin.com--test--noopInfo:RetrievingpluginfactsInfo:RetrievingpluginInfo:Cachingcatalogforcentostest.ewin.comInfo:Applyingconfigurationversion'1415246721'Notice:/Stage[main]/Puppet::Install/Package[facter]/ensure:current_value2.3.0-1.el6,shouldbe2.2.0-1.el6(noop)#说明:版本将变成2.2.0-1.el6Notice:/Stage[main]/Puppet::Install/Package[puppet]/ensure:current_value3.7.3-1.el6,shouldbe3.7.1-1.el6(noop)#说明:版本将变成3.7.1-1.el6Notice:Class[Puppet::Install]:Wouldhavetriggered'refresh'from2eventsNotice:/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content:#说明:生成puppet.conf配置文件内容---/etc/puppet/puppet.conf2014-11-0406:23:12.000000000+0800+++/tmp/puppet-file20141106-34117-1abwj46-02014-11-0612:04:04.724000002+0800@@-1,25+1,12@@-[main]-#ThePuppetlogdirectory.-#Thedefaultvalueis'$vardir/log'.-logdir=/var/log/puppet--#WherePuppetPIDfilesarekept.-#Thedefaultvalueis'$vardir/run'.-rundir=/var/run/puppet--#WhereSSLcertificatesarekept.-#Thedefaultvalueis'$confdir/ssl'.-ssldir=$vardir/ssl--[agent]-#Thefileinwhichpuppetdstoresalistoftheclasses-#associatedwiththeretrievedconfiguratiion.Canbeloadedin-#theseparate``puppet``executableusingthe``--loadclasses``-#option.-#Thedefaultvalueis'$confdir/classes.txt'.-classfile=$vardir/classes.txt--#Wherepuppetdcachesthelocalconfiguration.An-#extensionindicatingthecacheformatisaddedautomatically.-#Thedefaultvalueis'$confdir/localconfig'.-localconfig=$vardir/localconfig+###configbypuppet###+[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\Nonewlineatendoffile#说明:每行前的-表示删除行,+表示添加行Notice:/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content:current_value{md5}58e2f9765e2994db8e8ab19a3513356e,shouldbe{md5}fa6ae34360e0b6b7755165fc8e950a76(noop)Info:/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]:SchedulingrefreshofClass[Puppet::Service]#说明:配置文件的改变将触发service.ppNotice:Class[Puppet::Service]:Wouldhavetriggered'refresh'from1eventsInfo:Class[Puppet::Service]:SchedulingrefreshofService[puppet]Notice:Class[Puppet::Config]:Wouldhavetriggered'refresh'from1eventsNotice:/Stage[main]/Puppet::Service/Service[puppet]/ensure:current_valuestopped,shouldberunning(noop)#说明:服务当前是关闭的,将变成运行Info:/Stage[main]/Puppet::Service/Service[puppet]:UnschedulingrefreshonService[puppet]Notice:Class[Puppet::Service]:Wouldhavetriggered'refresh'from1eventsNotice:Stage[main]:Wouldhavetriggered'refresh'from3eventsNotice:Finishedcatalogrunin0.70seconds


(5)真正执行puppet agent(不带--noop参数)

[root@centostest~]#puppetagent--serverpuppet.ewin.com--testInfo:RetrievingpluginfactsInfo:RetrievingpluginInfo:Cachingcatalogforcentostest.ewin.comInfo:Applyingconfigurationversion'1415247249'Notice:/Stage[main]/Puppet::Install/Package[facter]/ensure:ensurechanged'2.3.0-1.el6'to'2.2.0-1.el6'Error:Couldnotupdate:Executionof'/usr/bin/yum-d0-e0-ydowngradepuppet-3.7.1-1.el6'returned1:ErrorDownloadingPackages:puppet-3.7.1-1.el6.noarch:failure:puppet-3.7.1-1.el6.noarch.rpmfrompuppetlabs-products:[Errno256]Nomoremirrorstotry.Wrappedexception:Executionof'/usr/bin/yum-d0-e0-ydowngradepuppet-3.7.1-1.el6'returned1:ErrorDownloadingPackages:puppet-3.7.1-1.el6.noarch:failure:puppet-3.7.1-1.el6.noarch.rpmfrompuppetlabs-products:[Errno256]Nomoremirrorstotry.Error:/Stage[main]/Puppet::Install/Package[puppet]/ensure:changefrom3.7.3-1.el6to3.7.1-1.el6failed:Couldnotupdate:Executionof'/usr/bin/yum-d0-e0-ydowngradepuppet-3.7.1-1.el6'returned1:ErrorDownloadingPackages:puppet-3.7.1-1.el6.noarch:failure:puppet-3.7.1-1.el6.noarch.rpmfrompuppetlabs-products:[Errno256]Nomoremirrorstotry.Notice:/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]:DependencyPackage[puppet]hasfailures:trueWarning:/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]:SkippingbecauseoffaileddependenciesNotice:/Stage[main]/Puppet::Service/Service[puppet]:DependencyPackage[puppet]hasfailures:trueWarning:/Stage[main]/Puppet::Service/Service[puppet]:SkippingbecauseoffaileddependenciesNotice:Finishedcatalogrunin171.49seconds

报错:YUM安装失败,无法下载软件包,在客户端yum clean up再yum list恢复仓库后重试

[root@centostest~]#puppetagent--server=puppet.ewin.com--testInfo:RetrievingpluginfactsInfo:RetrievingpluginInfo:Cachingcatalogforcentostest.ewin.comInfo:Applyingconfigurationversion'1415247249'Notice:/Stage[main]/Puppet::Install/Package[puppet]/ensure:ensurechanged'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.conf2014-09-1604:33:01.000000000+0800+++/tmp/puppet-file20141106-35765-10dpf4t-02014-11-0615:04:50.422305001+0800@@-1,25+1,12@@-[main]-#ThePuppetlogdirectory.-#Thedefaultvalueis'$vardir/log'.-logdir=/var/log/puppet--#WherePuppetPIDfilesarekept.-#Thedefaultvalueis'$vardir/run'.-rundir=/var/run/puppet--#WhereSSLcertificatesarekept.-#Thedefaultvalueis'$confdir/ssl'.-ssldir=$vardir/ssl--[agent]-#Thefileinwhichpuppetdstoresalistoftheclasses-#associatedwiththeretrievedconfiguratiion.Canbeloadedin-#theseparate``puppet``executableusingthe``--loadclasses``-#option.-#Thedefaultvalueis'$confdir/classes.txt'.-classfile=$vardir/classes.txt--#Wherepuppetdcachesthelocalconfiguration.An-#extensionindicatingthecacheformatisaddedautomatically.-#Thedefaultvalueis'$confdir/localconfig'.-localconfig=$vardir/localconfig+###configbypuppet###+[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\NonewlineatendoffileInfo:Computingchecksumonfile/etc/puppet/puppet.confInfo:/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]:Filebucketed/etc/puppet/puppet.conftopuppetwithsum58e2f9765e2994db8e8ab19a3513356eNotice:/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content:contentchanged'{md5}58e2f9765e2994db8e8ab19a3513356e'to'{md5}fa6ae34360e0b6b7755165fc8e950a76'Info:/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]:SchedulingrefreshofClass[Puppet::Service]Info:Class[Puppet::Service]:SchedulingrefreshofService[puppet]Notice:/Stage[main]/Puppet::Service/Service[puppet]/ensure:ensurechanged'stopped'to'running'Info:/Stage[main]/Puppet::Service/Service[puppet]:UnschedulingrefreshonService[puppet]Notice:Finishedcatalogrunin222.24seconds

(6)查看客户端日志

[root@centostest~]#tailf/var/log/messageNov612:12:50centostestpuppet-agent[34357]:RetrievingpluginfactsNov612:12:50centostestpuppet-agent[34357]:RetrievingpluginNov612:12:51centostestpuppet-agent[34357]:Cachingcatalogforcentostest.ewin.comNov612:12:52centostestpuppet-agent[34357]:Applyingconfigurationversion'1415247249'Nov612:13:29centostestyum[34565]:Installed:1:facter-2.2.0-1.el6.x86_64Nov612:13:31centostestpuppet-agent[34357]:(/Stage[main]/Puppet::Install/Package[facter]/ensure)ensurechanged'2.3.0-1.el6'to'2.2.0-1.el6'Nov612:15:43centostestpuppet-agent[34357]:Couldnotupdate:Executionof'/usr/bin/yum-d0-e0-ydowngradepuppet-3.7.1-1.el6'returned1:ErrorDownloadingPackages:Nov612:15:43centostestpuppet-agent[34357]:puppet-3.7.1-1.el6.noarch:failure:puppet-3.7.1-1.el6.noarch.rpmfrompuppetlabs-products:[Errno256]Nomoremirrorstotry.Nov612:15:43centostestpuppet-agent[34357]:Wrappedexception:Nov612:15:43centostestpuppet-agent[34357]:Executionof'/usr/bin/yum-d0-e0-ydowngradepuppet-3.7.1-1.el6'returned1:ErrorDownloadingPackages:Nov612:15:43centostestpuppet-agent[34357]:puppet-3.7.1-1.el6.noarch:failure:puppet-3.7.1-1.el6.noarch.rpmfrompuppetlabs-products:[Errno256]Nomoremirrorstotry.Nov612:15:43centostestpuppet-agent[34357]:(/Stage[main]/Puppet::Install/Package[puppet]/ensure)changefrom3.7.3-1.el6to3.7.1-1.el6failed:Couldnotupdate:Executionof'/usr/bin/yum-d0-e0-ydowngradepuppet-3.7.1-1.el6'returned1:ErrorDownloadingPackages:Nov612:15:43centostestpuppet-agent[34357]:(/Stage[main]/Puppet::Install/Package[puppet]/ensure)puppet-3.7.1-1.el6.noarch:failure:puppet-3.7.1-1.el6.noarch.rpmfrompuppetlabs-products:[Errno256]Nomoremirrorstotry.Nov612:15:43centostestpuppet-agent[34357]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf])DependencyPackage[puppet]hasfailures:trueNov612:15:43centostestpuppet-agent[34357]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf])SkippingbecauseoffaileddependenciesNov612:15:43centostestpuppet-agent[34357]:(/Stage[main]/Puppet::Service/Service[puppet])DependencyPackage[puppet]hasfailures:trueNov612:15:43centostestpuppet-agent[34357]:(/Stage[main]/Puppet::Service/Service[puppet])SkippingbecauseoffaileddependenciesNov612:15:43centostestpuppet-agent[34357]:Finishedcatalogrunin171.49seconds

#以上日志是第一次执行puppet agent,安装facter成功,但下载puppet-3.7.1失败


Nov615:01:08centostestpuppet-agent[35765]:RetrievingpluginfactsNov615:01:08centostestpuppet-agent[35765]:RetrievingpluginNov615:01:10centostestpuppet-agent[35765]:Cachingcatalogforcentostest.ewin.comNov615:01:10centostestpuppet-agent[35765]:Applyingconfigurationversion'1415247249'Nov615:04:49centostestyum[35972]:Installed:puppet-3.7.1-1.el6.noarchNov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Install/Package[puppet]/ensure)ensurechanged'3.7.3-1.el6'to'3.7.1-1.el6'Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)---/etc/puppet/puppet.conf#0112014-09-1604:33:01.000000000+0800Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)+++/tmp/puppet-file20141106-35765-10dpf4t-0#0112014-11-0615:04:50.422305001+0800Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)@@-1,25+1,12@@Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)-[main]Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)-#ThePuppetlogdirectory.Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)-#Thedefaultvalueis'$vardir/log'.Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)-logdir=/var/log/puppetNov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)-Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)-#WherePuppetPIDfilesarekept.Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)-#Thedefaultvalueis'$vardir/run'.Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)-rundir=/var/run/puppetNov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)-Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)-#WhereSSLcertificatesarekept.Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)-#Thedefaultvalueis'$confdir/ssl'.Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)-ssldir=$vardir/sslNov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)-Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)-[agent]Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)-#ThefileinwhichpuppetdstoresalistoftheclassesNov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)-#associatedwiththeretrievedconfiguratiion.CanbeloadedinNov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)-#theseparate``puppet``executableusingthe``--loadclasses``Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)-#option.Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)-#Thedefaultvalueis'$confdir/classes.txt'.Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)-classfile=$vardir/classes.txtNov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)-Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)-#Wherepuppetdcachesthelocalconfiguration.AnNov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)-#extensionindicatingthecacheformatisaddedautomatically.Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)-#Thedefaultvalueis'$confdir/localconfig'.Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)-localconfig=$vardir/localconfigNov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)+###configbypuppet####015Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)+[main]#015Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)+logdir=/var/log/puppet#015Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)+rundir=/var/run/puppet#015Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)+ssldir=$vardir/ssl#015Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)+[agent]#015Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)+classfile=$vardir/classes.txt#015Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)+localconfig=$vardir/localconfig#015Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)+server=puppet.ewin.com#015Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)+report=true#015Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)+pluginsync=false#015Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)+runinterval=10Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)\NonewlineatendoffileNov615:04:50centostestpuppet-agent[35765]:Computingchecksumonfile/etc/puppet/puppet.confNov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf])Filebucketed/etc/puppet/puppet.conftopuppetwithsum58e2f9765e2994db8e8ab19a3513356eNov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)contentchanged'{md5}58e2f9765e2994db8e8ab19a3513356e'to'{md5}fa6ae34360e0b6b7755165fc8e950a76'Nov615:04:50centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf])SchedulingrefreshofClass[Puppet::Service]Nov615:04:50centostestpuppet-agent[35765]:(Class[Puppet::Service])SchedulingrefreshofService[puppet]Nov615:04:52centostestpuppet-agent[36125]:ReopeninglogfilesNov615:04:52centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Service/Service[puppet]/ensure)ensurechanged'stopped'to'running'Nov615:04:52centostestpuppet-agent[35765]:(/Stage[main]/Puppet::Service/Service[puppet])UnschedulingrefreshonService[puppet]Nov615:04:52centostestpuppet-agent[35765]:Finishedcatalogrunin222.24secondsNov615:04:52centostestpuppet-agent[36125]:StartingPuppetclientversion3.7.1Nov615:04:52centostestpuppet-agent[36125]:RunofPuppetconfigurationclientalreadyinprogress;skipping(/var/lib/puppet/state/agent_catalog_run.lockexists)Nov615:05:06centostestpuppet-agent[36135]:Finishedcatalogrunin0.46seconds

#以上是重新获取YUM仓库后,第二次执行puppet agent的日志, 成功将puppet-3.7.3降为3.7.1版本,因此最好一开始指定好puppet版本安装。

(7)查看客户端测试结果

查看已安装版本:

[root@centostest~]#rpm-aq|grepfacterfacter-2.2.0-1.el6.x86_64[root@centostest~]#rpm-aq|greppuppetpuppet-3.7.1-1.el6.noarch

查看服务状态:

[root@centostest~]#/etc/init.d/puppetstatuspuppet(pid36125)正在运行...[root@centostest~]#chkconfig--list|greppuppetpuppet0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭

查看配置文件:

[root@centostest~]#cat/etc/puppet/puppet.conf###configbypuppet###[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"#addaline">>/etc/puppet/puppet.conf[root@centostest~]#tailf/var/log/messageNov615:33:57centostestpuppet-agent[57545]:(/Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content)contentchanged'{md5}29acb66e2f297a5cf2ff6cbe731998f5'to'{md5}bb6d66a4b72890ef1bfa048c0cf179d8'Nov615:33:57centostestpuppet-agent[56826]:CaughtHUP;callingrestartNov615:33:57centostestpuppet-agent[57545]:(/Stage[main]/Puppet::Service/Service[puppet])Triggered'refresh'from1eventsNov615:33:57centostestpuppet-agent[57545]:Finishedcatalogrunin1.10secondsNov615:33:58centostestpuppet-agent[56826]:CaughtHUP;callingrestartNov615:33:58centostestpuppet-agent[56826]:Restartingwith'/usr/bin/puppetagent'Nov615:33:59centostestpuppet-agent[57782]:ReopeninglogfilesNov615:34:00centostestpuppet-agent[57782]:StartingPuppetclientversion3.7.1Nov615:34:02centostestpuppet-agent[57784]:Finishedcatalogrunin0.63seconds

结论:成功改变配置文件内容,触发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=>,#只读状态检查文件类型}