puppet安装

安装准备

服务端跟客户端均关闭防火墙

[root@puppet01 ~]# service iptables stop
[root@puppet01 ~]# chkconfig iptables off

服务端跟客户端关闭修改selinux

[root@puppet01 ~]# sed -i ‘SELINUX/s/enforce/disabled’ /etc/selinux/config

服务端跟客户端修改hosts文件

[root@puppet01 ~]# cat /etc/hosts
1
2
3
4
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.231 puppetserver
192.168.1.232 puppetclient

安装步骤

服务端:

[root@puppet01 ~]# rpm -Uvh http://yum.puppetlabs.com/el/6/products/i386/puppetlabs-release-6-6.noarch.rpm
[root@puppet01 ~]# yum install puppet-server -y

客户端:

[root@puppet01 ~]# rpm -Uvh #rpm -Uvh http://yum.puppetlabs.com/el/6/products/i386/puppetlabs-release-6-6.noarch.rpm
[root@puppet01 ~]# yum install puppet -y

服务端开启puppetmaster服务

[root@puppet01 ~]#/etc/init.d/puppetmaster start

客户端证书申请

[root@puppet01 ~]#puppet agent –server puppetserver –test

服务端查看证书是否生成

[root@puppet01 ~]# puppet cert –list

服务端颁发证书

可以为特定的主机颁发证书命令:

[root@puppet01 ~]# puppet cert -s

给所有的主机颁发证书命令:

[root@puppet01 ~]# puppet cert -s and -a

为客户端颁发证书:

[root@puppet01 ~]#puppet cert –s puppetclient #后面是主机名

客户端/tmp下面创建test.txt文件

[root@puppet01 ~]# touch test.txt

服务端下面编辑site.pp

1
2
3
4
5
6
vi /etc/puppet/manifests/site.pp
node default {
file {
“/tmp/test.txt”: content => “helo,test!”;
}
}

客户端测试

[root@puppet01 ~]# puppet agent –server puppetserver –test

puppet自动认证

在服务端的puppet.conf配置文件里面[main]下方加入
autosign = true
然后重启puppetmaster服务。
这样在客户端执行puppetd -server=puppetserver -test服务端会自动认证

重新生成证书:

因为很多时候需要更换主机名称,所以需要重新认证
首先在客户端删除:

[root@puppet01 ~]# rm -rf /var/lib/puppet/ssl 文件夹

然后在服务端删除:

[root@puppet01 ~]# puppet cert –clean puppetclient

最后重新获取证书:

[root@puppet01 ~]#puppet agent –server puppetserver -test

配置客户端自动同步:

客户端配置puppet相关参数和同步时间:

[root@puppet01 ~]# vi /etc/puppet/sysconfig/puppet
1
2
3
4
5
6
7
8
# 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 服务

[root@puppet01 ~]# /etc/init.d/puppet start

修改同步的时间间隔:

[root@puppet01 ~]# vim /etc/puppet/puppet.conf

在[agent]下方加入:runinterval = 60
代表是60秒跟服务器同步一次

最后重启puppet服务

[root@puppet01 ~]# /etc/init.d/puppet start

puppetrun的使用(puppet kick)

在服务器端使用puppetrun这个命令可以给客户端发送一段信号,告诉客户端立刻跟服务器同步

修改客户端上的puppet配置文件

[root@puppet01 ~]# vim /etc/puppet/puppet.conf

在[agent]下方添加

1
listen = true #目的是让puppet监听8139端口

修改客户端的puppet的/etc/sysconfig/puppet文件

[root@puppet01 ~]# vim /etc/sysconfig/puppet
[root@puppet01 ~]# PUPPET_SERVER=puppetserver #server主机名称

####在客户端新建namespaceauth.conf文件
[puppetrunner]
allow *

在客户端修改auth.conf,在 paht / 的前面添加以下内容:

1
2
3
4
#test
path /run
method save
allow *

最后重启puppet服务

[root@puppet01 ~]# /etc/init.d/puppet restart

在服务端测试命令:

[root@puppet01 ~]# puppet kick -d host puppetclient

code 0表示成功