Puppet测试环境搭建

一.           Puppet介绍


Puppet是开源的自动化配置和部署工具,与cfengine相比,Puppet的语法更简单;对管理员屏蔽了底层的具体操作步骤,可以支持多种系统Linuxfreebsd等等,并且Puppet的代码是可以分享和重用的,避免了重复劳动同时弥补了脚本无法重用的缺陷。

 

二.             Puppet工作原理


工作原理如下:

1.       客户端puppetd调用facterfacter探测出主机的变量信息并且将这些信息通过ssl连接发送到服务器端

2.       服务器端puppetmaster检测客户端的主机名,然后找到manifest中对应的node配置,进行解析生成伪代码,并将伪代码发送给客户端

3.       客户端接受到伪代码并执行,将执行结果返回给服务器

4.       服务器把客户端的执行结果写入日志

Puppet使用的端口:814044361613 防火墙需要开放这几个端口

三.             测试环境搭建

测试环境列表:
Client1.centos192.168.2.101
Client2.centos 192.168.2.102
Client3.freebsd 192.168.2.99
Master.puppet 192.168.2.98

   Puppet需要和DNS结合,这里测试是写hosts文件

服务器端安装puppet-server,可以使用yum安装或者源码包编译安装

 
  
  1. [root@localhost ~]# yum install  puppet-server 

    启动puppetmaster服务:

 
  
  1. [root@localhost puppet]# /usr/sbin/puppetmasterd start 
  2.  
  3. [root@localhost puppet]# netstat -antup 
  4.  
  5. Active Internet connections (servers and established) 
  6.  
  7. Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
  8.  
  9. tcp        0      0 0.0.0.0:57771               0.0.0.0:*                   LISTEN      1699/rpc.statd      
  10.  
  11. tcp        0      0 0.0.0.0:8140                0.0.0.0:*                   LISTEN      15415/ruby 

    重启puppetmaster服务和将puppetmaster设置为自动启动

 
  
  1. [root@localhost puppet]# service  puppetmaster restart 
  2.  
  3. [root@master ~]# chkconfig  --level 345  puppetmaster on 

Centos客户端安装,使用EPEL源,直接yum安装puppet客户端

 
  
  1. [root@client1~]#rpm -ivh  http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm 
  2.  
  3. [root@localhost ~]# yum install  puppet 

    FreeBSD客户端的安装

 
  
  1. [root@nagios ~]# whereis puppet 
  2.  
  3. puppet: /usr/ports/sysutils/puppet 
  4.  
  5. [root@nagios ~]# cd /usr/ports/sysutils/puppet 
  6.  
  7. [root@nagios /usr/ports/sysutils/puppet]# make install clean 
  8.  
  9.   
  10.  
  11. [root@nagios ~]# vim /etc/rc.conf 
  12.  
  13. puppet_enable="YES" 
  14.  
  15. [root@nagios ~]# cd /usr/local/etc/puppet/ 
  16.  
  17. [root@nagios /usr/local/etc/puppet]# cp auth.conf-dist auth.conf      
  18.  
  19. [root@nagios /usr/local/etc/puppet]# cp puppet.conf-dist  puppet.conf 
  20.  
  21. [root@nagios ~]# vi puppet.conf 
  22.  
  23. [root@nagios ~]#  /usr/local/etc/rc.d/puppet  start 

    客户端的设置

 
  
  1. [root@client1 ~]# vim /etc/sysconfig/puppet 
  2.  
  3. # The puppetmaster server 
  4.  
  5. PUPPET_SERVER=Master.puppet 
  6.  
  7. # If you wish to specify the port to connect to do so here 
  8.  
  9. PUPPET_PORT=8140 
  10.  
  11. # Where to log to. Specify syslog to send log messages to the system log. 
  12.  
  13. PUPPET_LOG=/var/log/puppet/puppet.log 
  14.  
  15. # You may specify other parameters to the puppet client here 
  16.  
  17. PUPPET_EXTRA_OPTS=--waitforcert=500 

   重启客户端服务并加入自动启动

 
  
  1. [root@master ~]# service puppet start 
  2.  
  3. [root@client1 ~]#  chkconfig --level 345  puppet on 

   查看需要认证的客户端

 
  
  1. [root@master ~]# puppetca --list 
  2.  
  3.   client1.centos  (CD:3E:E5:F0:6A:0B:8B:52:B2:54:C7:AB:09:E7:E3:A1) 
  4.  
  5.   client2.centos  (F3:DF:25:77:7F:DF:37:5B:2B:18:EE:DC:7A:A6:F5:CA) 
  6.  
  7.   client3.freebsd (C4:93:76:65:49:34:18:FC:C7:68:9B:FD:02:D3:5F:CF) 

  认证所有的客户端

 
  
  1. [root@master ~]# puppetca  -s -a 

  认证某一台客户端

 
  
  1. [root@master ~]# puppetca --sign client1.centos 
  2.  
  3. notice: Signed certificate request for client1.centos 
  4.  
  5. notice: Removing file Puppet::SSL::CertificateRequest client1.centos at '/var/lib/puppet/ssl/ca/requests/client1.centos.pem' 

客户端连接测试

 
  
  1. [root@client1 ~]# puppetd --test --server master.puppet 
  2.  
  3. info: Caching catalog for client1.centos 
  4.  
  5. info: Applying configuration version '1329891537' 
  6.  
  7. notice: Finished catalog run in 0.01 seconds 

解决RDoc::usage问题

 
  
  1. [root@master ~]# puppetca --help 
  2.  
  3. No help available unless you have RDoc::usage installed 
  4.  
  5. [root@master ~]# yum install ruby-rdoc 
  6.  
  7. 安装ruby-rdoc后恢复