bobpxp 发表于 2018-8-3 06:02:19

通过部署MCollective+ActiveMQ模块更安全高效的触发puppet更新

  如果需要交流puppet 可加入puppet技术交流QQ群296934942
  实验环境:
  puppetserver.rsyslog.org
  MCollective客户端+ACtiveMQ服务端+Puppet服务端
  agent1.rsyslog.org
  MCollective服务端+Puppet客户端
  应用:apache
  agent2.rsyslog.org
  MCollective服务端+Puppet客户端
  应用:apache+mysql
  agent3.rsyslog.org
  MCollective服务端+Puppet客户端
  应用:php
  实验步骤:
  一、在Puppetserver端部署RabbitMQ
  1、安装ACtiveMQ
  # yum install tanukiwrapper activemq activemq-info-provider
  2、配置ActiveMQ
  <simpleAuthenticationPlugin>
  <users>
  <authenticationUser username=&quot;admin&quot; password=&quot;123.com&quot; groups=&quot;mcollective,admins,everyone&quot;/>
  <authenticationUser username=&quot;mcollective&quot; password=&quot;secret&quot; groups=&quot;mcollective,admins,everyone&quot;/>
  </users>
  </simpleAuthenticationPlugin>
  <transportConnectors>
  <transportConnector name=&quot;openwire&quot; uri=&quot;tcp://0.0.0.0:61616&quot;/>
  <!--            <transportConnector name=&quot;stomp+nio&quot; uri=&quot;stomp+nio://0.0.0.0:61613&quot;/> -->
  <transportConnector name=&quot;stomp&quot; uri=&quot;stomp://0.0.0.0:61613&quot;/>
  </transportConnectors>
  3、启动ActiveMQ
  # /etc/rc.d/init.d/activemq restart
  Stopping ActiveMQ Broker...
  ActiveMQ Broker was not running.
  Starting ActiveMQ Broker...
  # chkconfig activemq on
  # netstat -nlatp | grep 61613
  tcp      0      0 :::61613                  :::*                        LISTEN      3098/java
  二、在Puppetserver端部署MCollective客户端
  1、安装stomp gem包(也可以通过yum安装rubygem-stomp包)
  # 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客户端
  # yum install mcollective-commonmcollective-client
  3、配置Mcollective连接ACtiveMQ
  # 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
  三、在所有节点上部署MCollective服务端
  1、安装stomp gem包
  # 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服务端
  # yum install mcollectivemcollective-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服务端连接到ACtiveMQ
  # 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
  # /etc/rc.d/init.d/mcollective restart
  Shutting down mcollective:
  Starting mcollective:                                    
  四、测试MCollective通讯是否正常
  # 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
  # mco ping#测试和MC服务器端通讯是否正常
  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
  # mco inventory agent1.rsyslog.org#查看某一个MC服务器端MC的相关信息
  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>  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>
  No>  Facts:
  mcollective => 1
  # mco rpc rpcutil agent_inventory -I agent1.rsyslog.org
  * [ ============================================================> ] 1 / 1
  agent1.rsyslog.org
  Agents: [{:author=>&quot;R.I.Pienaar <rip@devco.net>&quot;,
  :agent=>&quot;discovery&quot;,
  :version=>&quot;2.2.4&quot;,
  :license=>&quot;Apache License, Version 2&quot;,
  :name=>&quot;Discovery Agent&quot;,
  :timeout=>5,
  :description=>&quot;MCollective Discovery Agent&quot;,
  :url=>&quot;http://www.marionette-collective.org&quot;},
  {:author=>&quot;R.I.Pienaar <rip@devco.net>&quot;,
  :agent=>&quot;rpcutil&quot;,
  :version=>&quot;1.0&quot;,
  :license=>&quot;Apache License, Version 2.0&quot;,
  :name=>&quot;rpcutil&quot;,
  :timeout=>10,
  :description=>
  &quot;General helpful actions that expose stats and internals to SimpleRPC clients&quot;,
  :url=>&quot;http://marionette-collective.org/&quot;}]
  Finished processing 1 / 1 hosts in 87.23 ms
  # mco help inventory#查看某一个命令下的参数
  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>  --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>
  -S, --select FILTER            Compound filter combining facts and>  -F, --wf, --with-fact fact=val   Match hosts with a certain fact

  -C, --wc, --with-class>  -A, --wa, --with-agent AGENT   Match hosts with a certain agent

  -I, --wi, --with-identity>  The Marionette Collective 2.2.4
  五、部署MCollective-puppet插件
  1、安装puppet插件
  ## yum install mcollective-package-agent mcollective-package-common
  # yum install mcollective-puppet-agent mcollective-puppet-common
  ## yum install mcollective-package-client mcollective-package-common
  # yum install mcollective-puppet-client mcollective-puppet-common
  2、载入agent插件

  # /etc/rc.d/init.d/mcollective>  Reloading mcollective agents:                              
  3、查看插件是否载入成功
  # 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>  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         #插件已经载入
  rpcutil
  Data Plugins:
  agent         fstat         puppet
  resource

  Configuration Management>
  No>  Facts:
  mcollective => 1
  4、从MCollective中运行puppet进行测试(触发节点agent运行一次)
  注意:所有节点puppetd服务必须关闭
  # mco puppet -v runonce   #失败运行的结果
  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
  # mco puppet -v runonce #成功运行的结果
  Discovering hosts using the mc method for 2 second(s) .... 1
  * [ ============================================================> ] 1 / 1
  agent1.rsyslog.org                     : OK#成功启动了节点的puppetd进程
  {:summary=>      &quot;Started a background Puppet run using the 'puppet agent --onetime --daemonize --color=false --splay --splaylimit 30' command&quot;}
  ---- 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
  # tailf /var/log/messages   #查看同步情况
  # watch -d /etc/rc.d/init.d/puppet status#查看节点puppet服务变化情况
  六、部署MCollective-facter插件
  1、安装facter插件
  # yum install mcollective-facter-facts
  # ll /usr/libexec/mcollective/mcollective/facts/
  total 24
  -rw-r--r-- 1 root root422 Feb 212013 facter_facts.ddl
  -rw-r--r-- 1 root root945 Feb 212013 facter_facts.rb
  -rw-r--r-- 1 root root 1530 May 21 01:34 yaml_facts.rb
  2、配置MCollective的facter插件
  # vim /etc/mcollective/server.cfg
  # Facts
  #factsource = yaml
  factsource = facter
  plugin.yaml = /etc/mcollective/facts.yaml
  3、重新启动MCollective服务激活facter
  # /etc/rc.d/init.d/mcollective restart
  Shutting down mcollective:
  Starting mcollective:                                    
  4、测试facter插件
  # mco facts hostname -v#查看所有节点的主机名
  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
  # mco facts operatingsystem -v   #查看所有节点的系统类型
  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
  # mco facts -v --with-fact hostname='agent1' memoryfree#查看agent1节点的剩余内存
  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
  # mco facts -v --with-factoperatingsystem='RedHat' kernelrelease#查看所有节点系统为RedHat的内核版本信息
  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
  **********************************************************************************
  附加测试:部署多个节点一起测试
  1、运行所有系统为RedHat,版本为6的所有节点puppetd服务
  # mco puppet -v runonce   rpc --np -Flsbmajdistrelease='6' -F operatingsystem='RedHat'
  Discovering hosts using the mc method for 2 second(s) .... 1
  agent3.rsyslog.org                     : OK
  {:summary=>      &quot;Started a background Puppet run using the 'puppet agent --onetime --daemonize --color=false --splay --splaylimit 30' command&quot;}
  ---- 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、运行所有系统为RedHat,kernel版本为2.6.18的所有节点puppetd服务
  # mco puppet -v runonce   rpc --np -Fkernelversion='2.6.18'- -F operatingsystem='RedHat'
  Discovering hosts using the mc method for 2 second(s) .... 2
  agent2.rsyslog.org                     : OK
  {:summary=>      &quot;Started a background Puppet run using the 'puppet agent --onetime --daemonize --color=false --splay --splaylimit 30' command&quot;}
  agent1.rsyslog.org                     : OK
  {:summary=>      &quot;Started a background Puppet run using the 'puppet agent --onetime --daemonize --color=false --splay --splaylimit 30' command&quot;}
  ---- 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结合自定义facter对puppet节点进行分类触发操作
  http://dreamfire.blog.51cto.com/418026/1282725
页: [1]
查看完整版本: 通过部署MCollective+ActiveMQ模块更安全高效的触发puppet更新