首页 > 代码库 > mcollective的web控制台---mcomaster搭建

mcollective的web控制台---mcomaster搭建

使用mcollective有段时间,每次在控制机上写命令运行agent感觉挺不方便的,于是想有没有专门的mcollective的web console,搜了下发现有两个:kermIT和mcomaster.

kermIT看上去比mcomaster功能多些,不过因为kermIT是django开发,而mcomaster是ruby开发,这样就和mcollective、pupppet一脉相承,学习成本也低点。

本文就介绍一下mcomaster系统的搭建(OS:Centos6.2),其中涉及到的链接可能有些需要翻墙。点击这里查看mcomaster官网的安装说明

===================================================================================================

1、mcomaster介绍

  mcomaster是一个mcollective框架的web控制台系统,通过mcomaster可以执行节点机agent,也就是在mco的各种命令,而这些只需要动动鼠标,不用再远程到mco的控制机上敲命令。并且可以实时查看返回结果。所以这一切都需要我们先搭建好mcollective环境。如果你对mcollective还不了解,建议先去我之前的文章翻看一下:http://www.cnblogs.com/waiwofei/p/3698675.html

2、ruby环境的搭建

  由于mcomaster要求必须是ruby1.9以上,而之前用yum安装的环境是是ruby1.87,最新的yum源都只是1.87,所以准备用源码安装ruby环境。下载 ruby2.12 源码。

# tar xzvf ruby-2.1.2.tar.gz# cd ruby-2.1.2# ./configure  --prefix=/usr/ruby/# make && make install# cp /usr/ruby/bin/ruby   /usr/bin/# cp /usr/ruby/bin/gem   /usr/bin/

  然后查看ruby及gem的版本看看是否安装成功

# ruby -vruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]# gem -v2.2.2

3、puppet安装

  puppet在mcomaster的部署中并不是必须的,不过puppet是我们肯定会用到,所以先把puppet弄好,当然你也可以不进行这一步。这里采用gem安装puppet

# gem install puppet# cd /usr/ruby/lib/ruby/gems/2.1.0/gems/puppet-3.6.2# cp conf/* /etc/puppet/# cp ext/redhat/server.init /etc/init.d/puppetmaster# chmod +x /etc/init.d/puppetmaster# cp bin/puppet /usr/bin/# mkdir /etc/puppet/manifests  /etc/puppet/modules# service puppetmaster start启动 puppetmaster:                                        [确定]

  接下来就是puppet服务器和客户端的常规配置,具体参考 http://www.chenshake.com/puppet-study-notes/

4、ActiveMQ安装

# yum install tanukiwrapper activemq activemq-info-provider

  安装完成后来对ActiveMQ进行配置,如下

# vim /etc/activemq/activemq.xml…<simpleAuthenticationPlugin>            <users><!--              <authenticationUser username="${activemq.username}" password="${activemq.password}" groups="admins,everyone"/> --> #禁用              <authenticationUser username="mcollective" password="secret" 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>
# service activemq startStarting ActiveMQ Broker...# chkconfig activemq on# netstat -nlatp | grep 61613  #查看监听端口tcp        0      0 :::61613                    :::*                        LISTEN      33805/java

5、mcollective安装

  首先安装mcollective-common,因为yum安装会同时ruby1.87等依赖,所以我们通过 https://yum.puppetlabs.com/el/6.2 下载对应的mcollective-common的rpm文件。

  接着通过下面语句安装

# rpm -ivh mcollective-common-2.5.2-1.el6.noarch.rpm --nodeps

  接着通过gem安装mcollective-client

# gem install mcollective-client# cp /usr/ruby/lib/ruby/gems/2.1.0/gems/mcollective-client-2.5.2/bin/mco /usr/bin/

  接下来就是mcollective的控制机和节点机的一些常规配置,这里省略,如果你不清楚的话,可以参考这个链接:http://www.cnblogs.com/waiwofei/p/3698675.html

  完成之后就是测试mco是否能正常使用,mco ping可以检查到2个节点机在线

# mco pingnode72.puppet.net                        time=115.32 msnode81.puppet.net                        time=131.42 ms---- ping statistics ----2 replies max: 131.42 min: 115.32 avg: 123.37
# mco inventory node72.puppet.netInventory for node72.puppet.net:   Server Statistics:                      Version: 2.3.2                   Start Time: 2014-07-17 10:22:05 +0800                  Config File: D:\mcollective\etc\server.cfg                  Collectives: mcollective              Main Collective: mcollective                   Process ID: 11040               Total Messages: 131      Messages Passed Filters: 131            Messages Filtered: 0             Expired Messages: 0                 Replies Sent: 8         Total Processor Time: 3.338 seconds                  System Time: 0.561 seconds   Agents:      discovery       filesystem      puppet      registration    rpcutil         runcmd   Data Plugins:      agent           fstat           puppet      resource   Configuration Management Classes:      No classes applied   Facts:      mcollective => 1

6、mcomaster安装和配置

  首先安装redis,mcomaster会使用到,具体查看这里:http://www.cnblogs.com/zhuhongbao/archive/2013/06/04/3117997.html

  然后下载mcomaster源码,https://github.com/ajf8/mcomaster,解压到/usr/目录

# cd /usr/mcomaster-master/# gem install bundler# bundle install

  上面安装必要的gem包,会需要一些时间,完成后继续

# cp config/application.example.yml config/application.yml# cp config/database.example.yml config/database.yml下面是初始化数据库,默认是sqlite# RAILS_ENV=production rake db:reset然后给mcomaster添加使用账号# RAILS_ENV=production script/add_user.sh -u username -p password -m email@domain.com# rake assets:precompile

  接下来我们需要对mcollective做一些配置

  在mcollective控制机上执行

# cp mcollective/agent/registration.rb /usr/libexec/mcollective/mcollective/agent/# cp mcollective/discovery/redisdiscovery.* /usr/libexec/mcollective/mcollective/discovery/# vim /etc/mcollective/client.cfg添加:default_discovery_method = redisdiscoverydirect_addressing = yesplugin.redis.host = localhostplugin.redis.port = 6379plugin.redis.db = 0

  在mcollective节点机上执行

# cp mcollective/registration/meta.rb /usr/libexec/mcollective/mcollective/registration/meta.rb编辑 server.cfg 添加plugin.redis.host = (mco控制机ip)plugin.redis.port = 6379plugin.redis.db = 0registerinterval = 300registration = Metadirect_addressing = yes

  现在mcomaster应该可以运行起来了

# rails server -e production=> Booting Thin=> Rails 4.0.0 application starting in production on http://0.0.0.0:3000=> Run `rails server -h` for more startup options=> Ctrl-C to shutdown server>> Thin web server (v1.5.1 codename Straight Razor)>> Maximum connections set to 1024>> Listening on 0.0.0.0:3000, CTRL+C to stop

打开浏览器输入 http://192.168.11.170:3000