mcollective shell插件功能在Linux系统上无所不能

运维 系统运维
众所周知,mcollecitve只是一个框架而已,它单独是干不了任何事情的,如果要让他去操作一个平台,是需要插件(plugins)进行操作的,比如通过puppet插件去管理节点puppet的所有命令,通过fact插件去管理fact的所有参数等等,那么如何去管理系统的命令呢,这就需要shell插件。

众所周知,mcollecitve只是一个框架而已,它单独是干不了任何事情的,如果要让他去操作一个平台,是需要插件(plugins)进行操作的,比如通过puppet插件去管理节点puppet的所有命令,通过fact插件去管理fact的所有参数等等,那么如何去管理系统的命令呢,这就需要shell插件。

插件下载地址:https://github.com/kisspuppet/mcollective-plugins,有github客户端的童鞋可直接clonehttps://github.com/kisspuppet/mcollective-plugins.git

更多有关puppet的文章可访问http://kisspuppet.com

1、下载插件放在对应的目录里即可

mcollective-client端

  1. [root@linuxmaster1poc ~]# mco shell "cat /etc/passwd | grep puppet" 
  2. Do you really want to send this command unfiltered? (y/n): y 
  3. Discovering hosts using the mc method for 2 second(s) .... 3 
  4. Host: linux58poc 
  5. Statuscode: 0 
  6. Output: 
  7. puppet:x:52:52:Puppet:/var/lib/puppet:/sbin/nologin 
  8. Host: linux64poc 
  9. Statuscode: 0 
  10. Output: 
  11. puppet:x:52:52:Puppet:/var/lib/puppet:/sbin/nologin 
  12. Host: linux57poc 
  13. Statuscode: 0 
  14. Output: 
  15. puppet:x:52:52:Puppet:/var/lib/puppet:/sbin/nologin 

mcollective-server端

  1. [root@linux57poc agent]# ll /usr/libexec/mcollective/mcollective/agent/ | grep shell 
  2. -rw-r--r-- 1 root root 1017 Aug  6 06:36 shell.ddl 
  3. -rw-r--r-- 1 root root  862 Aug  6 06:36 shell.rb 

备注:mcollective-server端部署完成之后,记得重启mcollective服务。

2、 查看shell插件是否加载成功

从下面可以看出mcollective-client端shell插件已经有了

  1. [root@linuxmaster1poc ~]# mco The Marionette Collective version 2.2.4 
  2. usage: /usr/bin/mco command <options> 
  3. Known commands: 
  4.    completion           facts                find               
  5.    help                 inventory            ping               
  6.    plugin               puppet               rpc                
  7.    shell   #shell插件加载OK                                                     
  8. Type '/usr/bin/mco help' for a detailed list of commands and '/usr/bin/mco help command' 
  9. to get detailed help for a command 

从下面可以看出mcollective-server端shell插件也加载了

  1. [root@linuxmaster1poc ~]# mco inventory linux57poc 
  2. Inventory for linux57poc: 
  3.    Server Statistics: 
  4.                       Version: 2.2.4 
  5.                    Start Time: Fri Dec 13 01:14:14 +0800 2013 
  6.                   Config File: /etc/mcollective/server.cfg 
  7.                   Collectives: mcollective 
  8.               Main Collective: mcollective 
  9.                    Process ID: 23898 
  10.                Total Messages: 10 
  11.       Messages Passed Filters: 10 
  12.             Messages Filtered: 0 
  13.              Expired Messages: 0 
  14.                  Replies Sent: 9 
  15.          Total Processor Time: 0.73 seconds 
  16.                   System Time: 0.17 seconds 
  17.    Agents: 
  18.       discovery       puppet          rpcutil       
  19.       shell  #shell插件加载OK                                         
  20.    Data Plugins: 
  21.       agent           fstat           puppet        
  22.       resource                                      
  23.    Configuration Management Classes: 
  24.       No classes applied 
  25.    Facts: 
  26.       architecture => x86_64 
  27.       augeasversion => 0.10.0 
  28.       bios_release_date => 06/22/2012 
  29.       bios_vendor => Phoenix Technologies LTD 
  30.       bios_version => 6.00 
  31.       blockdevice_fd0_size => 4096 
  32.       blockdevice_hdc_size => 3834736640 
  33.       blockdevice_sda_model => Virtual disk 
  34.       blockdevice_sda_size => 42949672960 
  35.     。。。 

3、通过shell插件执行shell命令

mco shell帮助信息

  1. [root@linuxmaster1poc ~]# mco shell --help 
  2. MCollective Distributed Shell 
  3. Usage:   mco shell <CMD> 
  4.   The CMD is a string 
  5.   EXAMPLES: 
  6.     mco shell uptime 
  7.         --np, --no-progress          Do not show the progress bar 
  8.     -1, --one                        Send request to only one discovered nodes 
  9.         --batch SIZE                 Do requests in batches 
  10.         --batch-sleep SECONDS        Sleep time between batches 
  11.         --limit-seed NUMBER          Seed value for deterministic random batching 
  12.         --limit-nodes, --ln, --limit COUNT 
  13.                                      Send request to only a subset of nodes, can be a percentage 
  14.     -j, --json                       Produce JSON output 
  15.         --display MODE               Influence how results are displayed. One of ok, all or failed 
  16.     -c, --config FILE                Load configuratuion from file rather than default 
  17.     -v, --verbose                    Be verbose 
  18.     -h, --help                       Display this screen 
  19. Common Options 
  20.     -T, --target COLLECTIVE          Target messages to a specific sub collective 
  21.         --dt, --discovery-timeout SECONDS 
  22.                                      Timeout for doing discovery 
  23.     -t, --timeout SECONDS            Timeout for calling remote agents 
  24.     -q, --quiet                      Do not be verbose 
  25.         --ttl TTL                    Set the message validity period 
  26.         --reply-to TARGET            Set a custom target for replies 
  27.         --dm, --disc-method METHOD   Which discovery method to use 
  28.         --do, --disc-option OPTION   Options to pass to the discovery method 
  29.         --nodes FILE                 List of nodes to address 
  30. Host Filters 
  31.     -W, --with FILTER                Combined classes and facts filter 
  32.     -S, --select FILTER              Compound filter combining facts and classes 
  33.     -F, --wf, --with-fact fact=val   Match hosts with a certain fact 
  34.     -C, --wc, --with-class CLASS     Match hosts with a certain config management class 
  35.     -A, --wa, --with-agent AGENT     Match hosts with a certain agent 
  36.     -I, --wi, --with-identity IDENT  Match hosts with a certain configured identity 
  37. The Marionette Collective 2.2.4 

显示对端uptime命令负载情况

  1. [root@linuxmaster1poc ~]# mco shell "uptime" 
  2. Do you really want to send this command unfiltered? (y/n): y 
  3. Discovering hosts using the mc method for 2 second(s) .... 3 
  4. Host: linux58poc 
  5. Statuscode: 0 
  6. Output: 
  7.  02:45:02 up 21:10,  2 users,  load average: 0.00, 0.00, 0.00 
  8. Host: linux64poc 
  9. Statuscode: 0 
  10. Output: 
  11.  02:45:02 up 20:59,  1 user,  load average: 0.00, 0.00, 0.00 
  12. Host: linux57poc 
  13. Statuscode: 0 
  14. Output: 
  15.  02:45:02 up 21:04,  3 users,  load average: 0.00, 0.00, 0.00 

显示所有节点/etc/password文件中puppet用户哪一行

  1. [root@linuxmaster1poc ~]# mco shell "cat /etc/passwd | grep puppet" 
  2. Do you really want to send this command unfiltered? (y/n): y 
  3. Discovering hosts using the mc method for 2 second(s) .... 3 
  4. Host: linux58poc 
  5. Statuscode: 0 
  6. Output: 
  7. puppet:x:52:52:Puppet:/var/lib/puppet:/sbin/nologin 
  8. Host: linux64poc 
  9. Statuscode: 0 
  10. Output: 
  11. puppet:x:52:52:Puppet:/var/lib/puppet:/sbin/nologin 
  12. Host: linux57poc 
  13. Statuscode: 0 
  14. Output: 
  15. puppet:x:52:52:Puppet:/var/lib/puppet:/sbin/nologin 

修改其中一台主机的root密码

备注:更多操作步骤可参考mco shell --help帮助。

警告:基于mcollective的shell插件虽然功能很强大,除了动态显示的命令之外,其它root能操作的,它基本上都能操作。所以操作也非常危险,可根据生产环境实际情况而定。

本文出自 “www.kisspuppet.com” 博客。

 

责任编辑:奔跑的冰淇淋 来源: 51CTO博客
相关推荐

2021-04-07 10:02:18

人工智能技术互联网

2009-07-06 18:43:13

VB指针

2013-05-22 14:05:18

2023-11-28 12:09:43

Linux网络工具

2015-04-30 14:53:43

Build 2015微软Azure

2015-10-28 15:47:22

谷歌物联网互联网

2021-08-16 10:13:26

AI DeepMind人工智能

2021-04-17 23:05:29

手机黑科技APP

2014-06-13 02:21:14

2019-12-19 14:17:11

以太坊去中心化加密货币

2013-04-09 14:23:12

3D打印

2020-03-09 10:43:28

人工智能疫情机器人

2014-03-11 23:02:00

2023-09-07 07:08:49

ChatGPTAI节点

2021-02-07 00:29:14

支付宝互联网返乡隔离政策

2011-09-12 15:32:58

2023-09-06 06:38:18

AMDCPUGPU

2021-04-05 22:37:29

微信小程序手机

2012-06-18 16:21:00

华硕无线路由RT-N15U

2021-07-30 15:50:54

Python定时器JavaScrip
点赞
收藏

51CTO技术栈公众号