Func 是红帽子公司 Fedora平台统一网络控制器

FuncFedora UnifiedNetwork Controller https://fedorahosted.org/func),目的是为了解决这一系列统一管理监控问题而设计开发的系统管理基础框架。能有效的简化多服务器系统管理工作的工具,易于学习,易于使用,易于扩展,而且功能强大。

Func的特点有:

1Func可以在主控机上一次管理任意多台或任意多个服务器组。

2Func基于Certmasterhttps://fedorahosted.org/certmaster/)建立了Master-Slaves主从SSL证书管控体系,可以将证书自动分发到所有受控服务器。

3Func命令行可以直接发送远程命令或者远程获取数据。

4Func 开发者已经完成了大多数常用任务模块的开发,包括命令执行模块、文件传输模块、IPtables模块、查看硬件信息模块、Mount模块、进程模块、服务模块、重启系统模块等。

5、可以通过Func提供的Python API轻松编写扩展模块,以实现具体功能扩展。而且任何Func命令行能完成的工作,都能通过API编程实现。

6Func通讯基于XMLRPCSSL标准协议。


系统:Master : centos 5.8 x86

Minion: centos 6.3 x86

配置hosts文件,使masterminions可以相互解析。

func安装

一、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"