查看已有模塊
linux
funcd --list-modulesnginx
查看minions主機列表web
func 「*」 list_minionsjson
==========================================================================ide
1、call 模塊用於運行遠端minions主機的func模塊,格式以下:函數
THE "CALL" MODULEspa
The "call" module is used for running func modules remotely.firefox
Format: func"*.example.org" call <module> <function> [ args ... ]orm
2、查看遠端minions主機能夠使用的moduleserver
LISTING REMOTE MODULES AVAILABLE
It’s possible to ask func minions what modules they have installed:
func "*.example.org" call system list_modules
3、查看遠端可用的functions
LISTING REMOTE FUNCTIONS AVAILABLE IN AMODULE
It is also possible to ask remote func modules what functions theysupport:
func target.example.org call modulename list_methods
4、查看遠端某模塊功能函數的可用參數
語法:func "web1"call modulename get_method_args
func " myvmware_station.example.com" call mount get_method_args
5、定義func的輸出格式【緊跟在call以後,不要在模塊後,模塊後爲方法,參數;不然就會被做爲參數,而沒法執行】
OUTPUT FORMATS
The "call" command by default outputs data using a"pretty printer". Otherdisplay options include --raw, --json, and --xmlrpc, which may be
more desirable if you are running func inside another script or preferto read those display formats.
Example: func "*" call --json service inventory
===============================================================================
模塊使用簡介
參照:https://fedorahosted.org/func/wiki/ModulesList
Copy File 用於從master拷貝文件到遠端minions,對於小文件頗有用,能夠替換scp。
functarget.example.org copyfile -f localfile--remotepath /remotepath/filename
PullFile
Thismodule makes it easy to pull a file (from a web/ftp server) and store itlocally.
func 「*」 call pullfile get http://testserver/super.conf /tmp/file1.txt
CommandModule
func target.example.org call command exists /bin/foo
func target.example.org call command run "/bin/foo arg1 arg2arg3"
注意斷定文件是否存在時,執行func命令的用戶要對該文件有執行權限,以下示例:【因此func只能夠斷定目錄、可執行文件存在與否】
[root@Master_station install]# func"myvmware_station.example.com" call command exists /tmp/f1 【/tmp/f1 是普通文件】
{'myvmware_station.example.com': False}
[root@Master_station install]#
[root@Master_station install]# func"myvmware_station.example.com" call command run "chmod u+x/tmp/f1" 【爲/tmp/f1 添加可執行權限】
('myvmware_station.example.com', [0, '',''])
[root@Master_station install]# func"myvmware_station.example.com" call command exists /tmp/f1
{'myvmware_station.example.com': True}
[root@Master_station install]#
[root@Master_station install]# func"myvmware_station.example.com" call command exists /etc 【斷定 /etc 存在與否】
{'myvmware_station.example.com': True}
[root@Master_station install]#
[root@Master_station install]# func"myvmware_station.example.com" call command run "ls -dl /etc/" 【查看目錄權限】
('myvmware_station.example.com',
[0,'drwxr-xr-x. 103 root root 12288 Oct 10 10:43 /etc/\n', ''])
CpuModule
func target.example.org call cpu usage
func target.example.org call cpu jiffies
DiskModule
functarget.example.org call disk usage
HardwareModule
functarget.example.org call hardware info
NetworkTest
Takes in all commands that ping takes via*args magic. You must define -c!【必須定義 -c】
func 「*」 call networktest ping www.baidu.com -c 2
func「*」 call networktest netstat
func「*」 call networktest isportopen localhost22 【全部minions本機的22端口開放狀況】
Iptablesmodule
Theiptables module can be used to make basic changes in your firewallconfiguration. It currently only supports modifying filter table.【目前僅支持filter表】
func"*" call iptables policy
[root@Master_station~]# func "*" call iptables drop_from 192.168.0.10 【丟棄來自192.168.0.10的包】
{'myvmware_station.example.com': 0, 'myvmware_station2.example.com':0}
[root@Master_station ~]# func"myvmware_station2.example.com" call iptables.port drop_to 53192.168.0.0/24 udp src 【丟棄到192.168.0.0/24的udp 53端口的數據包。】
{'myvmware_station2.example.com': 0}
Set default policy for OUTPUT:
func '*' call iptables policy OUTPUT DROP
Run '/sbin/iptables' command with arguments given.
func '*' calliptables run "-L INPUT"
func '*' call command run"iptables -nvL"
Mount Module
func target.example.org call mount /dev/device /path/to/dir
ProcessModule
functarget.example.org call process info "aux"
func target.example.org call process mem
func "*" call process pkill nginx -9 殺掉全部minions主機的nginx進程
func "*" call process kill firefox-bin SIGHUP
Service Module
functarget.example.org call service start httpd
Sysctl Module
Configure your minions kernel parameters at runtime.
Command line usage:
func"*" call sysctl list
func"*" call sysctl get <parameter>
func"*" call sysctl set <parameter> <value>
YumcmdModule
func target.example.org call yumcmd check_update
func target.example.org call yumcmd install [pkg]
func target.example.org call yumcmd update [pkg]
func target.example.org call yumcmd remove [pkg]
生產應用場景示例:
想更改全部linux主機的監控由之前的常數檢測,改成經過傳參來實現更合理監控,經過func管理,腳原本實現。
1、爲全部minions主機拷貝腳本文件
func "web_*" copyfile -f /tmp/check_disk.sh --remotepath=/tmp/file1
判斷文件是否存在【是否上傳成功】
func "web_*"call command exists /tmp/file1
2、在全部minions主機上執行腳本
func "web_*"call command run " /tmp/file1"
刪除使用的臨時文件
func "web_*"call command run "rm /tmp/file1"
再次判斷是否存在【確認是否刪除成功】
func "web_*"call command exists /tmp/file1