Puppet整合Foreman(六):Mcollective命令

一、測試

[root@puppetmaster ~]# mco find 
puppetagent.ewin.com 
[root@puppetmaster ~]# mco ping
puppetagent.ewin.com                     time=91.49 ms
---- ping statistics ----
1 replies max: 91.49 min: 91.49 avg: 91.49

      windows客戶端查看日誌

C:\mcollective\mcollective.log
        E, [2015-05-14T14:58:24.057800 #2608] ERROR -- : agents.rb:71:in `rescue in loadagent' Loading agent puppet failed: Could not create instance of plugin MCollective::Agent::Puppet: cannot load such file -- puppet

    分析問題是ruby加載puppet插件未成功報錯,最終找到原因是mcollective主配置文件server.cfg中 libdir = C:\mcollective\plugins中只指向了mcollective的lib庫,並沒有找到puppet和facter的lib庫導致!因此需要在libdir中添加puppet和facter的lib庫路徑libdir = C:\mcollective\plugins;C:\Puppet Labs\ Puppet\puppet\lib;C:\Puppet Labs\Puppet\facter\libdir


二、命令

    mco facts      #使用fact信息顯示報告
    mco inventory  #來自nodes\collectives\subcollectives報告工具
    mco nettest    #測試節點網絡和連接
    mco nrpe       #調用NRPE工具,返回監控信息
    mco package    #軟件包的安裝卸載升級
    mco plugin     #MC插件
    mco puppet     #管理puppet agent程序
    mco rpc        #利用RPC程序進行交互
    mco service    #管理系統服務

三、過濾

    mco rpc service status service=puppet -S "environment=development"  #-S可使用and or !
    mco ping --with-agent service        #--with-agent 或 -A
    mco ping --with-class apache        #--with-class 或 -C
    mco ping -C /service/
    mco ping --with-fact country=uk     #--with-fact 或 -F
    mco ping -I hostname01 -I hostname02


四、管理

1、驗證Agent插件

    mco inventory puppetagent.ewin.com
Inventory for puppetagent.ewin.com:
   Server Statistics:
                      Version: 2.8.1
                   Start Time: Thu Apr 23 14:35:39 +0800 2015
                  Config File: /etc/mcollective/server.cfg
                  Collectives: mcollective
              Main Collective: mcollective
                   Process ID: 12301
               Total Messages: 14
      Messages Passed Filters: 14
            Messages Filtered: 0
             Expired Messages: 0
                 Replies Sent: 13
         Total Processor Time: 5.69 seconds
                  System Time: 1.8 seconds
   Agents:
      discovery       puppet          rpcutil        
      service        
   Data Plugins:
      agent           collective      fact           
      fstat           puppet          resource       
      service                                        
   Configuration Management Classes:
      No classes applied
   Facts:
      mcollective => 1

    Data Plugins下列出了puppet說明插件安裝成功。

2、查看puppet狀態信息

    mco puppet status
 * [ ==========================================================> ] 1 / 1
   puppetagent.ewin.com: Currently stopped; last completed run 27 seconds ago
Summary of Applying:
   false = 1
Summary of Daemon Running:
   stopped = 1
Summary of Enabled:
   enabled = 1
Summary of Idling:
   false = 1
Summary of Status:
   stopped = 1
Finished processing 1 / 1 hosts in 70.91 ms

 3、查看agent的puppet狀態

    mco rpc puppet status
* [ ==========================================================> ] 1 / 1
puppetagent.ewin.com                     
         Applying: false
   Daemon Running: false
     Lock Message:
          Enabled: true
           Idling: false
         Last Run: 1429771233
          message: Currently stopped; last completed run 1 minutes 18 seconds ago
   Since Last Run: 78
           Status: stopped

 4、強制讓所有客戶端運行agent

    mco puppet runonce -v
Discovering hosts using the mc method for 2 second(s) .... 1
 * [ ==========================================================> ] 1 / 1
puppetagent.ewin.com                    : OK
    {:initiated_at=>1429771209,     :summary=>      "Started a Puppet run using the 'puppet agent --onetime --no-daemonize --color=false --show_diff --verbose --splay --splaylimit 30' command"}
---- rpc stats ----
           Nodes: 1 / 1
     Pass / Fail: 1 / 0
      Start Time: Thu Apr 23 14:40:13 +0800 2015
  Discovery Time: 2004.83ms
      Agent Time: 89.65ms
      Total Time: 2094.48ms

5、強制讓指定客戶端運行agent

    mco puppet runonce -I puppetagent.ewin.com -v


五、shell插件

shell插件可以遠程執行客戶端的shell命令,例如:

    mco shell "cat /etc/passwd | grep puppet"

http://projects.puppetlabs.com/projects/mcollective-plugins/wiki/InstallingPlugins


更多插件在:

https://github.com/puppetlabs/mcollective-plugins

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章