rabbitmq+mcollective2.5.3版本测试及部署

之前群里有不少人贴过mcollective新版本安装报错,本人亲自测试,未发现大的问题。 由于时间问题,更多的是步骤,详细安装过程可参考

http://kisspuppet.com/2013/12/24/mcollective_rabbitmq_high_availability/

http://kisspuppet.com/2013/11/10/mcollective-middleware/

测试版本如下:

系统版本                    rhel6.4
puppet-server              3.4.3
puppet                     3.4.3
facter                     2.0.2
rabbitmq-server            3.2.1
mcollective                2.5.3-1
mcollective-puppet-agent   1.9.3-1
mcollective-package-agent  4.3.1-1    
mcollective-service-agent  3.1.3-1

1、安装rabbitmq

#安装包
[root@puppetmaster343 ~]#  yum install erlang 
[root@puppetmaster343 ~]# yum install rabbitmq-server
[root@puppetmaster343 ~]# ln -s /usr/lib/rabbitmq/lib/rabbitmq_server-3.2.1/sbin/rabbitmq-env /usr/sbin/rabbitmq-env
[root@puppetmaster343 ~]# /etc/init.d/rabbitmq-server start
[root@puppetmaster343 ~]# /etc/init.d/rabbitmq-server status
#开启stomp和web管理插件
[root@puppetmaster343 ~]# rabbitmq-plugins enable rabbitmq_stomp rabbitmq_management
#修改默认监听端口为61613
[root@puppetmaster343 ~]# vim /etc/rabbitmq/rabbitmq.config 
[
        {rabbitmq_stomp,[ {tcp_listeners, [61613]} ]}
].
[root@puppetmaster343 ~]# /etc/init.d/rabbitmq-server restart

#查看安装配置是否OK
[root@puppetmaster343 ~]# netstat -nlp | grep beam 
tcp        0      0 0.0.0.0:15672               0.0.0.0:*                   LISTEN      30300/beam          
tcp        0      0 0.0.0.0:55672               0.0.0.0:*                   LISTEN      30300/beam          
tcp        0      0 0.0.0.0:43194               0.0.0.0:*                   LISTEN      30300/beam          
tcp        0      0 :::61613                    :::*                        LISTEN      30300/beam          
tcp        0      0 :::5672                     :::*                        LISTEN      30300/beam     

2、配置rabbitmq-server

#删除默认用户guest
[root@puppetmaster343 ~]# rabbitmqctl delete_user guest
Deleting user "guest" ...
...done.

#添加新用户
[root@puppetmaster343 ~]# rabbitmqctl add_user mc_rabbitmq 123.com
Creating user "mc_rabbitmq" ...
...done.
[root@puppetmaster343 ~]# rabbitmqctl add_user admin password=123.com 
Creating user "admin" ...
...done.
[root@puppetmaster343 ~]# rabbitmqctl add_user web_admin 123.com
Creating user "web_admin" ...
...done.

#设置用户角色
[root@puppetmaster343 ~]# rabbitmqctl set_user_tags admin administrator
Setting tags for user "admin" to [administrator] ...
...done.
[root@puppetmaster343 ~]# rabbitmqctl set_user_tags web_admin monitoring
Setting tags for user "web_admin" to [monitoring] ...
...done.

#创建虚拟主机并设置权限
[root@puppetmaster343 ~]# rabbitmqctl add_vhost /mcollective
Creating vhost "/mcollective" ...
...done.
[root@puppetmaster343 ~]# rabbitmqctl set_permissions -p "/mcollective" mc_rabbitmq  ".*" ".*" ".*"
Setting permissions for user "mc_rabbitmq" in vhost "/mcollective" ...
...done.
[root@puppetmaster343 ~]# rabbitmqctl set_permissions -p "/mcollective" admin  ".*" ".*" ".*"
Setting permissions for user "admin" in vhost "/mcollective" ...
...done.
[root@puppetmaster343 ~]# rabbitmqctl set_permissions -p "/mcollective" web_admin  ".*" ".*" ".*"
Setting permissions for user "web_admin" in vhost "/mcollective" ...
...done.

#使用rabbitmqadmin命令设置exchange路由,也可以登录web进行设置,具体如何操作可参(http://kisspuppet.com/2013/12/24/mcollective_rabbitmq_high_availability/)
[root@puppetmaster343 ~]# wget -P /usr/local/bin  http://localhost:15672/cli/rabbitmqadmin
--2014-12-17 13:55:09--  http://localhost:15672/cli/rabbitmqadmin
Resolving localhost... ::1, 127.0.0.1
Connecting to localhost|::1|:15672... failed: Connection refused.
Connecting to localhost|127.0.0.1|:15672... connected.
HTTP request sent, awaiting response... 200 OK
Length: 32287 (32K) [text/plain]
Saving to: “/usr/local/bin/rabbitmqadmin”
100%[=============================================================>] 32,287      --.-K/s   in 0.007s  
2014-12-17 13:55:09 (4.54 MB/s) - “/usr/local/bin/rabbitmqadmin” saved [32287/32287]
[root@puppetmaster343 ~]#  chmod u+rx /usr/local/bin/rabbitmqadmin
[root@puppetmaster343 ~]# rabbitmqadmin declare exchange --user=web_admin --password=123.com --vhost=/mcollective name=mcollective_directed type=direct
exchange declared
[root@puppetmaster343 ~]# rabbitmqadmin declare exchange --user=web_admin --password=123.com --vhost=/mcollective name=mcollective_broadcast type=topic
exchange declared

#查看并验证设置是否正确
[root@puppetmaster343 ~]# rabbitmqctl list_exchanges -p "/mcollective"
Listing exchanges ...
    direct
amq.direct    direct
amq.fanout    fanout
amq.headers    headers
amq.match    headers
amq.rabbitmq.trace    topic
amq.topic    topic
mcollective_broadcast    topic
mcollective_directed    direct
...done.
[root@puppetmaster343 ~]# rabbitmqctl list_permissions -p "/mcollective"
Listing permissions in vhost "/mcollective" ...
admin    .*    .*    .*
mc_rabbitmq    .*    .*    .*
web_admin    .*    .*    .*
...done.
[root@puppetmaster343 ~]#  rabbitmqctl list_users
Listing users ...
admin    [administrator]
mc_rabbitmq    []
web_admin    [monitoring]
...done.

3、安装mcollective服务端和客户端并测试与MQ的连通性

#安装client端
[root@puppetmaster343 ~]# yum install mcollective-common  mcollective-client
#安装server端
[root@puppetmaster343 ~]# yum install mcollective  mcollective-common
#配置server端
[root@puppetmaster343 ~]# 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 = 7758521
direct_addressing = 1
connector = rabbitmq
plugin.rabbitmq.vhost = /mcollective
plugin.rabbitmq.pool.size = 1
plugin.rabbitmq.pool.1.host = 192.168.20.153
plugin.rabbitmq.pool.1.port = 61613
plugin.rabbitmq.pool.1.user = mc_rabbitmq
plugin.rabbitmq.pool.1.password = 123.com
# Facts
factsource = yaml
plugin.yaml = /etc/mcollective/facts.yaml

#配置client端
[root@puppetmaster343 ~]# cat /etc/mcollective/client.cfg
main_collective = mcollective
collectives = mcollective
libdir = /usr/libexec/mcollective
logger_type = console
loglevel = warn
# Plugins
securityprovider = psk
plugin.psk = 7758521
# Rabbitmq Plugins
direct_addressing = 1
connector = rabbitmq
plugin.rabbitmq.vhost = /mcollective
plugin.rabbitmq.pool.size = 1
plugin.rabbitmq.pool.1.host = 192.168.20.153
plugin.rabbitmq.pool.1.port = 61613
plugin.rabbitmq.pool.1.user = mc_rabbitmq
plugin.rabbitmq.pool.1.password = 123.com
# Facts
factsource = yaml
plugin.yaml = /etc/mcollective/facts.yaml

#测试下和MQ的连通性    
[root@puppetmaster343 ~]# mco ping
puppetmaster343.kiss343.com              time=96.39 ms
---- ping statistics ----
1 replies max: 96.39 min: 96.39 avg: 96.39 

#测试下是否能够获取节点的信息
[root@puppetmaster343 ~]# mco inventory puppetmaster343.kiss343.com
Inventory for puppetmaster343.kiss343.com:
   Server Statistics:
                      Version: 2.5.3
                   Start Time: Wed Dec 17 15:04:45 +0800 2014
                  Config File: /etc/mcollective/server.cfg
                  Collectives: mcollective
              Main Collective: mcollective
                   Process ID: 32232
               Total Messages: 3
      Messages Passed Filters: 3
            Messages Filtered: 0
             Expired Messages: 0
                 Replies Sent: 2
         Total Processor Time: 0.38 seconds
                  System Time: 0.42 seconds
   Agents:
      discovery       rpcutil         shell          
   Data Plugins:
      agent           fstat                          
   Configuration Management Classes:
      No classes applied
   Facts:
      mcollective => 1

4、安装并测试puppet插件

#安装mcollective客户端和服务端
[root@puppetmaster343 ~]# yum install mcollective-puppet-agent mcollective-puppet-common 
[root@puppetmaster343 ~]# yum install mcollective-puppet-client mcollective-puppet-common 
#载入puppet插件
[root@puppetmaster343 ~]# /etc/init.d/mcollective reload-agents
Reloading mcollective agents:                              [  OK  ]
[root@puppetmaster343 ~]# mco 
The Marionette Collective version 2.5.3
usage: /usr/bin/mco command <options>
Known commands:
   completion           facts                find                
   help                 inventory            ping                
   plugin               puppet               rpc                 
Type '/usr/bin/mco help' for a detailed list of commands and '/usr/bin/mco help command'
to get detailed help for a command
#测试puppet插件
[root@puppetmaster343 ~]# mco puppet -v runonce
Discovering hosts using the mc method for 2 second(s) .... 1
 * [ ============================================================> ] 1 / 1
puppetmaster343.kiss343.com             : OK
    {:initiated_at=>1418800535,     :summary=>      "Started a Puppet run using the 'puppet agent --onetime --no-daemonize --color=false --show_diff --verbose --splay --splaylimit 30' command"}
---- rpc stats ----
           Nodes: 1 / 1
     Pass / Fail: 1 / 0
      Start Time: Wed Dec 17 15:15:35 +0800 2014
  Discovery Time: 2004.26ms
      Agent Time: 68.49ms
      Total Time: 2072.75ms

[root@puppetmaster343 ~]# mco puppet status
 * [ ============================================================> ] 1 / 1
   puppetmaster343.kiss343.com: Currently stopped; last completed run 12 seconds ago
Summary of Applying:
   false = 1
Summary of Daemon Running:
   stopped = 1
Summary of Enabled:
   enabled = 1
Summary of Idling:
   false = 1
Summary of Status:
   stopped = 1
Finished processing 1 / 1 hosts in 54.12 ms

测试结束,未发现mcollective新版本存在各种问题,比较伤心。。。

更多Rabbitmq的配置可参考 https://docs.puppetlabs.com/mcollective/reference/plugins/connector_rabbitmq.html