如果需要交流puppet 可加入puppet技術(shù)交流QQ群 296934942
成都創(chuàng)新互聯(lián)公司是一家專注于網(wǎng)站制作、網(wǎng)站設(shè)計與策劃設(shè)計,安國網(wǎng)站建設(shè)哪家好?成都創(chuàng)新互聯(lián)公司做網(wǎng)站,專注于網(wǎng)站建設(shè)十載,網(wǎng)設(shè)計領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:安國等地區(qū)。安國做網(wǎng)站價格咨詢:18982081108
實驗環(huán)境:
puppetserver.rsyslog.org
MCollective客戶端+ACtiveMQ服務(wù)端+Puppet服務(wù)端
agent1.rsyslog.org
MCollective服務(wù)端+Puppet客戶端
應(yīng)用:apache
agent2.rsyslog.org
MCollective服務(wù)端+Puppet客戶端
應(yīng)用:apache+MySQL
agent3.rsyslog.org
MCollective服務(wù)端+Puppet客戶端
應(yīng)用:php
實驗步驟:
一、在Puppetserver端部署RabbitMQ
1、安裝ACtiveMQ
[root@puppetserver yum.repos.d]# yum install tanukiwrapper activemq activemq-info-provider
2、配置ActiveMQ
3、啟動ActiveMQ
[root@puppetserver activemq]# /etc/rc.d/init.d/activemq restart
Stopping ActiveMQ Broker...
ActiveMQ Broker was not running.
Starting ActiveMQ Broker...
[root@puppetserver activemq]# chkconfig activemq on
[root@puppetserver activemq]# netstat -nlatp | grep 61613
tcp 0 0 :::61613 :::* LISTEN 3098/java
二、在Puppetserver端部署MCollective客戶端
1、安裝stomp gem包(也可以通過yum安裝rubygem-stomp包)
[root@puppetserver ~]# gem install stomp
Successfully installed stomp-1.2.14
1 gem installed
Installing ri documentation for stomp-1.2.14...
Installing RDoc documentation for stomp-1.2.14...
2、安裝Mcollective客戶端
[root@puppetserver activemq]# yum install mcollective-common mcollective-client
3、配置Mcollective連接ACtiveMQ
[root@puppetserver ~]# cat /etc/mcollective/client.cfg
topicprefix = /topic/
main_collective = mcollective
collectives = mcollective
libdir = /usr/libexec/mcollective
logger_type = console
loglevel = warn
# Plugins
securityprovider = psk
plugin.psk = 456.com
connector = stomp
#plugin.stomp.host = localhost
plugin.stomp.host = 172.16.200.100
plugin.stomp.port = 61613
plugin.stomp.user = mcollective
plugin.stomp.password = secret
# Facts
factsource = yaml
plugin.yaml = /etc/mcollective/facts.yaml
三、在所有節(jié)點上部署MCollective服務(wù)端
1、安裝stomp gem包
[root@agent1 mcollective]# gem install stomp
Successfully installed stomp-1.2.14
1 gem installed
Installing ri documentation for stomp-1.2.14...
Installing RDoc documentation for stomp-1.2.14...
2、安裝MCollective服務(wù)端
[root@agent1 yum.repos.d]# yum install mcollective mcollective-common
Installing : ruby-irb 1/6
Installing : ruby-rdoc 2/6
Installing : rubygems 3/6
Installing : rubygem-stomp 4/6
Installing : mcollective-common 5/6
Installing : mcollective
2、配置MCollective服務(wù)端連接到ACtiveMQ
[root@agent1 yum.repos.d]# cat /etc/mcollective/server.cfg
topicprefix = /topic/
main_collective = mcollective
collectives = mcollective
libdir = /usr/libexec/mcollective
logfile = /var/log/mcollective.log
loglevel = info
daemonize = 1
# Plugins
securityprovider = psk
plugin.psk = 456.com
connector = stomp
plugin.stomp.host = 172.16.200.100
plugin.stomp.port = 61613
plugin.stomp.user = mcollective
plugin.stomp.password = secret
# Facts
factsource = yaml
plugin.yaml = /etc/mcollective/facts.yaml
[root@agent1 rpms]# /etc/rc.d/init.d/mcollective restart
Shutting down mcollective:
Starting mcollective: [ OK ]
四、測試MCollective通訊是否正常
[root@puppetserver activemq]# mco help
The Marionette Collective version 2.2.4
completion Helper for shell completion systems
facts Reports on usage for a specific fact
find Find hosts using the discovery system matching filter criteria
help Application list and help
inventory General reporting tool for nodes, collectives and subcollectives
ping Ping all nodes
plugin MCollective Plugin Application
rpc Generic RPC agent client application
[root@puppetserver activemq]# mco ping #測試和MC服務(wù)器端通訊是否正常
agent1.rsyslog.org time=118.40 ms
agent1.rsyslog.org time=158.20 ms
agent1.rsyslog.org time=158.99 ms
---- ping statistics ----
3 replies max: 158.99 min: 118.40 avg: 145.20
[root@puppetserver activemq]# mco inventory agent1.rsyslog.org #查看某一個MC服務(wù)器端MC的相關(guān)信息
Inventory for agent1.rsyslog.org:
Server Statistics:
Version: 2.2.4
Start Time: Sun Aug 25 12:36:25 +0800 2013
Config File: /etc/mcollective/server.cfg
Collectives: mcollective
Main Collective: mcollective
Process ID: 8304
Total Messages: 3
Messages Passed Filters: 3
Messages Filtered: 0
Expired Messages: 0
Replies Sent: 2
Total Processor Time: 0.02 seconds
System Time: 0.0 seconds
Agents:
discovery rpcutil
Data Plugins:
agent fstat
Configuration Management Classes:
No classes applied
Facts:
mcollective => 1
[root@puppetserver activemq]# mco rpc rpcutil agent_inventory -I agent1.rsyslog.org
* [ ============================================================> ] 1 / 1
agent1.rsyslog.org
Agents: [{:author=>"R.I.Pienaar
:agent=>"discovery",
:version=>"2.2.4",
:license=>"Apache License, Version 2",
:name=>"Discovery Agent",
:timeout=>5,
:description=>"MCollective Discovery Agent",
:url=>"http://www.marionette-collective.org"},
{:author=>"R.I.Pienaar
:agent=>"rpcutil",
:version=>"1.0",
:license=>"Apache License, Version 2.0",
:name=>"rpcutil",
:timeout=>10,
:description=>
"General helpful actions that expose stats and internals to SimpleRPC clients",
:url=>"http://marionette-collective.org/"}]
Finished processing 1 / 1 hosts in 87.23 ms
[root@puppetserver activemq]# mco help inventory #查看某一個命令下的參數(shù)
General reporting tool for nodes, collectives and subcollectives
--script SCRIPT Script to run
--list-collectives, --lc List all known collectives
--collective-graph, --cg, --map MAP
Create a DOT graph of all collectives
--np, --no-progress Do not show the progress bar
-1, --one Send request to only one discovered nodes
--batch SIZE Do requests in batches
--batch-sleep SECONDS Sleep time between batches
--limit-seed NUMBER Seed value for deterministic random batching
--limit-nodes, --ln, --limit COUNT
Send request to only a subset of nodes, can be a percentage
-j, --json Produce JSON output
--display MODE Influence how results are displayed. One of ok, all or failed
-c, --config FILE Load configuratuion from file rather than default
-v, --verbose Be verbose
-h, --help Display this screen
Common Options
-T, --target COLLECTIVE Target messages to a specific sub collective
--dt, --discovery-timeout SECONDS
Timeout for doing discovery
-t, --timeout SECONDS Timeout for calling remote agents
-q, --quiet Do not be verbose
--ttl TTL Set the message validity period
--reply-to TARGET Set a custom target for replies
--dm, --disc-method METHOD Which discovery method to use
--do, --disc-option OPTION Options to pass to the discovery method
--nodes FILE List of nodes to address
Host Filters
-W, --with FILTER Combined classes and facts filter
-S, --select FILTER Compound filter combining facts and classes
-F, --wf, --with-fact fact=val Match hosts with a certain fact
-C, --wc, --with-class CLASS Match hosts with a certain config management class
-A, --wa, --with-agent AGENT Match hosts with a certain agent
-I, --wi, --with-identity IDENT Match hosts with a certain configured identity
The Marionette Collective 2.2.4
五、部署MCollective-puppet插件
1、安裝puppet插件
#[root@agent1 ~]# yum install mcollective-package-agent mcollective-package-common
[root@agent1 ~]# yum install mcollective-puppet-agent mcollective-puppet-common
#[root@puppetserver ~]# yum install mcollective-package-client mcollective-package-common
[root@puppetserver ~]# yum install mcollective-puppet-client mcollective-puppet-common
2、載入agent插件
[root@agent1 ~]# /etc/rc.d/init.d/mcollective reload-agents
Reloading mcollective agents: [ OK ]
3、查看插件是否載入成功
[root@puppetserver sbin]# mco inventory agent1.rsyslog.org
Inventory for agent1.rsyslog.org:
Server Statistics:
Version: 2.2.4
Start Time: Sun Aug 25 14:37:59 +0800 2013
Config File: /etc/mcollective/server.cfg
Collectives: mcollective
Main Collective: mcollective
Process ID: 11978
Total Messages: 13
Messages Passed Filters: 13
Messages Filtered: 0
Expired Messages: 0
Replies Sent: 12
Total Processor Time: 2.49 seconds
System Time: 0.47 seconds
Agents:
discovery package puppet #插件已經(jīng)載入
rpcutil
Data Plugins:
agent fstat puppet
resource
Configuration Management Classes:
No classes applied
Facts:
mcollective => 1
4、從MCollective中運行puppet進行測試(觸發(fā)節(jié)點agent運行一次)
注意:所有節(jié)點puppetd服務(wù)必須關(guān)閉
[root@puppetserver sbin]# mco puppet -v runonce #失敗運行的結(jié)果
Discovering hosts using the mc method for 2 second(s) .... 0
No request sent, we did not discover any nodes.
---- rpc stats ----
Nodes: 0 / 0
Pass / Fail: 0 / 0
Start Time: Sun Aug 25 14:55:29 +0800 2013
Discovery Time: 2003.59ms
Agent Time: 0.00ms
Total Time: 2003.59ms
[root@puppetserver sbin]# mco puppet -v runonce #成功運行的結(jié)果
Discovering hosts using the mc method for 2 second(s) .... 1
* [ ============================================================> ] 1 / 1
agent1.rsyslog.org : OK #成功啟動了節(jié)點的puppetd進程
{:summary=> "Started a background Puppet run using the 'puppet agent --onetime --daemonize --color=false --splay --splaylimit 30' command"}
---- rpc stats ----
Nodes: 1 / 1
Pass / Fail: 1 / 0
Start Time: Sun Aug 25 14:46:04 +0800 2013
Discovery Time: 2003.13ms
Agent Time: 1534.35ms
Total Time: 3537.49ms
[root@agent1 ~]# tailf /var/log/messages #查看同步情況
[root@agent1 ~]# watch -d /etc/rc.d/init.d/puppet status #查看節(jié)點puppet服務(wù)變化情況
六、部署MCollective-facter插件
1、安裝facter插件
[root@agent1 ~]# yum install mcollective-facter-facts
[root@agent1 ~]# ll /usr/libexec/mcollective/mcollective/facts/
total 24
-rw-r--r-- 1 root root 422 Feb 21 2013 facter_facts.ddl
-rw-r--r-- 1 root root 945 Feb 21 2013 facter_facts.rb
-rw-r--r-- 1 root root 1530 May 21 01:34 yaml_facts.rb
2、配置MCollective的facter插件
[root@agent1 ~]# vim /etc/mcollective/server.cfg
# Facts
#factsource = yaml
factsource = facter
plugin.yaml = /etc/mcollective/facts.yaml
3、重新啟動MCollective服務(wù)激活facter
[root@agent1 ~]# /etc/rc.d/init.d/mcollective restart
Shutting down mcollective:
Starting mcollective: [ OK ]
4、測試facter插件
[root@puppetserver ~]# mco facts hostname -v #查看所有節(jié)點的主機名
Discovering hosts using the mc method for 2 second(s) .... 3
Report for fact: hostname
agent1 found 1 times
agent1.rsyslog.org
---- rpc stats ----
Nodes: 3 / 3
Pass / Fail: 3 / 0
Start Time: Sun Aug 25 16:03:36 +0800 2013
Discovery Time: 2003.23ms
Agent Time: 55.57ms
Total Time: 2058.81ms
[root@puppetserver ~]# mco facts operatingsystem -v #查看所有節(jié)點的系統(tǒng)類型
Discovering hosts using the mc method for 2 second(s) .... 3
Report for fact: operatingsystem
RedHat found 1 times
agent1.rsyslog.org
---- rpc stats ----
Nodes: 3 / 3
Pass / Fail: 3 / 0
Start Time: Sun Aug 25 16:03:48 +0800 2013
Discovery Time: 2003.28ms
Agent Time: 92.51ms
Total Time: 2095.79ms
[root@puppetserver ~]# mco facts -v --with-fact hostname='agent1' memoryfree #查看agent1節(jié)點的剩余內(nèi)存
Discovering hosts using the mc method for 2 second(s) .... 1
Report for fact: memoryfree
1.54 GB found 1 times
agent1.rsyslog.org
---- rpc stats ----
Nodes: 1 / 1
Pass / Fail: 1 / 0
Start Time: Sun Aug 25 16:05:15 +0800 2013
Discovery Time: 2001.67ms
Agent Time: 54.73ms
Total Time: 2056.40ms
[root@puppetserver ~]# mco facts -v --with-fact operatingsystem='RedHat' kernelrelease #查看所有節(jié)點系統(tǒng)為RedHat的內(nèi)核版本信息
Discovering hosts using the mc method for 2 second(s) .... 1
Report for fact: kernelrelease
2.6.18-308.el5 found 1 times
agent1.rsyslog.org
---- rpc stats ----
Nodes: 1 / 1
Pass / Fail: 1 / 0
Start Time: Sun Aug 25 16:09:28 +0800 2013
Discovery Time: 2003.23ms
Agent Time: 53.57ms
Total Time: 2056.80ms
operatingsystemrelease
**********************************************************************************
附加測試:部署多個節(jié)點一起測試
1、運行所有系統(tǒng)為RedHat,版本為6的所有節(jié)點puppetd服務(wù)
[root@puppetserver rhel5]# mco puppet -v runonce rpc --np -F lsbmajdistrelease='6' -F operatingsystem='RedHat'
Discovering hosts using the mc method for 2 second(s) .... 1
agent3.rsyslog.org : OK
{:summary=> "Started a background Puppet run using the 'puppet agent --onetime --daemonize --color=false --splay --splaylimit 30' command"}
---- rpc stats ----
Nodes: 1 / 1
Pass / Fail: 1 / 0
Start Time: Sun Aug 25 18:39:23 +0800 2013
Discovery Time: 2003.41ms
Agent Time: 1353.21ms
Total Time: 3356.62ms
2、運行所有系統(tǒng)為RedHat,kernel版本為2.6.18的所有節(jié)點puppetd服務(wù)
[root@puppetserver rhel5]# mco puppet -v runonce rpc --np -F kernelversion='2.6.18' - -F operatingsystem='RedHat'
Discovering hosts using the mc method for 2 second(s) .... 2
agent2.rsyslog.org : OK
{:summary=> "Started a background Puppet run using the 'puppet agent --onetime --daemonize --color=false --splay --splaylimit 30' command"}
agent1.rsyslog.org : OK
{:summary=> "Started a background Puppet run using the 'puppet agent --onetime --daemonize --color=false --splay --splaylimit 30' command"}
---- rpc stats ----
Nodes: 2 / 2
Pass / Fail: 2 / 0
Start Time: Sun Aug 25 18:44:58 +0800 2013
Discovery Time: 2003.31ms
Agent Time: 1470.12ms
Total Time: 3473.43ms
更多博文請參看自動化運維模塊:http://dreamfire.blog.51cto.com/418026/d-27
MCollective結(jié)合自定義facter對puppet節(jié)點進行分類觸發(fā)操作
http://dreamfire.blog.51cto.com/418026/1282725