一、什么是puppet?
1、基于ruby语言开发的系统配置集中管理工具,跨平台
2、一个C/S架构,配置服务端和客户端
puppet依赖于ruby与facter,安装puppet3.x,需要ruby1.8.7版本及以上;facter是一个系统盘点工具,收集主机的一些资料,比如OS、IP、CPU等
3、puppet是一个C/S结构,开源软件,基于Ruby的系统配置管理工具,安装puppet3.x,需要ruby1.8.7版本及以上
4、默认情况下,客户端每隔30分钟连接一次puppet服务端
5、能管理多达40种资源,例如:file、user、cron、package、yum等,适合整个软件的生命周期管理
原理图:
1) 客户端通过facter收集客户端信息并发送至服务端
2) 连接服务端并请求catalog日志
3) 请求节点(node)的信息
4) 从服务器端接收节点(node)的实例
5) 编译代码(包括语法检查等工作)
6) 查询是否有exported 虚拟资源
7) 如有,则从数据库接收虚拟资源
8) 接收完整的catalog日志
9) 存储catalog日志到数据库
10) 客户端接收完整的catalog日志
二、我们怎样用puppet和实验环境介绍
1、拓扑图
系统管理员经常陷入一系列的重复任务中:如升级软件包、管理配置文件、系统服务、用户管理、cron任务以及添加新的配置、修复错误等。这些任务通常是重
复低效的,解决这类任务的第一反应是让他们自动化,于是出现了定制脚本。由于环境复杂,定制脚本和应用程序一再被重复开发,并且很难适合多种平台,灵活性
和功能也很难保证,于是像Puppet这样的自动化配置管理工具便出现了。
注:本次实验要检查防火墙确保8140端口开放.
禁用防火墙和SELinux
service iptables stop
chkconfig iptables off
setenforce 0
cat /etc/sysconfig/selinux <<EOF
SELINUX=disabled
SELINUXTYPE=targeted
EOF
2、下载
操作系统RHEL6.3 x64
facter下载: https://downloads.puppetlabs.com/facter/
puppet下载: https://downloads.puppetlabs.com/puppet/
3、puppetmaster与puppetclient可以相互解析(server和client都要如此)
vi /etc/hosts
192.168.0.200 puppetmaster.com
192.168.0.201 puppetclient1.com
4、puppet服务端与客户端时间同步
yum install ntp -y
service ntpd start
ntpdate pool.ntp.org #同步时间
clock -w #将时间写入硬件
chkconfig ntpd on
三、安装服务端puppet
1、安装ruby环境
[[email protected]petmaster ~]
# yum install -y ruby ruby-libs ruby-shadow ruby-rdoc
2、安装facter
安装puppet之前必须先安装facter
facter是一个系统盘点工具,收集主的一些资料,比如CPU,主机IP等,它收集到值发送给puppet服务器端,服务器端就可以根据不同的条件来对不同的节点机器生成不同的puppet配置文件
[[email protected] ~]# tar zxvf facter-1.7.3.tar.gz
[[email protected] ~]# cd facter-1.7.3
[[email protected] facter-1.7.3]# ruby install.rb
3、安装配置puppet
[[email protected] puppet-3.3.1]
# useradd -s /sbin/nologin puppet
[[email protected] ~]
# tar zxvf puppet-3.3.1.tar.gz
[[email protected] ~]
# cd puppet-3.3.1
[[email protected] puppet-3.3.1]
# ruby install.rb
[[email protected] puppet-3.3.1]
# cp ext/redhat/puppet.conf /etc/puppet/
[[email protected] puppet-3.3.1]
# cp ext/redhat/server.init /etc/init.d/puppetmaster
[[email protected] puppet-3.3.1]
# chmod +x /etc/init.d/puppetmaster
刚开始的话, puppet.conf不需要配置就可以满足。
[[email protected] ~]
# vi /etc/puppet/puppet.conf
[main]
#在main里面添加puppet服务端主机名
server = puppetmaster.com
设置puppetmaster 服务开机启动
[[email protected] puppet-3.3.1]
# chkconfig --add puppetmaster
[[email protected] puppet-3.3.1]
# chkconfig puppetmaster on
[[email protected] puppet-3.3.1]
# service puppetmaster start
注:要保证/var/lib/puppet/rrd目录存在且属主是puppet
- [[email protected] puppet]# ls -l /var/lib/puppet/
- total 36
- drwxr-x--- 2 puppet puppet 4096 Sep 3 12:17 bucket
- drwxr-xr-x 2 root root 4096 Sep 3 12:17 facts
- drwxr-xr-x 2 root root 4096 Sep 3 12:17 lib
- drwxr-x--- 2 puppet puppet 4096 Sep 3 12:17 reports
- drwxr-x--- 2 puppet puppet 4096 Sep 3 12:17 rrd
- drwxr-x--- 2 puppet puppet 4096 Sep 3 12:17 server_data
- drwxrwx--x 8 puppet root 4096 Sep 3 12:26 ssl
- drwxr-xr-t 2 root root 4096 Sep 3 12:17 state
- drwxr-x--- 2 puppet puppet 4096 Sep 3 12:17 yaml
要查看端口
- [[email protected] puppet]# netstat -Tanlp | grep 8140
- tcp 0 0 0.0.0.0:8140 0.0.0.0:* LISTEN 4556/ruby
四、安装客户端puppet agent
1、安装ruby环境
[[email protected] ~]
# yum install -y ruby ruby-libs ruby-shadow
ruby-rdoc
2、安装facter
[[email protected] ~]# tar zxvf facter-
1.7
.
3
.tar.gz
[[email protected] ~]# cd facter-
1.7
.
3
[[email protected] facter-
1.7
.
3
]# ruby install.rb
3、安装配置puppet
[[email protected] puppet-3.3.1]
# useradd -s /sbin/nologin puppet
[[email protected] ~]
# tar zxvf puppet-3.3.1.tar.gz
[[email protected] puppet-3.3.1]
# ruby install.rb
[[email protected] puppet-3.3.1]
# cp ext/redhat/puppet.conf /etc/puppet/puppet.conf
[[email protected] puppet-3.3.1]
# cp ext/redhat/client.init /etc/init.d/puppet
[[email protected] puppet-3.3.1]
# chmod +x /etc/init.d/puppet
[[email protected] ~]
# vi /etc/puppet/puppet.conf
Agent的配置主要是更改agent上的/etc/puppet/puppet.conf文件的[agent]部分。
在agent上vim /etc/puppet/puppet.conf 添加如下配置
server = puppetmaster.com
#master服务器的地址
runinterval = 3600 #每隔多久的时间进行自动更新,时间单位为秒
listen =true #客户端作为一个服务进行监听,允许其它的机器触发puppet运行允许远程触发puppet的节点配置
[[email protected] puppet-3.3.1]
# chkconfig --add puppet
[[email protected] puppet-3.3.1]
# chkconfig puppet on
[[email protected] puppet-3.3.1]
# service puppet start
[[email protected] puppet-3.3.1]
# netstat -tupln | grep 8140
注:要保证/var/lib/puppet/rrd目录存在且属主是puppet
[[email protected] puppet]# ls -l /var/lib/puppet/
- total 36
- drwxr-x--- 2 puppet puppet 4096 Sep 3 12:17 bucket
- drwxr-xr-x 2 root root 4096 Sep 3 12:17 facts
- drwxr-xr-x 2 root root 4096 Sep 3 12:17 lib
- drwxr-x--- 2 puppet puppet 4096 Sep 3 12:17 reports
- drwxr-x--- 2 puppet puppet 4096 Sep 3 12:17 rrd
- drwxr-x--- 2 puppet puppet 4096 Sep 3 12:17 server_data
- drwxrwx--x 8 puppet root 4096 Sep 3 12:26 ssl
- drwxr-xr-t 2 root root 4096 Sep 3 12:17 state
- drwxr-x--- 2 puppet puppet 4096 Sep 3 12:17 yaml
要查看端口
- [[email protected] puppet]# netstat -Tanlp | grep 8140
- tcp 0 0 0.0.0.0:8140 0.0.0.0:* LISTEN 4556/ruby
五、配置签名证书
1、客户端创建证书注册请求
[[email protected] ~]
# puppet agent --test
Info: Creating a new SSL key
for
puppetclient1.com
Info: Caching certificate
for
ca
Info: Creating a new SSL certificate request
for
puppetclient1.com
Info:
Certificate Request fingerprint (SHA256):
7E:10:48:3F:3C:D4:13:BA:BF:66:ED:86:52:92:19:05:1E:D2:3A:CD:06:67:27:80:60:D6:54:66:0E:33:F7:C7
Exiting; no certificate found and waitforcert is disabled
2、服务端查看证书注册请求
[[email protected] ~]
# puppet cert list #加--all查看所有
"puppetclient1.com"
(SHA256) 7E:10:48:3F:3C:D4:13:BA:BF:66:ED:86:52:92:19:05:1E:D2:3A:CD:06:67:27:80:60:D6:54:66:0E:33:F7:C7
"puppetclient1.com.com"
(SHA256) 46:B6:95:A6:1B:6A:FD:83:E4:1C:72:D4:5C:3C:B5:EF:3D:F7:43:2C:09:CF:00:B8:44:18:E4:3E:B3:DC:6F:FD
3、服务端受理客户端证书注册请求
[[email protected] ~]
# puppet cert sign puppetclient1.com #主机名改为--all,是受理所有
Notice: Signed certificate request
for
puppetclient1.com
Notice: Removing
file
Puppet::SSL::CertificateRequest puppetclient1.com at
‘/var/lib/puppet/ssl/ca/requests/puppetclient1.com.pem‘
4、客户端确认是否证书注册成功
[[email protected] ~]
# puppet agent --test
如果出现以下报错,则在客户端puppet.conf配置文件[main]里面添加pluginsync=false,再重启!
Error:
/File
[
/var/lib/puppet/lib
]: Could not evaluate: Could not retrieve information from environment production
source
(s) puppet:
//puppetmaster
.com
/plugins
5、想清除证书使用
[[email protected] ~]
# puppet cert clean puppetclient1.com
六、简单测试
1、服务端编写配置
[[email protected] ~]
# vi /etc/puppet/manifests/site.pp #修改后立即,无需重启
node
‘puppetclient1.com‘
{
#指定某台,也可以不写为所有
file
{
"/tmp/test.txt"
:
content=>
"hello,puppet test\n"
;
#source=> "puppet://$puppetserver/files/httpd.conf"
#也可以这样分发一个配置文件
}
}
注:file是一个资源管理关键字,用来管理文件的,还有package软件包管理,service管理系统服务,exec执行shell命令,/tmp/test.txt是创建文件名字,content定义文件内容
2、客户端默认30分钟与服务端同步配置文件,所以我们手动执行,也可以修改puppet.conf更改默认时间,添加runinterval=600,设置为10分钟同步一次
[[email protected] ~]
# puppet agent --test
[[email protected] ~]
# ls /tmp/
test
.txt
client端出现test.txt文件 至此,基本的puppet系统配置完成!
参考文章 http://56281688.blog.51cto.com/780901/1222560