1.puppet agent 调度方式

      后台进程: 这种方式就是通过服务脚本来控制,也可以手动运行 puppet agent ,加上 –no-daemonize 这个参数即可保持在前台,以交互的方式运行。
      cron: 定义系统自带的周期性任务来运行 puppet agent。
      mcollective:这种方式是采用中心调度式,从控制端发出指令到被控制端执行相应的操作,puppet agent 只是这些操作之一。
mcollective 与前两种方式的差别在于 mcollective 更主动,前两种方式都是隔一段时间运行一次,而不管配置是否需要发生变更,而 mcollectvice 则是在配置需要发生变更时从控制端发出puppet agent 命令到被控制端,这样不会浪费系统资源,而且在需要的时候能立即发生变更。

2.mcollective 消息流程

121536272.png

1)client 是控制端,从 client 发出指令,如 puppet agent

2)client 发出指令后, middleware 接收到指令,将这些指令广播到各个节点,这些节点一般称为服务器端

3)服务器端接收到指令,同时对照指令中指定的筛选条件,如果符合则执行指令,并将结果返回给中间件

4)中间件将结果返回给 client


3.mcollective安装与配置
实验环境:
puppet-master:172.16.5.200
mcollective client、activemq server、puppet master
puppet-agent:172.16.5.202
mcollective server、puppet agent

配置yum源:
rpm -ivh http://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-6.noarch.rpm

puppet-master:
安装与配置activemq:
yum install -y tanukiwrapper activemq activemq-info-provider
vim /etc/activemq/activemq.xml
<simpleAuthenticationPlugin>
          <users>
<authenticationUser username="admin" password="redhat" groups="mcollective,admins,everyone"/>
<authenticationUser username="mcollective" password="redhat" groups="mcollective,admins,everyone"/>
          </users>
        </simpleAuthenticationPlugin>
      <transportConnectors>
          <transportConnector name="openwire" uri="tcp://0.0.0.0:61616"/>
<!-- <transportConnector name="stomp+nio" uri="stomp+nio://0.0.0.0:61613"/> -->
<transportConnector name="stomp" uri="stomp://0.0.0.0:61613"/>
      </transportConnectors>
service activemq start
spacer.gif 121610120.png

安装与配置mcollective客户端:
yum install mcollective-common mcollective-client -y
gem update --system 1.8.25     #注:yum默认安装的版本过低,如果直接yum update --system,则会直接升级到2.1版本,版本又会过高,无论版本过低时,后面通过gem安装stomp时,也会因为版本过低,而导致mco命令无法执行。版本过高时,gem安装rake时,也会因为版本过高,rake命令无法执行。
gem install stomp   #注:yum默认安装的stomp版本过低
vim /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 = redhat
connector = stomp
plugin.stomp.host = 172.16.5.200
plugin.stomp.port = 61613
plugin.stomp.user = mcollective
plugin.stomp.password = redhat
# Facts
factsource = yaml
plugin.yaml = /etc/mcollective/facts.yaml

puppet agent:
mcollective服务端:
yum install -y mcollective-common mcollective
gem update --system 1.8.25
gem install stomp
vim /etc/mcollective/server.xml
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 = redhat
connector = stomp
plugin.stomp.host = 172.16.5.200
plugin.stomp.port = 61613
plugin.stomp.user = mcollective
plugin.stomp.password = redhat
# Facts
factsource = yaml
plugin.yaml = /etc/mcollective/facts.yaml
servoce mcollective start

测试(在puppet master上执行):
mco ping    #测试与MC服务器端通讯是否正常
mco inventory puppet-agent     #查看MC服务端的MC的相关信息

当执行mco ping时,报如下错误:
/usr/lib/ruby/site_ruby/1.8/rubygems/core_ext/kernel_require.rb:55:in `gem_original_require': no such file to load -- stomp (LoadError)
from /usr/lib/ruby/site_ruby/1.8/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/lib/ruby/site_ruby/1.8/mcollective.rb:2
from /usr/bin/mco:3:in `require'
from /usr/bin/mco:3
解决方法:
gem install stomp

4.部署mcollective-puppet插件

puppet master:
yum install -y mcollective-package-client mcollective-package-common   mcollective-puppet-client mcollective-puppet-common

puppet agent:
yum install mcollective-package-agent mcollective-package-common   mcollective-puppet-agent mcollective-puppet-common
/etc/rc.d/init.d/mcollective reload-agents
执行如下命令查看插件是否已载入:
spacer.gif 121819845.png
spacer.gif 121918125.png


5.部署mcollective-facts插件
puppet agent:
yum install -y mcollective-facter-facts
ll /usr/libexec/mcollective/mcollective/facts/
vim /etc/mcollectvie/server.cfg
spacer.gif 122037433.png
service mcollective restart

在puppet-master上执行 mco facts hostname -v  #查看所有节点的主机名
122151732.png spacer.gif
查看所有节点的系统类型:
spacer.gif 122231561.png
查看test节点的剩余内存:
spacer.gif 122442212.png
查看所有节点系统为OracleLinux的内核版本信息:

 mco facts -v --with-fact  operatingsystem='OracleLinux' kernelrelease

122732973.png

运行所有系统为OracleLinux,版本为6的所有节点puppetd服务:

mco puppet -v runonce   rpc --np -F  lsbmajdistrelease='6' -F operatingsystem='OracleLinux'

123457528.png

运行所有系统为OracleLinux,kernel版本为2.6.18的所有节点puppetd服务:
mco puppet -v runonce   rpc --np -F  kernelversion='2.6.39'  - -F operatingsystem='OracleLinux'

123330856.png




linux交流群:22346652。欢迎Linux爱好者加入,一起学习,一起进步。