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

简介:

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

mcollective-client端

1
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@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
1
 

mcollective-server端

1
2
3
[root@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插件已经有了[root@linuxmaster1poc ~]# mco The Marionette Collective version 2.2.4

1
2
3
4
5
6
7
8
usage: /usr/bin/mco command <options>
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插件也加载了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
[root@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帮助信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
[root@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命令负载情况

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@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用户哪一行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@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密码

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

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



本文转自凌激冰51CTO博客,原文链接:http://blog.51cto.com/dreamfire/1340121,如需转载请自行联系原作者
相关文章
|
3月前
|
Ubuntu Linux Anolis
Linux系统禁用swap
本文介绍了在新版本Linux系统(如Ubuntu 20.04+、CentOS Stream、openEuler等)中禁用swap的两种方法。传统通过注释/etc/fstab中swap行的方式已失效,现需使用systemd管理swap.target服务或在/etc/fstab中添加noauto参数实现禁用。方法1通过屏蔽swap.target适用于新版系统,方法2通过修改fstab挂载选项更通用,兼容所有系统。
225 3
Linux系统禁用swap
|
3月前
|
Linux
Linux系统修改网卡名为eth0、eth1
在Linux系统中,可通过修改GRUB配置和创建Udev规则或使用systemd链接文件,将网卡名改为`eth0`、`eth1`等传统命名方式,适用于多种发行版并支持多网卡配置。
335 3
|
3月前
|
存储 安全 Unix
七、Linux Shell 与脚本基础
别再一遍遍地敲重复的命令了,把它们写进Shell脚本,就能一键搞定。脚本本质上就是个存着一堆命令的文本文件,但要让它“活”起来,有几个关键点:文件开头最好用#!/usr/bin/env bash来指定解释器,并用chmod +x给它执行权限。执行时也有讲究:./script.sh是在一个新“房间”(子Shell)里跑,不影响你;而source script.sh是在当前“房间”里跑,适合用来加载环境变量和配置文件。
420 9
|
Ubuntu Linux 网络安全
Linux系统初始化脚本
一款支持Rocky、CentOS、Ubuntu、Debian、openEuler等主流Linux发行版的系统初始化Shell脚本,涵盖网络配置、主机名设置、镜像源更换、安全加固等多项功能,适配单/双网卡环境,支持UEFI引导,提供多版本下载与持续更新。
300 0
Linux系统初始化脚本
|
3月前
|
算法 Linux Shell
Linux实用技能:打包压缩、热键、Shell与权限管理
本文详解Linux打包压缩技巧、常用命令与原理,涵盖.zip与.tgz格式操作、跨系统传文件方法、Shell运行机制及权限管理,助你高效使用Linux系统。
Linux实用技能:打包压缩、热键、Shell与权限管理
|
3月前
|
存储 Shell Linux
八、Linux Shell 脚本:变量与字符串
Shell脚本里的变量就像一个个贴着标签的“箱子”。装东西(赋值)时,=两边千万不能有空格。用单引号''装进去的东西会原封不动,用双引号""则会让里面的$变量先“变身”再装箱。默认箱子只能在当前“房间”(Shell进程)用,想让隔壁房间(子进程)也能看到,就得给箱子盖个export的“出口”戳。此外,Shell还自带了$?(上条命令的成绩单)和$1(别人递进来的第一个包裹)等许多特殊箱子,非常有用。
315 2
|
4月前
|
运维 Linux 开发者
Linux系统中使用Python的ping3库进行网络连通性测试
以上步骤展示了如何利用 Python 的 `ping3` 库来检测网络连通性,并且提供了基本错误处理方法以确保程序能够优雅地处理各种意外情形。通过简洁明快、易读易懂、实操性强等特点使得该方法非常适合开发者或系统管理员快速集成至自动化工具链之内进行日常运维任务之需求满足。
236 18
|
3月前
|
安全 Linux Shell
Linux系统提权方式全面总结:从基础到高级攻防技术
本文全面总结Linux系统提权技术,涵盖权限体系、配置错误、漏洞利用、密码攻击等方法,帮助安全研究人员掌握攻防技术,提升系统防护能力。
283 1
|
3月前
|
监控 安全 Linux
Linux系统提权之计划任务(Cron Jobs)提权
在Linux系统中,计划任务(Cron Jobs)常用于定时执行脚本或命令。若配置不当,攻击者可利用其提权至root权限。常见漏洞包括可写的Cron脚本、目录、通配符注入及PATH变量劫持。攻击者通过修改脚本、创建恶意任务或注入命令实现提权。系统管理员应遵循最小权限原则、使用绝对路径、避免通配符、设置安全PATH并定期审计,以防范此类攻击。
1010 1
|
4月前
|
缓存 监控 Linux
Linux系统清理缓存(buff/cache)的有效方法。
总结而言,在大多数情形下你不必担心Linux中buffer与cache占用过多内存在影响到其他程序运行;因为当程序请求更多内存在没有足够可用资源时,Linux会自行调整其占有量。只有当你明确知道当前环境与需求并希望立即回收这部分资源给即将运行重负载任务之前才考虑上述方法去主动干预。
1577 10