关于puppet的说明这里就不详细介绍了,下面我们直接开始puppet的部署安装吧!
特别说明:请注意客户端和服务器端版本要一致。如果版本不一致的话,那么高版本的只能是puppet server,另一台只能作为puppet客户端,也就是说puppet 服务端的版本可以大于或者等于客户端版本。
1.关闭防火墙
[root@puppet01~]service iptables stop
[root@puppet01~]chkconfig iptables off
2.设置selinux
[root@puppet01~]sed -i's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
3.修改服务端跟客户端hosts文件,添加IP和主机名称
[root@puppet01~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4localhost4.localdomain4
::1 localhost localhost.localdomainlocalhost6 localhost6.localdomain6
192.168.1.231 puppetserver
192.168.1.232 puppetclient
4.服务端安装puppetmaster
rpm-Uvh
yum install puppet-server –y
5.客户端安装puppet
rpm-Uvh
yum install puppet -y
6.服务端开启puppetmaster服务
/etc/init.d/puppetmasterstart
7.客户端证书申请
puppetagent --server puppetserver --test
8.服务端查看证书是否生成
[root@puppet01~]# puppet cert --list
"puppet02" (SHA256)36:1F:C6:80:48:66:90:52:87:3B:55:AB:6C:66:31:3F:33:35:CF:AE:8A:3A:BA:F9:D0:70:EE:C2:3F:FD:23:9C
9.服务端颁发证书
1.可以为特定的主机颁发证书命令:puppetcert –s
2.给所有的主机颁发证书命令:puppetcert –s and –a
为客户端颁发证书:
puppetcert --s puppetclient #后面是主机名
10.客户端/tmp下面创建个test.txt文件,做测试
touchtest.txt
#服务端下面编辑site.pp
vi /etc/puppet/manifests/site.pp
node default {
file {
"/tmp/test.txt": content => "helo,test!";
}
}
11.客户端测试
puppetagent --server puppetserver --test
成功信息:
Info:Caching certificate for puppetclient
Info:Caching certificate_revocation_list for ca
Info:Caching certificate for puppetclient
Info:Retrieving pluginfacts
Info:Retrieving plugin
Info:Caching catalog for puppetclient
Info:Applying configuration version '1426557149'
Notice:/Stage[main]/Main/Node[default]/File[/tmp/test.txt]/content:
---/tmp/test.txt 2015-03-1621:51:08.889040996 -0400
+++/tmp/puppet-file20150316-1468-1n3cxlt-0 2015-03-1621:52:29.746041636 -0400
@@-0,0 +1 @@
+hello,test!
\No newline at end of file
Info:Computing checksum on file /tmp/test.txt
Info:/Stage[main]/Main/Node[default]/File[/tmp/test.txt]: Filebucketed /tmp/test.txtto puppet with sum d41d8cd98f00b204e9800998ecf8427e
Notice:/Stage[main]/Main/Node[default]/File[/tmp/test.txt]/content: content changed'{md5}d41d8cd98f00b204e9800998ecf8427e' to'{md5}18ea2a60db7763506261f87ecb82fb96'
Info:Creating state file /var/lib/puppet/state/state.yaml
Notice:Finished catalog run in 0.05 seconds
12.设置puppet自动认证
在服务端的puppet.conf配置文件里面[main]下方加入
autosign= true
然后重启puppetmaster服务。
#这样在客户端执行puppetd –server=puppetserver --test服务端会自动认证
13.重新生成证书:
因为很多时候需要更换主机名称,所以需要重新认证
1.首先在客户端删除:rm –rf /var/lib/puppet/ssl文件夹
2.然后在服务端删除:puppet cert--clean puppetclient
3.最后重新获取证书:puppet agent--server puppetserver --test
14.客户端配置puppet相关参数和同步时间:
vi /etc/puppet/sysconfig/puppet
#The puppetmaster server
PUPPET_SERVER=puppetserver
#If you wish to specify the port to connect to do so here
PUPPET_PORT=8140
#Where to log to. Specify syslog to send log messages to the system log.
PUPPET_LOG=/var/log/puppet/puppet.log
#You may specify other parameters to the puppet client here
PUPPET_EXTRA_OPTS=--waitforcert=500
#最后重启puppet 服务
/etc/init.d/puppetstart
#默认配置完毕后,客户端是半小时同步一次的,我们可以修改同步的时间间隔:
vim/etc/puppet/puppet.conf
#在[agent]下方加入:runinterval = 60
#代表是60秒跟服务器同步一次
#最后重启puppet服务
/etc/init.d/puppetstart
15.puppetrun的使用(puppet kick)
#在服务器端使用puppetrun这个命令可以给客户端发送一段信号,告诉客户端立刻跟服务器同步
1. 修改客户端上的puppet配置文件
vim /etc/puppet/puppet.conf
在[agent]下方添加
listen = true #目的是让puppet监听8139端口
2. 修改客户端的puppet的/etc/sysconfig/puppet文件
vim /etc/sysconfig/puppet
PUPPET_SERVER=puppetserver #server主机名称
3. 在客户端新建namespaceauth.conf文件
[puppetrunner]
allow *
4. 在客户端修改auth.conf,在 paht / 的前面添加以下内容:
#test
path /run
method save
allow *
5. 最后重启puppet服务
/etc/init.d/puppet restart
6. 在服务端测试命令:
puppet kick –d host puppetclient
#code 0表示成功