2011年(264)
分类: 系统运维
2011-04-06 22:55:38
一、技术框架选型
Puppet: 集中配置管理。应用了它的facter采集被控服务器的外网IP、内网IP、主机名
在服务器接入到机房配置好唯一外网IP之后将数据传递回主控制机。从而将这台服务器的IP相关信息获取。通过它我们可以实现服务器KS安装OS之后配置外网IP之后的自动化。
Func: 红帽子出产的集中式管理工具。它的优势是我们可以在主控机上面往所有被控机发送指令、调用指定的模块进行命令操作。应用它的主要目的是把一些操作主动发送到被控机器执行之后反馈得到结果。
二、搭建步骤
搭建可以分为两步:安装服务器端与安装客户端
Certmaster服务器端安装命令:
#yum install func
配置文件如下:
[root@xx certmaster]# more /etc/certmaster/certmaster.conf
# configuration for certmasterd and certmaster-ca
[main]
autosign = yes
listen_addr =
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
[root@xx certmaster]# more /etc/certmaster/minion.conf
# configuration for minions
[main]
certmaster = 主控机的HOSTNAME
certmaster_port = 51235
log_level = DEBUG
cert_dir = /etc/pki/certmaster
存放证书的位置
[root@xx certmaster]# more /etc/func/minion.conf
# configuration for minions
[main]
log_level = ERROR
acl_dir = /etc/func/minion-acl.d
listen_addr =
listen_port = 51234
安装puppet的master服务
1、 修改主机的HOSTNAME
2、 安装
#yum install -y puppet-server 安装服务端
#service puppetmaster start 将服务启动
#chkconfig --level 2345 puppetmaster on 将其添加进启动服务
3、 编写M端的配置文件
[puppetmasterd]
environment = production
reports = myreport
logdir = /var/log/puppet
modulepath = /etc/puppet/modules:/usr/share/puppet/modules
config = /etc/puppet/puppet.conf
manifestdir = /etc/puppet/manifests
manifest = /etc/puppet/manifests/site.pp
fileserverconfig = /etc/puppet/fileserver.conf
templatedir = /etc/puppet/templates
reportdir = /var/lib/puppet/reports
autosign=true
clientyamldir = /var/lib/puppet/client_yaml
客户端安装《通过Rpm包安装puppet与func》
三、服务器端自定义报表采集脚本
存放目录:/usr/lib/ruby/site_ruby/1.8/puppet/reports/
文件内容:
$ams_url=""
require 'puppet'
require 'net/http'
require 'uri'
Puppet::Reports.register_report(:mytest) do
Puppet.settings.use(:reporting)
desc "Sends reports directly to Foreman"
def process
begin
uri = URI.parse($ams_url)
http = Net::HTTP.new(uri.host, uri.port)
if uri.scheme == 'https' then
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
req = Net::HTTP::Post.new("/myreport.php")
req.set_form_data({'report' => to_yaml})
response = http.request(req)
rescue Exception => e
raise Puppet::Error, "Could not send report to mytest at #{$ams_url}/reports/create?format=yml: #{e}"
end
end
end
这个程序的作用是将puppet客户端发过来的数据提交到一个自定义接口myreport.php里面
这样就可以实现当安装了客户端之后在服务器端就会看到认证的主机列表。