设为首页 收藏本站
查看: 2210|回复: 0

[经验分享] mcollective插件(shell plugins)功能在Linux系统上无所不能

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-4-21 09:56:02 | 显示全部楼层 |阅读模式
众所周知,mcollecitve只是一个框架而已,它单独是干不了任何事情的,如果要让他去操作一个平台,是需要插件(plugins)进行操作的,比如通过puppet插件去管理节点puppet的所有命令,通过fact插件去管理fact的所有参数等等,那么如何去管理系统的命令呢,这就需要shell插件。
插件下载地址:https://github.com/kisspuppet/mcollective-plugins,有github客户端的童鞋可直接clone https://github.com/kisspuppet/mcollective-plugins.git
1、下载插件放在对应的目录里即可
mcollective-client端
[iyunv@linuxmaster1poc ~]# ll /usr/libexec/mcollective/mcollective/application/ | grep shell
-rw-r--r-- 1 root root  1601 Aug  6 06:36 shell.rb
[iyunv@linuxmaster1poc ~]# ll /usr/libexec/mcollective/mcollective/agent/ | grep shell
-rw-r--r-- 1 root root 1017 Aug  6 06:36 shell.ddl
-rw-r--r-- 1 root root  862 Aug  6 06:36 shell.rb
mcollective-server端
[iyunv@linux57poc agent]# ll /usr/libexec/mcollective/mcollective/agent/ | grep shell
-rw-r--r-- 1 root root 1017 Aug  6 06:36 shell.ddl
-rw-r--r-- 1 root root  862 Aug  6 06:36 shell.rb
备注:mcollective-server端部署完成之后,记得重启mcollective服务。
2、 查看shell插件是否加载成功
从下面可以看出mcollective-client端shell插件已经有了 [iyunv@linuxmaster1poc ~]# mco The Marionette Collective version 2.2.4 usage: /usr/bin/mco command Known commands: completion facts find
help inventory ping
plugin puppet rpc
shell #shell插件加载OK
Type '/usr/bin/mco help' for a detailed list of commands and '/usr/bin/mco help command' to get detailed help for a command
从下面可以看出mcollective-server端shell插件也加载了
[iyunv@linuxmaster1poc ~]# mco inventory linux57poc
Inventory for linux57poc:
   Server Statistics:
                      Version: 2.2.4
                   Start Time: Fri Dec 13 01:14:14 +0800 2013
                  Config File: /etc/mcollective/server.cfg
                  Collectives: mcollective
              Main Collective: mcollective
                   Process ID: 23898
               Total Messages: 10
      Messages Passed Filters: 10
            Messages Filtered: 0
             Expired Messages: 0
                 Replies Sent: 9
         Total Processor Time: 0.73 seconds
                  System Time: 0.17 seconds
   Agents:
      discovery       puppet          rpcutil        
      shell  #shell插件加载OK                                          
   Data Plugins:
      agent           fstat           puppet         
      resource                                       
   Configuration Management Classes:
      No classes applied
   Facts:
      architecture => x86_64
      augeasversion => 0.10.0
      bios_release_date => 06/22/2012
      bios_vendor => Phoenix Technologies LTD
      bios_version => 6.00
      blockdevice_fd0_size => 4096
      blockdevice_hdc_size => 3834736640
      blockdevice_sda_model => Virtual disk
      blockdevice_sda_size => 42949672960
    。。。
3、通过shell插件执行shell命令
mco shell帮助信息
[iyunv@linuxmaster1poc ~]# mco shell --help
MCollective Distributed Shell
Usage:   mco shell <CMD>
  The CMD is a string
  EXAMPLES:
    mco shell uptime
        --np, --no-progress          Do not show the progress bar
    -1, --one                        Send request to only one discovered nodes
        --batch SIZE                 Do requests in batches
        --batch-sleep SECONDS        Sleep time between batches
        --limit-seed NUMBER          Seed value for deterministic random batching
        --limit-nodes, --ln, --limit COUNT
                                     Send request to only a subset of nodes, can be a percentage
    -j, --json                       Produce JSON output
        --display MODE               Influence how results are displayed. One of ok, all or failed
    -c, --config FILE                Load configuratuion from file rather than default
    -v, --verbose                    Be verbose
    -h, --help                       Display this screen
Common Options
    -T, --target COLLECTIVE          Target messages to a specific sub collective
        --dt, --discovery-timeout SECONDS
                                     Timeout for doing discovery
    -t, --timeout SECONDS            Timeout for calling remote agents
    -q, --quiet                      Do not be verbose
        --ttl TTL                    Set the message validity period
        --reply-to TARGET            Set a custom target for replies
        --dm, --disc-method METHOD   Which discovery method to use
        --do, --disc-option OPTION   Options to pass to the discovery method
        --nodes FILE                 List of nodes to address
Host Filters
    -W, --with FILTER                Combined classes and facts filter
    -S, --select FILTER              Compound filter combining facts and classes
    -F, --wf, --with-fact fact=val   Match hosts with a certain fact
    -C, --wc, --with-class CLASS     Match hosts with a certain config management class
    -A, --wa, --with-agent AGENT     Match hosts with a certain agent
    -I, --wi, --with-identity IDENT  Match hosts with a certain configured identity
The Marionette Collective 2.2.4
显示对端uptime命令负载情况
[iyunv@linuxmaster1poc ~]# mco shell "uptime"
Do you really want to send this command unfiltered? (y/n): y
Discovering hosts using the mc method for 2 second(s) .... 3
Host: linux58poc
Statuscode: 0
Output:
02:45:02 up 21:10,  2 users,  load average: 0.00, 0.00, 0.00
Host: linux64poc
Statuscode: 0
Output:
02:45:02 up 20:59,  1 user,  load average: 0.00, 0.00, 0.00
Host: linux57poc
Statuscode: 0
Output:
02:45:02 up 21:04,  3 users,  load average: 0.00, 0.00, 0.00
显示所有节点/etc/password文件中puppet用户哪一行
[iyunv@linuxmaster1poc ~]# mco shell "cat /etc/passwd | grep puppet"
Do you really want to send this command unfiltered? (y/n): y
Discovering hosts using the mc method for 2 second(s) .... 3
Host: linux58poc
Statuscode: 0
Output:
puppet:x:52:52:Puppet:/var/lib/puppet:/sbin/nologin
Host: linux64poc
Statuscode: 0
Output:
puppet:x:52:52:Puppet:/var/lib/puppet:/sbin/nologin
Host: linux57poc
Statuscode: 0
Output:
puppet:x:52:52:Puppet:/var/lib/puppet:/sbin/nologin
修改其中一台主机的root密码
[iyunv@linuxmaster1poc ~]# mco shell "echo redhat | passwd root --stdin" -I linux57poc
Host: linux57poc
Statuscode: 0
Output:
Changing password for user root.
passwd: all authentication tokens updated successfully.
备注:更多操作步骤可参考mco shell --help帮助。
警告:基于mcollective的shell插件虽然功能很强大,除了动态显示的命令之外,其它root能操作的,它基本上都能操作。所以操作也非常危险,可根据生产环境实际情况而定。


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-18012-1-1.html 上篇帖子: puppet资源yumrepo详细介绍(附案例) 下篇帖子: 基于mcollective的多种plugins组合使用功能展示 Linux
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表