系统版本 ip地址 主机名
centos6.5_x64 192.168.0.153 master (puppetmaster代表服务端)
centos6.5_x64 192.168.0.154 node1 (agent代表客户端)
修改master和node1的hosts文件,添加主机名和ip映射:
192.168.0.154 node1
192.168.0.153 master
master和node1安装epel源(或者用puppet官方源):
[root@master ~]# yum install -y epel-*
[root@node1 ~]# yum install -y epel-*
master安装服务端:
[root@master ~]# yum install -y ruby ruby-libs ruby-shadow puppet puppet-server facter
node1安装客户端:
[root@node1 ~]# yum install -y ruby ruby-libs ruby-shadow puppet facter
master配置:
主目录为/etc/puppet/
auth.conf #定义puppet master的acl文件
environments #这个可能在3.x版本上才有
fileserver.conf #定义puppet master文件服务器的配置文件
manifests #puppet脚本主文件目录,site.pp文件必须存在
modules #puppet模块目录
puppet.conf #puppet主配置文件
默认不需要太多配置,先保持默认。
启动服务。
[root@master ~]# service puppetmaster start
默认占用8140端口,在防火墙中放行,或关闭iptables。
node1配置:
/etc/puppet/puppet.conf
[agent]
classfile = $vardir/classes.txt
localconfig = $vardir/localconfig
server = master #设置master
runinterval = 5s #探测master时间间隔 s/m/h/d/y 分别为秒/分/时/年 数字零0代表立即
listen = true
保存退出,启动服务。
[root@node1 ~]# service puppet start
客户端在puppetmaster登记:
[root@master ~]# puppet agent –test
Exiting; no certificate found and waitforcert is disabled #出现此错误为正常,因为客户端还没有在master登记。
master检查证书请求:
[root@master ~]# puppet cert list
“node1” (B8:96:46:DD:B7:1C:21:8B:3A:2E:3B:6E:35:96:81:B1)
会看到一个包含计算机名的请求,对此请求签名:
[root@master ~]# puppet cert sign node1
notice: Signed certificate request for node1
notice: Removing file Puppet::SSL::CertificateRequest node1 at ‘/var/lib/puppet/ssl/ca/requests/node1.pem’
node1再次查看登记:
[root@node1 certs]# puppet agent –test
info: Caching certificate for node1
info: Caching certificate_revocation_list for ca
info: Caching catalog for node1
info: Applying configuration version ‘1422335958’
info: Creating state file /var/lib/puppet/state/state.yaml
notice: Finished catalog run in 0.03 seconds
配置差不多就完成了,现在测试对客户端发布命令,安装nmap、wget软件:
[root@master ~]# vi /etc/puppet/manifests/site.pp #创建配置文件
node 'node1' { include install_rpm } class install_rpm { package { ["nmap","wget"]: ensure => latest, } }
重启服务:
[root@master ~]# service puppetmaster restart
客户端根据上面配置是5秒跟master通信一次,如果想立即执行master下发的任务就执行:
[root@node1 ~]# puppet agent -t
node1上过5秒查看进程:
调试方法:
puppet agent -t #使用“-t”选项,你可以看到puppet的详细输出。 puppet agent -t --debug #debug 选项会显示puppet本次运行时的差不多每一个步骤。 puppet agent -t --noop #让 puppet 工作在dry-run模式下,不会应用任何修改,不会对真实环境产生影响。
原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/3227.html