Winse Blog

走走停停都是风景, 熙熙攘攘都向最好, 忙忙碌碌都为明朝, 何畏之.

MCollective Plugins

上一篇介绍了mcollective的安装。乘着这股热情把 mco 命令行和插件的安装弄通,记录下来。

基本命令使用

1
2
3
4
5
6
7
8
9
10
11
12
[root@hadoop-master2 ~]# mco help
The Marionette Collective version 2.8.8

  completion      Helper for shell completion systems
  describe_filter Display human readable interpretation of filters
  facts           Reports on usage for a specific fact
  find            Find hosts using the discovery system matching filter criteria
  help            Application list and help
  inventory       General reporting tool for nodes, collectives and subcollectives
  ping            Ping all nodes
  plugin          MCollective Plugin Application
  rpc             Generic RPC agent client application

自带的插件只能用来查看环境情况(下面列出来的命令上一篇:MCollective安装配置都已记录过)。

1
2
3
mco ping
mco inventory [server_host]
mco facts [fact]

mcollective 的 filter(适配节点)功能很强大,具体查看文档:Selecting Request Targets Using Filters

使用filter功能需要结合facts,需要先把节点的信息写入到mcollective/facts.yaml文件

1
2
3
4
5
6
7
8
[hadoop@hadoop-master1 ~]$ sudo mco ping -I /^hadoop/
[hadoop@hadoop-master1 ~]$ sudo mco puppet runall 8 -I /^hadoop/
[hadoop@hadoop-master1 ~]$ sudo mco service iptables status -I "/cu-ud.*/"

[root@hadoop-master1 manifests]# mco ping -S "hostname=hadoop-master2"
[hadoop@hadoop-master1 ~]$ sudo mco ping -S 'hostname=/hadoop.*/'

[hadoop@hadoop-master1 ~]$ sudo mco facts hostname

插件安装

文档中描述了 Use packagesPut files directly into the libdir 两种安装插件的方式。但是 Packages 都是放在 旧的repo 里面,我们这里使用第二种方式把github下载源码放到libdir来安装。

安装mcollective-puppet-agent

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# 使用文档 https://github.com/puppetlabs/mcollective-puppet-agent#readme
# 直接下载release版本 
[root@hadoop-master2 ~]# cd /usr/libexec/mcollective/
[root@hadoop-master2 mcollective]# ll
total 44
-rw-r--r-- 1 root root 44759 Apr 29 11:53 mcollective-puppet-agent-1.10.0.tar.gz
[root@hadoop-master2 mcollective]# tar zxf mcollective-puppet-agent-1.10.0.tar.gz  
[root@hadoop-master2 mcollective]# ll mcollective-puppet-agent-1.10.0
total 60
drwxrwxr-x 2 root root  4096 Apr 13  2015 agent
drwxrwxr-x 2 root root  4096 Apr 13  2015 aggregate
drwxrwxr-x 2 root root  4096 Apr 13  2015 application
-rw-rw-r-- 1 root root  3456 Apr 13  2015 CHANGELOG.md
drwxrwxr-x 2 root root  4096 Apr 13  2015 data
drwxrwxr-x 4 root root  4096 Apr 13  2015 ext
-rw-rw-r-- 1 root root   349 Apr 13  2015 Gemfile
-rw-rw-r-- 1 root root  3036 Apr 13  2015 Rakefile
-rw-rw-r-- 1 root root 14739 Apr 13  2015 README.md
drwxrwxr-x 9 root root  4096 Apr 13  2015 spec
drwxrwxr-x 3 root root  4096 Apr 13  2015 util
drwxrwxr-x 2 root root  4096 Apr 13  2015 validator
# 官网提供example有区分服务端和客户端文件。反正多了没问题,直接全部放就行咯。。。
[root@hadoop-master2 mcollective]# mv mcollective-puppet-agent-1.10.0 mcollective

# 验证
# 多了puppet的命令!
[root@hadoop-master2 mcollective]# mco help
The Marionette Collective version 2.8.8

  completion      Helper for shell completion systems
  describe_filter Display human readable interpretation of filters
  facts           Reports on usage for a specific fact
  find            Find hosts using the discovery system matching filter criteria
  help            Application list and help
  inventory       General reporting tool for nodes, collectives and subcollectives
  ping            Ping all nodes
  plugin          MCollective Plugin Application
  puppet          Schedule runs, enable, disable and interrogate the Puppet Agent
  rpc             Generic RPC agent client application


# 同步到mcollective-servers (172.17.0.2对应hadoop-slaver1)
[root@hadoop-master2 mcollective]# rsync -az /usr/libexec/mcollective 172.17.0.2:/usr/libexec/

# mcollective-server添加插件后,重启mcollective服务
# 也可以使用 reload-agents 来重新加载agents: service mcollective reload-agents
[root@hadoop-slaver1 libexec]# service mcollective restart
Shutting down mcollective:                                 [  OK  ]
Starting mcollective:                                      [  OK  ]


# 验证server,已经可以看到新添加的puppet命令了
[root@hadoop-master2 mcollective]# mco inventory hadoop-slaver1
Inventory for hadoop-slaver1:

   Server Statistics:
                      Version: 2.8.8
                   Start Time: 2016-04-29 12:01:40 +0800
                  Config File: /etc/puppetlabs/mcollective/server.cfg
                  Collectives: mcollective
              Main Collective: mcollective
                   Process ID: 123
               Total Messages: 1
      Messages Passed Filters: 1
            Messages Filtered: 0
             Expired Messages: 0
                 Replies Sent: 0
         Total Processor Time: 0.67 seconds
                  System Time: 0.8 seconds

   Agents:
      discovery       puppet          rpcutil        

   Data Plugins:
      agent           collective      fact           
      fstat           puppet          resource       

[root@hadoop-master2 mcollective]# mco help puppet

[root@hadoop-master2 mcollective]# mco puppet status    

 * [ ============================================================> ] 3 / 3

   hadoop-slaver1: Currently stopped; last completed run 10 hours 57 minutes 20 seconds ago
   hadoop-master1: Currently stopped; last completed run 11 hours 1 minutes 05 seconds ago
   hadoop-slaver2: Currently stopped; last completed run 10 hours 57 minutes 16 seconds ago
...


# 配置server.conf
# 注意:真正要执行puppet命令,为了适配puppet4需要添加/修改配置
-bash-4.1# cat /etc/puppetlabs/mcollective/server.cfg 
...
plugin.puppet.command = /opt/puppetlabs/bin/puppet agent
plugin.puppet.config = /etc/puppetlabs/puppet/puppet.conf

# 重启所有mcollective(重新加载agent也可以不重启,使用 mco shell run service mcollective reload-agents 来重新加载)

[root@hadoop-master2 mcollective]# mco puppet runall 1
2016-04-29 16:52:46: Running all nodes with a concurrency of 1
2016-04-29 16:52:46: Discovering enabled Puppet nodes to manage
2016-04-29 16:52:49: Found 3 enabled nodes
2016-04-29 16:52:50: hadoop-slaver1 schedule status: Started a Puppet run using the '/opt/puppetlabs/bin/puppet agent --onetime --no-daemonize --color=false --show_diff --verbose --no-splay' command
2016-04-29 16:52:55: hadoop-slaver2 schedule status: Started a Puppet run using the '/opt/puppetlabs/bin/puppet agent --onetime --no-daemonize --color=false --show_diff --verbose --no-splay' command
2016-04-29 16:52:59: hadoop-master1 schedule status: Started a Puppet run using the '/opt/puppetlabs/bin/puppet agent --onetime --no-daemonize --color=false --show_diff --verbose --no-splay' command
2016-04-29 16:52:59: Iteration complete. Initiated a Puppet run on 3 nodes.

[root@hadoop-master2 puppetlabs]# mco puppet status

 * [ ============================================================> ] 3 / 3

   hadoop-master1: Currently stopped; last completed run 10 seconds ago
   hadoop-slaver1: Currently stopped; last completed run 15 seconds ago
   hadoop-slaver2: Currently stopped; last completed run 04 seconds ago
...
# 或者通过 puppetexplorer 查看节点最后的更新时间

安装 package / service 插件

为了更好的管理,再添加 package 和 service 两个插件

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# http://stackoverflow.com/questions/8488253/how-to-force-cp-to-overwrite-without-confirmation
[root@hadoop-master2 mcollective]# unalias cp
[root@hadoop-master2 mcollective]# cp -rf mcollective-service-agent-3.1.3/* mcollective/   
[root@hadoop-master2 mcollective]# cp -rf mcollective-package-agent-4.4.0/* mcollective/

[root@hadoop-master2 mcollective]# rsync -az /usr/libexec/mcollective 172.17.0.2:/usr/libexec/

# 重启mcollective服务(或者 mco shell run service mcollective reload-agents 重新加载)

# updated 2016-5-11 17:15:08
# 还是重启比较好,reload-agents Data Plugins 没有重新加载
[root@hadoop-master1 puppet]# mco inventory hadoop-master2
Inventory for hadoop-master2:

   Server Statistics:
                      Version: 2.8.8
                   Start Time: 2016-05-11 17:12:45 +0800
                  Config File: /etc/puppetlabs/mcollective/server.cfg
                  Collectives: mcollective
              Main Collective: mcollective
                   Process ID: 39878
               Total Messages: 1
      Messages Passed Filters: 1
            Messages Filtered: 0
             Expired Messages: 0
                 Replies Sent: 0
         Total Processor Time: 1.17 seconds
                  System Time: 0.1 seconds

   Agents:
      discovery       package         puppet         
      rpcutil         service         shell          

   Data Plugins:
      agent           collective      fact           
      fstat           puppet          resource       
      service                                        

   Configuration Management Classes:
      No classes applied

   Facts:
      mcollective => 1
[root@hadoop-master1 puppet]# mco inventory hadoop-slaver2
Inventory for hadoop-slaver2:

   Server Statistics:
                      Version: 2.8.8
                   Start Time: 2016-05-11 16:56:09 +0800
                  Config File: /etc/puppetlabs/mcollective/server.cfg
                  Collectives: mcollective
              Main Collective: mcollective
                   Process ID: 14062
               Total Messages: 9
      Messages Passed Filters: 7
            Messages Filtered: 2
             Expired Messages: 0
                 Replies Sent: 6
         Total Processor Time: 1.31 seconds
                  System Time: 0.23 seconds

   Agents:
      discovery       package         puppet         
      rpcutil         service         shell          

   Data Plugins:
      agent           collective      fact           
      fstat                                          

   Configuration Management Classes:
      No classes applied

   Facts:
      mcollective => 1

验证下package的实力:

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
[root@hadoop-master2 mcollective]# mco package lrzsz status

 * [ ============================================================> ] 3 / 3

   hadoop-slaver1: lrzsz-0.12.20-27.1.el6.x86_64
   hadoop-master1: -purged.
   hadoop-slaver2: -purged.

Summary of Arch:

   x86_64 = 1

Summary of Ensure:

             purged = 2
   0.12.20-27.1.el6 = 1


Finished processing 3 / 3 hosts in 1488.41 ms

[root@hadoop-master2 mcollective]# mco rpc package install package=lrzsz
Discovering hosts using the mc method for 2 second(s) .... 3

 * [ ============================================================> ] 3 / 3


hadoop-slaver1                           Unknown Request Status
   Package is already installed


Summary of Ensure:

   0.12.20-27.1.el6 = 3


Finished processing 3 / 3 hosts in 14525.03 ms
[root@hadoop-master2 mcollective]# mco package lrzsz status

 * [ ============================================================> ] 3 / 3

   hadoop-master1: lrzsz-0.12.20-27.1.el6.x86_64
   hadoop-slaver2: lrzsz-0.12.20-27.1.el6.x86_64
   hadoop-slaver1: lrzsz-0.12.20-27.1.el6.x86_64

Summary of Arch:

   x86_64 = 3

Summary of Ensure:

   0.12.20-27.1.el6 = 3


Finished processing 3 / 3 hosts in 572.13 ms

还有很多的插件:

添加了 service,package,shell,puppet 插件后,用 mco 来执行管理集群太爽了!!

后期统一安装

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
[root@hadoop-master1 mcollective]# ll
total 100
-rw-r--r-- 1 root root 17101 Apr 29 12:15 mcollective-package-agent-4.4.0.tar.gz
-rw-r--r-- 1 root root 44759 Apr 29 11:53 mcollective-puppet-agent-1.10.0.tar.gz
-rw-r--r-- 1 root root 12483 Apr 29 12:15 mcollective-service-agent-3.1.3.tar.gz
-rw-r--r-- 1 root root 17984 Apr 29 19:24 mcollective-shell-agent-0.0.2.tar.gz
[root@hadoop-master1 mcollective]# ls | xargs -I{} tar zxf {}

# TODO 可以考虑打包成rpm
[root@hadoop-master1 mcollective]# mkdir mcollective
[root@hadoop-master1 mcollective]# unalias cp
[root@hadoop-master1 mcollective]# cp -rf mcollective-package-agent-4.4.0/* mcollective/
[root@hadoop-master1 mcollective]# cp -rf mcollective-puppet-agent-1.10.0/* mcollective/
[root@hadoop-master1 mcollective]# cp -rf mcollective-service-agent-3.1.3/* mcollective/
[root@hadoop-master1 mcollective]# cp -rf mcollective-shell-agent-0.0.2/lib/mcollective/* mcollective/
[root@hadoop-master1 mcollective]# rm -rf mcollective-*

# 验证
[root@hadoop-master1 mcollective]# mco help
The Marionette Collective version 2.8.8

  completion      Helper for shell completion systems
  describe_filter Display human readable interpretation of filters
  facts           Reports on usage for a specific fact
  find            Find hosts using the discovery system matching filter criteria
  help            Application list and help
  inventory       General reporting tool for nodes, collectives and subcollectives
  package         Install, uninstall, update, purge and perform other actions to packages
  ping            Ping all nodes
  plugin          MCollective Plugin Application
  puppet          Schedule runs, enable, disable and interrogate the Puppet Agent
  rpc             Generic RPC agent client application
  service         Manages system services
  shell           Run shell commands

# 同步
[root@hadoop-master1 mcollective]# cd ..
[root@hadoop-master1 libexec]# rsync -az mcollective hadoop-master2:/usr/libexec/

# filter
[root@hadoop-master1 manifests]# mco shell run hostname -S "hostname=hadoop-master2"
[root@hadoop-master1 manifests]# mco ping -S "not hostname=hadoop-master1"
[root@hadoop-master1 manifests]# mco ping -S "! hostname=hadoop-master1"

[hadoop@hadoop-master1 ~]$ sudo mco shell --sort -I /cu-ud[1234]{1}$/ run -- ' ls /home/ud/ftpxdr | wc -l  '

# 少配置了
[root@hadoop-master1 manifests]# mco shell run "echo -e '\n\nplugin.puppet.command = /opt/puppetlabs/bin/puppet agent\nplugin.puppet.config = /etc/puppetlabs/puppet/puppet.conf' >> /etc/puppetlabs/mcollective/server.cfg" 


# 重启 mcollective 服务
[root@hadoop-master1 manifests]# mco shell run "echo service mcollective restart >/tmp/mcollective_restart.sh ; nohup sh /tmp/mcollective_restart.sh "


# ---
[root@hadoop-master1 dtarepo]# mco rpc package install package=lrzsz -I cu-omc1
[root@hadoop-master1 dtarepo]# mco rpc package install package=gmetad -I cu-omc1

mco rpc service start service=puppet
=> mco rpc --agent service --action start --argument service=puppet

mco plugin doc package

mco rpc service status service=puppet -S "environment=development"

mco puppet status
mco rpc puppet status


[root@hadoop-master1 gmond]# mco shell -I cu-ud2 run -- "/opt/puppetlabs/bin/puppet agent -t"
[root@hadoop-master1 production]# mco shell -I /^cu-omc2/ run -- "/opt/puppetlabs/bin/puppet agent -t"

# gmond 多网卡情况确认
[root@hadoop-master1 production]# route add -host 239.2.11.71 dev bond0

# puppet 基本语法
# https://docs.puppet.com/puppet/latest/reference/lang_conditional.html#if-statements
# https://docs.puppet.com/puppet/latest/reference/lang_relationships.html

# puppet使用tag可以更灵活的使用
# https://docs.puppet.com/puppet/latest/reference/lang_tags.html
apache::vhost {'docs.puppetlabs.com':
  port => 80,
  tag  => ['us_mirror1', 'us_mirror2'],
}

$ sudo puppet agent --test --tags apache,us_mirror1

再次强调Filter : Selecting Request Targets Using Filters

–END

Comments