• MCollective架构篇2-MCollective+MQ架构的部署
  • 1 Mcollective介绍
  • 2 安装和配置RabbitMQ
    • 2.1 安装和配置RabbitMQ
  • 3 安装和配置MCollective
    • 3.1 安装MCollective
    • 3.2 配置MCollective
    • 3.3 测试Mcollective与Middleware通信

    MCollective架构篇2-MCollective+MQ架构的部署

    1 Mcollective介绍

    MCollective 是一个构建服务器编排(Server Orchestration)和并行工作执行系统的框架。 首先,MCollective 是一种针对服务器集群进行可编程控制的系统管理解决方案。在这一点上,它的功能类似:Func,Fabric 和 Capistrano。

    其次,MCollective 的设计打破基于中心存储式系统和像 SSH 这样的工具,不再仅仅痴迷于 SSH 的 For 循环。它使用发布订阅中间件(Publish Subscribe Middleware)这样的现代化 工具和通过目标数据(meta data)而不是主机名(hostnames)来实时发现网络资源这样的现代化理念。提供了一个可扩展的而且迅速的并行执行环境。

    MCollective 工具为命令行界面,但它可与数千个应用实例进行通信,而且传输速度惊人。无论部署的实例位于什么位置,通信都能以线速进行传输,使用的是一个类似多路传送的推送信息系统。MCollective 工具没有可视化用户界面,用户只能通过检索来获取需要应用的实例。Puppet Dashboard 提供有这部分功能。

    2 安装和配置RabbitMQ

    2.1 安装和配置RabbitMQ

    2.1.1 安装RabbitMQ

    1. [root@puppetserver rpms]# yum install erlang #RabbitMQ依赖erlang语言,需要安装大概65个左右的erlang依赖包
    2. [root@puppetserver rpms]# yum install rabbitmq-server
    3. [root@puppetserver rpms]# ll /usr/lib/rabbitmq/lib/rabbitmq_server-3.1.5/plugins/ #默认已经安装了stomp插件,老版本需要下载安装
    4. -rw-r--r-- 1 root root 242999 Aug 24 17:42 amqp_client-3.1.5.ez
    5. -rw-r--r-- 1 root root 85847 Aug 24 17:42 rabbitmq_stomp-3.1.5.ez

    2.1.2 启动rabbitmq-server

    1. [root@puppetserver rpms]# /etc/rc.d/init.d/rabbitmq-server start #启动rabbitmq服务
    2. Starting rabbitmq-server: SUCCESS
    3. rabbitmq-server.
    4. [root@puppetserver rpms]# /etc/rc.d/init.d/rabbitmq-server status #查看rabbitmq状态
    5. Status of node rabbit@puppetserver ...
    6. [{pid,43198},
    7. {running_applications,[{rabbit,"RabbitMQ","3.1.5"},
    8. {mnesia,"MNESIA CXC 138 12","4.5"},
    9. {os_mon,"CPO CXC 138 46","2.2.7"},
    10. {xmerl,"XML parser","1.2.10"},
    11. {sasl,"SASL CXC 138 11","2.1.10"},
    12. {stdlib,"ERTS CXC 138 10","1.17.5"},
    13. {kernel,"ERTS CXC 138 10","2.14.5"}]},
    14. {os,{unix,linux}},
    15. {erlang_version,"Erlang R14B04 (erts-5.8.5) [source] [64-bit] [rq:1] [async-threads:30] [kernel-poll:true]\n"},
    16. {memory,[{total,27101856},
    17. {connection_procs,2648},
    18. {queue_procs,5296},
    19. {plugins,0},
    20. {other_proc,9182320},
    21. {mnesia,57456},
    22. {mgmt_db,0},
    23. {msg_index,21848},
    24. {other_ets,765504},
    25. {binary,3296},
    26. {code,14419185},
    27. {atom,1354457},
    28. {other_system,1289846}]},
    29. {vm_memory_high_watermark,0.4},
    30. {vm_memory_limit,838362726},
    31. {disk_free_limit,1000000000},
    32. {disk_free,15992676352},
    33. {file_descriptors,[{total_limit,924},
    34. {total_used,3},
    35. {sockets_limit,829},
    36. {sockets_used,1}]},
    37. {processes,[{limit,1048576},{used,122}]},
    38. {run_queue,0},
    39. {uptime,4}]
    40. ...done.
    41. [root@puppetserver rpms]# netstat -nlp | grep beam #默认监听端口为5672
    42. tcp 0 0 0.0.0.0:44422 0.0.0.0:* LISTEN 43198/beam
    43. tcp 0 0 :::5672 :::* LISTEN 43198/beam

    2.1.3 配置RabbitMQ

    2.1.3.1 加载amqp_client和rabbit_stomp插件

    1. [root@puppetserver sbin]#ln -s /usr/lib/rabbitmq/lib/rabbitmq_server-3.1.5/sbin/rabbitmq-plugins /usr/sbin/rabbitmq-plugins #创建命令rabbitmq-plugins的软连接
    2. [root@puppetserver sbin]# ln -s /usr/lib/rabbitmq/lib/rabbitmq_server-3.1.5/sbin/rabbitmq-env /usr/sbin/rabbitmq-env #创建命令rabbitmq-env的软连接
    3. [root@puppetserver sbin]# rabbitmq-plugins enable rabbitmq_stomp #开启rabbitmq_stomp插件
    4. The following plugins have been enabled:
    5. amqp_client
    6. rabbitmq_stomp
    7. Plugin configuration has changed. Restart RabbitMQ for changes to take effect.
    8. [root@puppetserver sbin]# /etc/rc.d/init.d/rabbitmq-server restart
    9. Restarting rabbitmq-server: SUCCESS
    10. rabbitmq-server.
    11. [root@puppetserver rabbitmq]# tailf /var/log/rabbitmq/rabbit\@puppetserver.log #可以从日志看到stomp插件加载成功
    12. =INFO REPORT==== 3-Oct-2013::20:25:18 ===
    13. started STOMP TCP Listener on [::]:61613
    14. =INFO REPORT==== 3-Oct-2013::20:25:18 ===
    15. Server startup complete; 2 plugins started.
    16. * amqp_client
    17. * rabbitmq_stomp
    • 2.1.3.2 创建rabbitmq.config配置文件,修改监听端口为61613

      [root@puppetserver rpms]# vim /etc/rabbitmq/rabbitmq.config
      [

      1. {stomp,[ {tcp_listeners, [61613]} ]} #设置connector为stomp,监听端口为61613

      ].
      [root@puppetserver rpms]# /etc/rc.d/init.d/rabbitmq-server restart
      Restarting rabbitmq-server: SUCCESS
      rabbitmq-server.
      [root@puppetserver rpms]# netstat -nlp | grep beam #默认监听端口为61613
      tcp 0 0 0.0.0.0:56532 0.0.0.0: LISTEN 1906/beam.smp
      tcp 0 0 :::61613 :::
      LISTEN 1906/beam.smp
      tcp 0 0 :::5672 :::* LISTEN 1906/beam.smp

    2.1.3.3 删除默认账户guest,为MCollective创建账户“mcollective”并设置密码为“secret”,然后设置权限。

    1. [root@puppetserver rpms]# rabbitmqctl delete_user guest
    2. Deleting user "guest" ...
    3. ...done.
    4. [root@puppetserver rpms]# rabbitmqctl add_user mcollective secret
    5. Creating user "mcollective" ...
    6. ...done.
    7. [root@puppetserver rpms]# rabbitmqctl set_permissions -p "/" mcollective ".*" ".*" ".*"
    8. Setting permissions for user "mcollective" in vhost "/" ...
    9. ...done.
    10. [root@puppetserver sbin]# rabbitmqctl list_users #查看监听用户
    11. Listing users ...
    12. mcollective []
    13. ...done.

    备注:RabbitMQ拥有一个默认的guest账户,它默认对消息队列拥有全部权限。出于安全方面的考虑,建议删除这个账户。

    更多详细配置信息请参考 http://www.rabbitmq.com/admin-guide.html

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

    3 安装和配置MCollective

    3.1 安装MCollective

    3.1.1 测试端安装MCollective客户端

    1. [root@puppetserver rpms]# yum install mcollective-common mcollective-client #依赖包rubygem-stomp

    3.1.2 节点安装MCollective服务端

    1. [root@agent1 ~]# yum install mcollective mcollective-common #依赖rubygem-stomp、rubygems和ruby相关包

    3.2 配置MCollective

    3.2.1 测试端配置MCollective客户端

    1. [root@puppetserver rpms]# vim /etc/mcollective/client.cfg
    2. topicprefix = /topic/
    3. main_collective = mcollective
    4. collectives = mcollective
    5. libdir = /usr/libexec/mcollective
    6. logger_type = console
    7. loglevel = warn
    8. # Plugins
    9. securityprovider = psk
    10. plugin.psk = a36cd839414370e10fd281b8a38a4f48 #MCollective通信共享密钥,和MCollective服务端保持一致
    11. connector = stomp #通信协议
    12. plugin.stomp.host = 192.168.100.110 #Middleware地址
    13. plugin.stomp.port = 61613 #Middleware监听端口
    14. plugin.stomp.user = mcollective #Middleware通信账号
    15. plugin.stomp.password = secret #Middleware通信密码
    16. # Facts
    17. factsource = yaml
    18. plugin.yaml = /etc/mcollective/facts.yaml

    3.2.2 节点配置MCollective服务端

    1. [root@agent1 rpms]# vim /etc/mcollective/server.cfg
    2. topicprefix = /topic/
    3. main_collective = mcollective
    4. collectives = mcollective
    5. libdir = /usr/libexec/mcollective #存放plugins的位置
    6. logfile = /var/log/mcollective.log
    7. loglevel = info
    8. daemonize = 1
    9. # Plugins
    10. securityprovider = psk
    11. plugin.psk = a36cd839414370e10fd281b8a38a4f48 #MCollective通信共享密钥,和MCollective客户端保持一致
    12. connector = stomp #通信协议
    13. plugin.stomp.host = 192.168.100.110 #Middleware地址
    14. plugin.stomp.port = 61613 #Middleware监听端口
    15. plugin.stomp.user = mcollective #Middleware通信账号
    16. plugin.stomp.password = secret #Middleware通信密码
    17. # Facts
    18. factsource = yaml
    19. plugin.yaml = /etc/mcollective/facts.yaml
    20. [root@agent1 ~]# /etc/rc.d/init.d/mcollective start
    21. Starting mcollective: [ OK ]
    22. [root@agent1 ~]# chkconfig mcollective on
    23. [root@agent1 ~]#

    3.3 测试Mcollective与Middleware通信

    1. [root@puppetserver rpms]# mco ping #检查所有存活的节点
    2. agent2.kisspuppet.com time=119.98 ms
    3. agent1.kisspuppet.com time=159.31 ms
    4. ---- ping statistics ----
    5. 2 replies max: 159.31 min: 119.98 avg: 139.64
    6. [root@puppetserver rpms]# mco find
    7. agent1.kisspuppet.com
    8. agent2.kisspuppet.com