一.mco构架简介:

puppet-node ( mco server + 各种插件 ) 【受控端】  <-----  activemq(消息列队)【中间件】  <------ puppet-master ( mco client + 各件插件 )【主控端】

mco client 通过中间件,对mco server发送控制消息,可远程批量并发执行各种操作(每种类型操作需要安装相应的插件,例如执行 shell 命令,需要安装shell 插件)

二. 环境预览:

1. mco server 安装在所有puppet node 节点服务器上,需要安装的软件包有:

yum install mcollective mcollective-common

2. mco client 安装在puppet master 服务器上,需要安装的软件包有:

yum install mcollective-client mcollective-common

3. 中间件,可用单独服务器安装,为了节省资源,安装在puppet master服务器上,需要安装的软件包有:

yum install tanukiwrapper activemq activemq-info-provider

4. mco插件: server 与 clinet 皆要安装

yum install mcollective-* #linux上安装所有puppet官方提供的mco插件,windows上安装插件后面文档会专门讲述

三.安装及配置:

1.配置puppet官方yum源

rhel 6:

rpm -Uvh http://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-10.noarch.rpm

rhel 5:

rpm -Uvh http://yum.puppetlabs.com/el/5/products/x86_64/puppetlabs-release-5-10.noarch.rpm

2. puppet master 上的操作:

2.1.安装中间件activemq

yum install tanukiwrapper activemq activemq-info-provider

2.2配置activemq:  (注意下列红色字体标出部份)

[root@puppetmaster]# vim /etc/activemq/activemq.xml
<simpleAuthenticationPlugin>
<users>
<!-- <authenticationUser username="${activemq.username}" password="${activemq.password}" groups="admins,everyone"/> --> #禁用
 <authenticationUser username="mcollective" password="password" 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>

2.3 启动ActiveMQ

[root@puppetmaster]# /etc/rc.d/init.d/activemq start
Starting ActiveMQ Broker...
[root@puppetmaster]# chkconfig activemq on
[root@puppemaster]# netstat -nlatp | grep 61613 #查看监听端口
tcp 0 0 :::61613 :::* LISTEN 33805/java

备注:更多详细配置信息请参考 http://docs.puppetlabs.com/mcollective/reference/plugins/connector_activemq.html


2.4 安装配置 mco控制端mco client

安装mco client: 

 yum install mcollective-client mcollective-common

配置mco控制端: 

[root@puppet ~]# cat /etc/mcollective/client.cfg  

main_collective = mcollective 

collectives = mcollective 

libdir = /usr/libexec/mcollective 

logger_type = console 

loglevel = warn 


# Plugins 

securityprovider = psk 

plugin.psk = password  #设置通信密码与mco server端保持一致

connector = activemq 


connector = activemq 

plugin.activemq.pool.size = 1 

plugin.activemq.pool.1.host = 192.168.xx.xx #中间件服务器IP 或者主机名

plugin.activemq.pool.1.port = 61613          #中间件服务器端口

plugin.activemq.pool.1.user = mcollective    #与中间件的连接用户 与activemq中配置保持一致

plugin.activemq.pool.1.password = password    #与中间件的连接密码 与activemq中配置保持一致


# Facts 

factsource = yaml 

plugin.yaml = /etc/mcollective/facts.yaml 

3. puppet node 节点上的操作

3.1:linux 上安装配置mco server 

安装:

yum install mcollective mcollective-common


配置:

[root@puppetnode]# cat /etc/mcollective/server.cfg 

main_collective = mcollective

collectives = mcollective
libdir = /usr/libexec/mcollective
logfile = /var/log/mcollective.log
loglevel = info
daemonize = 1

# Plugins
securityprovider = psk
plugin.psk = password #设置通信密码 与mco client保持一致
connector = activemq
plugin.activemq.pool.size = 1
plugin.activemq.pool.1.host = 192.168.xx.xx #中间件服务器IP 或者主机名
plugin.activemq.pool.1.port = 61613  #中间件服务器端口
plugin.activemq.pool.1.user = mcollective  #与中间件的连接用户 与activemq中配置保持一致
plugin.activemq.pool.1.password = password #与中间件的连接密码 与activemq中配置保持一致
# Facts
factsource = yaml
plugin.yaml = /etc/mcollective/facts.yaml
启动mco server服务
/etc/init.d/mcollective start
chkconfig mcollective on


3.2 windows上安装mco server
需要先安装好puppet clinet,可到以下网站下载最新版进行安装或升级安装:https://downloads.puppetlabs.com/windows/
3.2.1:准备环境变量:
PATH中确保包含puppet和ruby的运行路径:
C:\Program Files (x86)\Puppet Labs\Puppet\bin;C:\Program Files (x86)\Puppet Labs\Puppet\sys\ruby\bin
RUBYLIB:新建该变量,包含puppet facter ruby 的lib路径:
C:\Program Files (x86)\Puppet Labs\Puppet\puppet\lib;C:\Program Files (x86)\Puppet Labs\Puppet\facter\lib;C:\Program Files (x86)\Puppet Labs\Puppet\sys\ruby\lib

3.2.2:下载windows安装包:http://repos.mornati.net/mcollective/2.3.2/mcollective_2_3_2_Setup.exe
安装后会安装一个服务,名为:The Marionette Collective
配置文件内容和linux上是一样的:
more C:\mcollective\etc\server.cfg
main_collective = mcollective
collectives = mcollective
libdir = C:\mcollective\plugins
logfile = C:\mcollective\mcollective.log
loglevel = info
daemonize = 1

# Plugins
securityprovider = psk
plugin.psk = password
connector = activemq
plugin.activemq.pool.size = 1
plugin.activemq.pool.1.host = 192.168.xx.xx
plugin.activemq.pool.1.port = 61613
plugin.activemq.pool.1.user = mcollective
plugin.activemq.pool.1.password = password
#为了安装puppet agent插件,加入以下配置,否则执行 mco puppet runonce 推送时会出现invalid byte sequence in US-ASCII 报错
plugin.puppet.command = "C:\Program Files (x86)\Puppet Labs\Puppet\bin\puppet.bat" agent
plugin.puppet.config = C:\ProgramData\PuppetLabs\puppet\etc\puppet.conf

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

#启动 the marionette collective服务即可
若有问题可查看日志: C:\mcollective\mcollective.log
【附:相关报错日志说明在文档最后】

4.测试连接:
在mco 控制端运行:
mco find 或 mco ping 即可列出在线的所有server节点:
[root@puppet ~]# mco find
xxx-db-1.xxx.it
SZ-WEB-111
SZ-WEB-112
xxx-db-1.xxx.it
xxx-mem-1.xxx.it
[root@puppet ~]# mco ping
xxx-db-1.xxx.it time=75.80 ms
SZ-WEB-112 time=78.71 ms
xxx-mem-1.xxx.it time=81.74 ms
SZ-WEB-111 time=82.40 ms
xxx-db-2.xxx.it time=83.12 ms
---- ping statistics ----
5 replies max: 83.12 min: 75.80 avg: 80.35
至此mco框架安装结束。


四.安装插件:

mco框架安装好后,还需要安装相应的插件,才能对节点做相关的管理工作,接下来安装一些常用插件

1.linux上安装常用插件(puppet官方有提供rpm包,可直接yum安装)

常用的puppet官方皆已经提供直接yum install 就可以了, 下面安装puppet插件,以便使用mco来调用puppet:

#server端和clinet端都需要安装:

yum install mcollective-puppet-agent.noarch 

安装成功后验证:

主控端clent:

mco 直接回车,便会列出已经可用的插件命令:

[root@puppet ~]# mco  

The Marionette Collective version 2.5.2 


usage: /usr/bin/mco command <options> 


Known commands: 


   completion   facts       find                 

   help         inventory   ping                 

   plugin       puppet      rpc                  

   service      shell                                     

Type '/usr/bin/mco help' for a detailed list of commands and '/usr/bin/mco help command' 


Type '/usr/bin/mco help' for a detailed list of commands and '/usr/bin/mco help command' 

检查受控端server安装的插件:

mco  inventory  host_name

[root@puppet ~]# mco inventory xxx-db-1.xxx.it
Inventory for xxx-db-1.xxx.it:

Server Statistics:
Version: 2.5.3
Start Time: Mon Jul 21 18:14:14 +0800 2014
Config File: /etc/mcollective/server.cfg
Collectives: mcollective
Main Collective: mcollective
Process ID: 4003
Total Messages: 37
Messages Passed Filters: 37
Messages Filtered: 0
Expired Messages: 0
Replies Sent: 36
Total Processor Time: 30.05 seconds
System Time: 65.83 seconds

Agents:
discovery filemgr nrpe 
package puppet rpcutil 
service shell
package puppet rpcutil
service shell



2.linux上安装其它插件(不能直接通过yum安装的插件):
这里用shell插件做示例:
shell 插件:可以在节点上执行shell命令
下载插件:
git clone https://github.com/cegeka/mcollective-shell-agent.git
下载后得到一个mcollective-plugins目录:
cline控制端:
cp mcollective-plugins/mcollective-client/agent/shell.* /usr/libexec/mcollective/mcollective/agent/
cp mcollective-plugins/mcollective-client/application/shell.* /usr/libexec/mcollective/mcollective/application/
 
   

server受控端:
cp mcollective-plugins/mcollective-server/agent/shell.* /usr/libexec/mcollective/mcollective/agent/
/etc/init.d/mcollective restart
至此linux shell插件完成安装。

 
  

3.windows上安装puppet插件
再集中列举一下windows下的安装包下载路径:
1.puppet安装包:https://downloads.puppetlabs.com/windows/ #本文用的版本是: 3.6.2
2.mocllective server安装包:http://repos.mornati.net/mcollective/ #本文用的版本是:2.3.2
3.mco puppet agent 插件:https://github.com/puppetlabs/mcollective-puppet-agent/releases #本文用的版本是:1.7.2

先下载mco puppet agent 插件:进入网站选择最新版(目前是1.7.2),下载下来是个压缩文件。解压文件后里面一共有以下文件件:

DD88878CAB724B9EBE96488880F2C9F3+

将 agent 和 util 中的文件复制到 C:\mcollective\plugins\mcollective\ 对应的目录下(注:为了保险起见,只要

C:\mcollective\plugins\mcollective\ 下存在的目录,我都拷了进去)

),再重启mco服务即可:

C:\mcollective\plugins\mcollective\ 看起来是这个样子的:

2B272918BCDE4535B525B0EA48DC2D89


【附:注意事项】
1.确保以下两个环境变量存在:
PATH中确保包含puppet和ruby的运行路径:否则将无法安装注册mco server 服务
C:\Program Files (x86)\Puppet Labs\Puppet\bin;C:\Program Files (x86)\Puppet Labs\Puppet\sys\ruby\bin
RUBYLIB:新建该变量,包含puppet facter ruby 的lib路径:否则在安装puppet agent插件时mco 启动会出现以下报错,而无法加载puppet插件
ERROR -- : agents.rb:71:in `rescue in loadagent' Loading agent puppet failed: Could not create instance of plugin MCollective::Agent::Puppet: cannot load such file -- puppet
C:\Program Files (x86)\Puppet Labs\Puppet\puppet\lib;C:\Program Files (x86)\Puppet Labs\Puppet\facter\lib;C:\Program Files (x86)\Puppet Labs\Puppet\sys\ruby\lib


2.确保C:\mcollective\etc\server.cfg 中加入以下两条配置:

#安装puppet agent插件必须加入以下配置,否则执行 mco puppet runonce 推送时会出现invalid byte sequence in US-ASCII 报错
plugin.puppet.command = "C:\Program Files (x86)\Puppet Labs\Puppet\bin\puppet.bat" agent
plugin.puppet.config = C:\ProgramData\PuppetLabs\puppet\etc\puppet.conf

PF大神提供分享:

http://note.youdao.com/share/?id=726e6fc94f4df3309be77f84852f2a40&type=note