puppet在比较老的版本的时候是通过kick进行推送实现配置及时更新,由于kick的效率问题,在比较新的版本中开始采用第三方工具MCollective来实现,网上介绍如何部署MCollective文章也不少,但大都是linux平台下的部署,windows下的几乎没有,我在研究的时候也是一路坎坷,差点放弃,不过看到有一个老外自己成功部署后,有点不甘心,在坚持下终于配置成功,现在整理一下分享出来。

如果你还一点都不了解MCollective,建议看看这篇文章,他讲的是在linux下部署MCollective,其中讲了各个工具的关系,其实流程都一样,只不过我这里讲的是windows客户端的部署。

=========================================================================================

以下每个用到的工具我都有写明自己部署时候的版本号,如果你部署完成后无法正常实现推送,可以重新指定安装每个工具的版本

1、首先配置好puppet server和puppet client,这个很容易实现,就不详细说明了,我用到版本分别是

      puppet server(centos 6.2): 3.4.3

      puppet client(windows 2008 r2):    3.4.3

2、安装一款 消息队列服务,你可以选择RabbitMQ或者ActiveMQ,我这里选择的是ActiveMQ,ActiveMQ是装在puppet server端,使用如下命令进行安装,

当前ActiveMQ版本号为:5.8.0

yum install tanukiwrapper activemq activemq-info-provider

安装完成后来对ActiveMQ进行配置,如下

[root@puppetserver rpms]# vim /etc/activemq/activemq.xml
…
<simpleAuthenticationPlugin>
            <users>
<!--              <authenticationUser username="${activemq.username}" password="${activemq.password}" groups="admins,everyone"/> --> #禁用
              <authenticationUser username="mcollective" password="secret" groups="mcollective,admins,everyone"/>  #配置通信的账号及密码
            </users>
          </simpleAuthenticationPlugin><authorizationPlugin>  #配置权限,默认即可
            <map>
              <authorizationMap>
                <authorizationEntries>
                  <authorizationEntry queue=">" write="admins" read="admins" admin="admins" />
                  <authorizationEntry topic=">" write="admins" read="admins" admin="admins" />
                  <authorizationEntry topic="mcollective.>" write="mcollective" read="mcollective" admin="mcollective" />
                  <authorizationEntry topic="mcollective.>" write="mcollective" read="mcollective" admin="mcollective" />
                  <authorizationEntry topic="ActiveMQ.Advisory.>" read="everyone" write="everyone" admin="everyone"/>
                </authorizationEntries>
              </authorizationMap>
            </map>
          </authorizationPlugin><transportConnectors>
            <transportConnector name="openwire" uri="tcp://0.0.0.0:61616"/>
            <transportConnector name="stomp+nio" uri="stomp://0.0.0.0:61613"/> #配置通信协议为stomp,监听61613端口
        </transportConnectors>

然后启动ActiveMQ

[root@puppetserver rpms]# service activemq start
Starting ActiveMQ Broker...
[root@puppetserver rpms]# chkconfig activemq on
[root@puppetserver rpms]# netstat -nlatp | grep 61613  #查看监听端口
tcp        0      0 :::61613                    :::*                        LISTEN      33805/java 

3、现在开始配置MCollective,MCollective也分为客户端和服务器端,其客户端是装在puppetserver上,服务器端是装下puppetclient,我们先配置客户端,也就是puppetserver上的环境,命令如下,当前mcollective客户端版本是2.5.0:

[root@puppetserver rpms]# yum install mcollective-common  mcollective-client 

然后配置mcollective客户端:

[root@puppetserver rpms]# vim /etc/mcollective/client.cfg
main_collective = mcollective
collectives = mcollective
libdir = /usr/libexec/mcollective
logger_type = console
loglevel = warn

# Plugins
securityprovider = psk
plugin.psk = test123123  #MCollective通信共享密钥,和MCollective服务端保持一致

connector = activemq  #MCollective用到的通讯组件
plugin.activemq.pool.size = 1
plugin.activemq.pool.1.host = 192.168.3.91 #本机ip
plugin.activemq.pool.1.port = 61613  #AcitveMQ中设置的端口号
plugin.activemq.pool.1.user = mcollective #AcitveMQ中设置的用户
plugin.activemq.pool.1.password = secret  #AcitveMQ中设置的密码
plugin.activemq.heartbeat_interval = 30  


# Facts
factsource = yaml
plugin.yaml = /etc/mcollective/facts.yaml

 

接下来是个需要注意的地方,mcollective本身并没有相应的windows服务端安装包,在windows下安装mcollective是一件麻烦的事情,不过有大神做了mcollective安装程序,它集成了mcollective运行所需要的一个gem包,以及将mcollective安装成windows服务,点击这里下载安装包,我下载的是2.3.2版本,下载后在puppet client端安装,安装完成后windows服务里会有一个服务名:The Marionette Collective。

注意安装前检查如下环境变量,安装的时候才用右键管理员运行程序包

Path变量是否包含 D:\Puppet Labs\Puppet\sys\ruby\bin;D:\Puppet Labs\Puppet\bin

然后配置mcollective服务端server.cfg,我的目录是D:\mcollective\etc下:

main_collective = mcollective
collectives = mcollective
libdir = d:\mcollective\plugins  #mcollective插件目录
logfile = d:\mcollective\mcollective.log  #mcollective日志
loglevel = info
daemonize = 1

# Plugins
securityprovider = psk
plugin.psk = test123123

connector = activemq
plugin.activemq.pool.size = 1
plugin.activemq.pool.1.host = 192.168.3.91
plugin.activemq.pool.1.port = 61613
plugin.activemq.pool.1.user = mcollective
plugin.activemq.pool.1.password = secret
plugin.activemq.pool.1.heartbeat_interval = 30


# Facts
factsource = yaml
plugin.yaml = d:\mcollective\etc\facts.yaml

完成后在puppetclient上启动mcollective服务,此时mcollective的服务端和客户端配置就已经成功,可以在puppetserver上测试mcollective的通讯是否正常,如下

[root@puppetserver mcollective]# mco ping
waiwofei                                 time=42.00 ms
WIN-6BJIEV6N3T6                          time=80.98 ms
WIN-3JOT1GVGEOO                          time=89.42 ms


---- ping statistics ----
3 replies max: 89.42 min: 42.00 avg: 70.80

4、为mcollective安装puppet agent插件,首先在puppet server端安装,当前版本是1.7.1

yum install mcollective-puppet-client mcollective-puppet-common

接着要在puppet client安装,如果是linux可以通过命令向上面那样直接安装,window的话我们只能下载插件包,然后把相关文件复制到mcollective插件目录,通过下面地址下载,我最初下载的是1.7.1版本,但是在mcollective启动的时候无法正常加载puppet agent插件,后来换成1.6.1就没问题了,版本的问题困扰了我很久,几乎要放弃了,但是看到某个老外配置成功,发现帖子的时间是2013年6月份,我就索性把插件版本降到比较老,结果正常了。好了,通过下面下载

https://github.com/puppetlabs/mcollective-puppet-agent/releases

解压后将里面的文件夹复制到mcollective的插件目录,我的插件目录[d:\mcollective\plugins],接着再次配置puppet client端mcollective的server.cfg,增加如下两行,这个插件的配置写法也卡住了我很久,说多了都是泪啊。。。。

main_collective = mcollective
collectives = mcollective
libdir = d:\mcollective\plugins  
logfile = d:\mcollective\mcollective.log  
loglevel = info
daemonize = 1

# Plugins
securityprovider = psk
plugin.psk = test123123

connector = activemq
plugin.activemq.pool.size = 1
plugin.activemq.pool.1.host = 192.168.3.91
plugin.activemq.pool.1.port = 61613
plugin.activemq.pool.1.user = mcollective
plugin.activemq.pool.1.password = secret
plugin.activemq.pool.1.heartbeat_interval = 30

plugin.puppet.command = "D:\Puppet Labs\Puppet\bin\puppet.bat" agent
plugin.puppet.config = C:\ProgramData\PuppetLabs\puppet\etc\puppet.conf

# Facts
factsource = yaml
plugin.yaml = d:\mcollective\etc\facts.yaml

 

ok,重启puppet client端mcollective服务,可以在puppet server通过下面的命令查看puppet client的插件的加载情况。

[root@puppetserver mcollective]# mco inventory waiwofei
Inventory for waiwofei:

   Server Statistics:
                      Version: 2.3.2
                   Start Time: Mon Apr 28 17:24:51 +0800 2014
                  Config File: D:\mcollective\etc\server.cfg
                  Collectives: mcollective
              Main Collective: mcollective
                   Process ID: 73044
               Total Messages: 4
      Messages Passed Filters: 4
            Messages Filtered: 0
             Expired Messages: 0
                 Replies Sent: 3
         Total Processor Time: 1.014 seconds
                  System Time: 0.39 seconds

   Agents:
      discovery       puppet          rpcutil

   Data Plugins:
      agent           fstat           puppet
      resource

   Configuration Management Classes:
      No classes applied

   Facts:
      mcollective => 1

注意,如果你重启不了或者puppet插件正常加载(也可以通过mcollective.log查看加载是否有错误),那么你需要检查下你的环境变量

RUBYLIB是否存在以及包含 D:\Puppet Labs\Puppet\puppet\lib;D:\Puppet Labs\Puppet\facter\lib

整个配置过程结束,在puppetserver上进行一次推送试试吧

[root@puppetserver mcollective]# mco puppet -v -I waiwofei runonce

 * [ ============================================================> ] 1 / 1


waiwofei                                : OK
    {:summary=>      "Started a background Puppet run using the '\"D:\\Puppet Labs\\Puppet\\bin\\puppet.bat\" agent --onetime --color=false --splay --splaylimit 30' command"}



---- rpc stats ----
           Nodes: 1 / 1
     Pass / Fail: 1 / 0
      Start Time: Tue Apr 29 10:36:58 +0800 2014
  Discovery Time: 0.00ms
      Agent Time: 50.93ms
      Total Time: 50.93ms

 

运行成功,通过puppet dashboard也可以看到运行成功

posted on 2014-04-29 10:33  慕 林  阅读(2044)  评论(1编辑  收藏  举报