mcollective安裝文檔

一.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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章