我々はすべて知っているように、mcollecitveは単なるフレームワークであり、それだけで何かをすることはできません、あなたは彼がプラットフォームを動作させたい場合は、そのようなファクトのすべてのパラメータを管理するために、ファクトのプラグインを介して、ノードの傀儡のすべてのコマンドを管理するための傀儡プラグインを介してのように動作するようにプラグインの必要性である、どのようにシステムのコマンドを管理するために、これは次のとおりです。シェルプラグインが必要です。
1、プラグインをダウンロードして、対応するカタログに入れてください。
mcollective クライアント側
[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
mcollective サーバ側
[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、シェルプラグインが正常にロードされたかどうかを確認します
以下のように、mcollective-client側のシェルプラグインはすでに存在しています。
[root@linuxmaster1poc ~]# mco The Marionette Collective version 2.2.4
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 側のシェルプラグインもロードされています!
[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、シェルプラグインでシェルコマンドを実行
mco shell ヘルプ情報
[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コマンドの負荷を表示
[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 ユーザーの行を表示します。
[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台でrootパスワードを変更
警告: mcollectiveベースのシェルプラグインは非常に強力ですが、動的に表示されるコマンドを除き、基本的にrootができる他のすべてを操作します。そのため、本番環境の実際の状況によっては、この操作も非常に危険です。
この記事はブログからのものです。





