一、什么是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、拓扑图
2、下载
操作系统RHEL6.3 x64
facter下载: https://downloads.puppetlabs.com/facter/
puppet下载: https://downloads.puppetlabs.com/puppet/
3、puppetmaster与puppetclient可以相互解析
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环境
1
|
[root@puppetmaster ~] # yum install -y ruby ruby-libs ruby-shadow
|
2、安装facter
1
2
3
|
[root@puppetmaster ~]# tar zxvf facter-1.7.3.tar.gz [root@puppetclient1 ~]# cd facter-1.7.3 [root@puppetmaster facter-1.7.3]# ruby install.rb |
3、安装配置puppet
1
2
3
4
5
6
7
|
[root@puppetmaster puppet-3.3.1] # useradd -s /sbin/nologin puppet
[root@puppetmaster ~] # tar zxvf puppet-3.3.1.tar.gz
[root@puppetclient1 ~] # cd puppet-3.3.1
[root@puppetclient1 puppet-3.3.1] # ruby install.rb
[root@puppetmaster puppet-3.3.1] # cp ext/redhat/puppet.conf /etc/puppet/
[root@puppetmaster puppet-3.3.1] # cp ext/redhat/server.init /etc/init.d/puppetmaster
[root@puppetmaster puppet-3.3.1] # chmod +x /etc/init.d/puppetmaster
|
1
2
3
|
[root@puppetmaster ~] # vi /etc/puppet/puppet.conf
[main] #在main里面添加puppet服务端主机名
server = puppetmaster.com |
1
2
3
|
[root@puppetmaster puppet-3.3.1] # chkconfig --add puppetmaster
[root@puppetmaster puppet-3.3.1] # chkconfig puppetmaster on
[root@puppetmaster puppet-3.3.1] # service puppetmaster start
|
四、安装客户端puppet agent
1、安装ruby环境
1
|
[root@puppetclient1 ~] # yum install -y ruby ruby-libs ruby-shadow
|
2、安装facter
1
2
3
|
[root@puppetclient1 ~]# tar zxvf facter- 1.7 . 3 .tar.gz
[root@puppetclient1 ~]# cd facter- 1.7 . 3
[root@puppetclient1 facter- 1.7 . 3 ]# ruby install.rb
|
3、安装配置puppet
1
2
3
4
5
6
|
[root@puppetclient1 puppet-3.3.1] # useradd -s /sbin/nologin puppet
[root@puppetclient1 ~] # tar zxvf puppet-3.3.1.tar.gz
[root@puppetclient1 puppet-3.3.1] # ruby install.rb
[root@puppetclient1 puppet-3.3.1] # cp ext/redhat/puppet.conf /etc/puppet/puppet.conf
[root@puppetclient1 puppet-3.3.1] # cp ext/redhat/client.init /etc/init.d/puppet
[root@puppetclient1 puppet-3.3.1] # chmod +x /etc/init.d/puppet
|
1
2
3
|
[root@puppetclient1 ~] # vi /etc/puppet/puppet.conf
[main] #在main里面添加puppet服务端主机名
server = puppetmaster.com |
1
2
3
4
|
[root@puppetclient1 puppet-3.3.1] # chkconfig --add puppet
[root@puppetclient1 puppet-3.3.1] # chkconfig puppet on
[root@puppetclient1 puppet-3.3.1] # service puppet start
[root@puppetclient1 puppet-3.3.1] # netstat -tupln | grep 8140
|
五、配置签名证书
1、客户端创建证书注册请求
1
2
3
4
5
6
|
[root@puppetclient1 ~] # 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、服务端查看证书注册请求
1
2
3
|
[root@puppetmaster ~] # 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、服务端受理客户端证书注册请求
1
2
3
|
[root@puppetmaster ~] # 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、客户端确认是否证书注册成功
1
|
[root@puppetclient1 ~] # puppet agent --test
|
如果出现以下报错,则在客户端puppet.conf配置文件[main]里面添加pluginsync=false,再重启!
1
|
Error: /File [ /var/lib/puppet/lib ]: Could not evaluate: Could not retrieve information from environment production source (s) puppet: //puppetmaster .com /plugins
|
5、想清除证书使用
1
|
[root@puppetmaster ~] # puppet cert clean puppetclient1.com
|
六、简单测试
1、服务端编写配置
1
2
3
4
5
6
7
8
|
[root@puppetmaster ~] # 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分钟同步一次
1
2
3
|
[root@puppetclient1 ~] # puppet agent --test
[root@puppetclient1 ~] # ls /tmp/
test .txt
|
至此,Puppet系统安装配置完成!
本文转自 李振良OK 51CTO博客,原文链接:http://blog.51cto.com/lizhenliang/1322710,如需转载请自行联系原作者