一.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-common2. mco client 安装在puppet master 服务器上,需要安装的软件包有:
yum install mcollective-client mcollective-common3. 中间件,可用单独服务器安装,为了节省资源,安装在puppet master服务器上,需要安装的软件包有:
yum install tanukiwrapper activemq activemq-info-provider4. 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-provider2.2配置activemq: (注意下列红色字体标出部份)
[root@puppetmaster]# vim /etc/activemq/activemq.xml…
#禁用
#配置通信的账号及密码
…
#配置权限,默认即可
…
#配置通信协议为stomp,监听61613端口 …2.3 启动ActiveMQ
[root@puppetmaster]# /etc/rc.d/init.d/activemq startStarting 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 = mcollectivelibdir = /usr/libexec/mcollectivelogfile = /var/log/mcollective.logloglevel = infodaemonize = 1
# Pluginssecurityprovider = pskplugin.psk = password #设置通信密码 与mco client保持一致connector = activemqplugin.activemq.pool.size = 1plugin.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中配置保持一致# Factsfactsource = yamlplugin.yaml = /etc/mcollective/facts.yaml启动mco server服务/etc/init.d/mcollective startchkconfig 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\binRUBYLIB:新建该变量,包含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.cfgmain_collective = mcollectivecollectives = mcollectivelibdir = C:\mcollective\pluginslogfile = C:\mcollective\mcollective.logloglevel = infodaemonize = 1
# Pluginssecurityprovider = pskplugin.psk = passwordconnector = activemqplugin.activemq.pool.size = 1plugin.activemq.pool.1.host = 192.168.xx.xxplugin.activemq.pool.1.port = 61613plugin.activemq.pool.1.user = mcollectiveplugin.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" agentplugin.puppet.config = C:\ProgramData\PuppetLabs\puppet\etc\puppet.conf
# Factsfactsource = yamlplugin.yaml = C:\mcollective\etc\facts.yaml
#启动 the marionette collective服务即可若有问题可查看日志: C:\mcollective\mcollective.log【附:相关报错日志说明在文档最后】
4.测试连接:
在mco 控制端运行:mco find 或 mco ping 即可列出在线的所有server节点:[root@puppet ~]# mco findxxx-db-1.xxx.itSZ-WEB-111SZ-WEB-112xxx-db-1.xxx.itxxx-mem-1.xxx.it[root@puppet ~]# mco pingxxx-db-1.xxx.it time=75.80 msSZ-WEB-112 time=78.71 msxxx-mem-1.xxx.it time=81.74 msSZ-WEB-111 time=82.40 msxxx-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
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.itInventory for xxx-db-1.xxx.it:
Server Statistics:Version: 2.5.3Start Time: Mon Jul 21 18:14:14 +0800 2014Config File: /etc/mcollective/server.cfgCollectives: mcollectiveMain Collective: mcollectiveProcess ID: 4003Total Messages: 37Messages Passed Filters: 37Messages Filtered: 0Expired Messages: 0Replies Sent: 36Total Processor Time: 30.05 secondsSystem Time: 65.83 seconds
Agents:discovery filemgr nrpe
package puppet rpcutil
service shellpackage puppet rpcutilservice 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.22.mocllective server安装包:http://repos.mornati.net/mcollective/ #本文用的版本是:2.3.23.mco puppet agent 插件:https://github.com/puppetlabs/mcollective-puppet-agent/releases #本文用的版本是:1.7.2先下载mco puppet agent 插件:进入网站选择最新版(目前是1.7.2),下载下来是个压缩文件。解压文件后里面一共有以下文件件:
将 agent 和 util 中的文件复制到 C:\mcollective\plugins\mcollective\ 对应的目录下(注:为了保险起见,只要
C:\mcollective\plugins\mcollective\ 下存在的目录,我都拷了进去)),再重启mco服务即可:
C:\mcollective\plugins\mcollective\ 看起来是这个样子的:
【附:注意事项】1.确保以下两个环境变量存在:PATH中确保包含puppet和ruby的运行路径:否则将无法安装注册mco server 服务C:\Program Files (x86)\Puppet Labs\Puppet\bin;C:\Program Files (x86)\Puppet Labs\Puppet\sys\ruby\binRUBYLIB:新建该变量,包含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 -- puppetC:\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" agentplugin.puppet.config = C:\ProgramData\PuppetLabs\puppet\etc\puppet.conf
PF大神提供分享:
http://note.youdao.com/share/?id=726e6fc94f4df3309be77f84852f2a40&type=note