Func 是红帽子公司 Fedora平台统一网络控制器python
Func(Fedora UnifiedNetwork Controller https://fedorahosted.org/func),目的是为了解决这一系列统一管理监控问题而设计开发的系统管理基础框架。能有效的简化多服务器系统管理工做的工具,易于学习,易于使用,易于扩展,并且功能强大。编程
Func的特色有:json
1、Func能够在主控机上一次管理任意多台或任意多个服务器组。centos
2、Func基于Certmaster(https://fedorahosted.org/certmaster/)创建了Master-Slaves主从SSL证书管控体系,能够将证书自动分发到全部受控服务器。服务器
3、Func命令行能够直接发送远程命令或者远程获取数据。网络
4、Func 开发者已经完成了大多数经常使用任务模块的开发,包括命令执行模块、文件传输模块、IPtables模块、查看硬件信息模块、Mount模块、进程模块、服务模块、重启系统模块等。框架
5、能够经过Func提供的Python API轻松编写扩展模块,以实现具体功能扩展。并且任何Func命令行能完成的工做,都能经过API编程实现。tcp
6、Func通信基于XMLRPC和SSL标准协议。ide
系统:Master : centos 5.8 x86 工具
Minion: centos 6.3 x86
配置hosts文件,使master与minions能够相互解析。
func安装
1、Master控制端配置
1.安装fedora发布的epel yum源,
rpm –Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
http://fedoraproject.org/wiki/EPEL
2.安装func
func基于certmaster,本次会一同安装,都在epel源里,我这里安装的时候提示少个依赖包python-simplejson,网上搜了一个(若是你的源里有的话能够不用下载)
wget ftp://ftp.pbone.net/mirror/ftp.centos.org/5.9/os/i386/CentOS/python-simplejson-2.0.9-8.el5.i386.rpm
rpm -ivh python-simplejson-2.0.9-8.el5.i386.rpm
yum install func
3.配置certmaster
vi/etc/certmaster/certmaster.conf
#configuration for certmasterd and certmaster-ca
[main]
autosign= no
listen_addr= 192.168.15.188 #监听IP,也能够不写
listen_port= 51235 #监听端口,本身定义
cadir =/etc/pki/certmaster/ca
cert_dir= /etc/pki/certmaster
certroot= /var/lib/certmaster/certmaster/certs
csrroot =/var/lib/certmaster/certmaster/csrs
cert_extension= cert
sync_certs = False
###############################################################
4.iptables容许,启动certmaster服务
#func
/sbin/iptables -A INPUT -s 192.168.15.183 -p tcp --dport 51235 -j ACCEPT
/sbin/iptables -A INPUT -s 192.168.1.200 -p tcp --dport 51235 -j ACCEPT
注意:Master端是启动certmaster服务,被控制端是启动funcd服务
#/etc/init.d/certmaster start
二 minion被控制端
1.安装epel
版本5
wgethttp://mirrors.yun-idc.com/epel/5/i386/epel-release-5-4.noarch.rpm
rpm -ivh epel-release-5-4.noarch.rpm
版本6
rpm –Uvh http://mirrors.yun-idc.com/epel/6/i386/epel-release-6-8.noarch.rpm
2.安装func
一样,仍是少这个包【应该5.5及如下的系统版本会少】,若是你的系统没有报错缺乏,能够跳过
wget ftp://ftp.pbone.net/mirror/ftp.centos.org/5.9/os/i386/CentOS/python-simplejson-2.0.9-8.el5.i386.rpm
rpm -ivh python-simplejson-2.0.9-8.el5.i386.rpm
yum install func
3.minions客户端配置
vi /etc/func/minion.conf
#configuration for minions
[main]
log_level= INFO #默认日志级别为debug
acl_dir =/etc/func/minion-acl.d
listen_addr=
listen_port= 51234 #默认端口被监控主机监听的端口
minion_name=
method_log_dir = /var/log/func/methods/
这里可选配置minion被控制端的监听地址,在/etc/func/minion.conf文件中,该监听端口用于响应master发送的指令。这个修改要在申请证书前完成,完成后不可修改。【因为没有了解到更深层的东西,因此端口的修改建议不要作,保留默认的51234端口。】
与certmaster关联配置
vi /etc/certmaster/minion.conf
#configuration for minions
[main]
certmaster= server.puppet.com #配置master的地址或master主机名【要可以互相解析】
certmaster_port= 51235 #服务端的侦听端口
log_level= DEBUG
cert_dir = /etc/pki/certmaster
4.启动funcd服务
/sbin/iptables -A INPUT -s 192.168.15.188 -p tcp --dport 51234 -j ACCEPT #容许master访问minions
/etc/init.d/funcd start
服务启动后会自动向master服务器提交证书申请
这个服务启动有没有成功都不会报错,若是有报错,会在日志 /var/log/func/func.log里,
注意:master链接minions时,要求minions监听在相同的端口
Funcd's listening port can be configured in /etc/func/minion.conf inthe listen_port option.
Overlord's will also check this file and setting todetermine which ports to connect to the minions with.Note that currentlyoverlord requires all minions to be listening on the same port.
若是以上都没有报错能够进行第三步证书签署,有报错先解决了。
三证书签署及验证操做
1. master服务器端
certmaster-ca –l 查看证书请求
certmaster-ca –s hostname 签署证书(这个hostname便是经过-l列出来的)为客户端签署证书
certmaster-ca--list-signed查看已经签署了哪些证书
2.以上的操做都能在日志里面看到,涉及的日志有
/var/log/certmaster/*
/var/log/func/*
3. 使用简例(master端)
1.列出有多少个minions
[root@Master_station~]# func "*" list_minions
myvmware_station.example.com
myvmware_station2.example.com
2. 查看minions是否都在线
[root@Master_station ~]# func "*" ping
[ ok ... ] myvmware_station.example.com
[ ok ... ] myvmware_station2.example.com
3.[root@server ~]#func "myvmware_station2.example.com" call cpu usage
有返回数据,则说明安装完成正常,具体使用语法参考其余资料。
4.在master端执行funcd --list-modules能够查看已有的模块。
四 命令使用示例
操做对象可使用正则匹配,能够列举多个【用分号对分隔】
funcd --list-modules
查看minions主机列表
func “*” list_minions
拷贝文件[拷贝到远端]
func "myvmware_statio*" copyfile -f /tmp/check_disk.sh --remotepath=/tmp/file1
判断文件是否存在
func "myvmware_statio*"call command exists /tmp/file1
执行脚本
func "myvmware_statio*"call command run " /tmp/file1"
删除使用的临时文件
func "myvmware_statio*"call command run "rm /tmp/file1"