puppet3.5源码包安装和配置
简介:puppet采用C/S星状的结构,所有的客户端和一个或几个服务器交互。每个客户端周期的(默认半个小时)向服务器发送请求,获得其最新的配置信息,保证和该配置信息同步。每个puppet客户端每半小时(可以设置)连接一次服务器端, 下载最新的配置文件,并且严格按照配置文件来配置服务器. 配置完成以后,puppet客户端可以反馈给服务器端一个消息. 如果出错,也会给服务器端反馈一个消息。
一、在master和client安装puppet
1、关闭iptables和selinux
2、在hosts添加master和client 主机信息
# vi /etc/hosts
192.168.1.10 master
192.168.1.11 client
3、在master上安装puppet
1)创建相关目录以及下载所需软件
# mkdir /tmp/soft/
# cd /tmp/soft/
# wget http://downloads.puppetlabs.com/puppet/puppet-3.5.1.tar.gz
# wget https://downloads.puppetlabs.com/facter/facter-2.0.1.tar.gz
# wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.gz
2)安装ruby
# tar fzvx ruby-2.1.2.tar.gz
# cd ruby-2.1.2
# ./configure --prefix=/usr/local/ruby
# make && make install
#添加环境变量
# vi /etc/profile.d/ruby.sh
export PATH=$PATH:/usr/local/ruby/bin
# source /etc/profile
#查看ruby版本信息
# ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877)
3)安装facter
# cd ..
# tar zfvx facter-2.0.1.tar.gz
# cd facter-2.0.1
# ruby install.rb
4)安装puppet
# cd ..
# useradd -M -s /sbin/nologin puppet
# tar fzvx puppet-3.5.1.tar.gz
# cd puppet-3.5.1
# ruby install.rb
# cp ext/redhat/puppet.conf /etc/puppet/puppet.conf
# vi /etc/puppet/puppet.conf
#在中增加:
server = master #master的主机名
certname = master #master的主机名
pluginsync = false
5)启动puppet
# puppet master
# ps -ef |grep master
puppet 11503 10 12:24 ? 00:00:01 /usr/local/ruby/bin/ruby /usr/local/ruby/bin/puppet master
4、在client上安装puppet
1)安装ruby
# tar fzvx ruby-2.1.2.tar.gz
# cd ruby-2.1.2
# ./configure --prefix=/usr/local/ruby
# make && make install
#添加环境变量
# vi /etc/profile.d/ruby.sh
export PATH=$PATH:/usr/local/ruby/bin
# source /etc/profile
#查看ruby版本信息
# ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877)
2)安装facter
# cd ..
# tar zfvx facter-2.0.1.tar.gz
# cd facter-2.0.1
3)安装puppet
# cd ..
# useradd -M -s /sbin/nologin puppet
# tar fzvx puppet-3.5.1.tar.gz
# cd puppet-3.5.1
# ruby install.rb
# cp ext/redhat/puppet.conf /etc/puppet/puppet.conf
# vi /etc/puppet/puppet.conf
#在中增加:
server = master #master的主机名
pluginsync = false
二、puppet证书认证
puppet为了安全,采用ssl隧道通信,因此需要申请证书来验证的。
1)Client agent连接server
# puppet agent --server=master 2)在master上查看申请证书请求
# puppet cert --list
"client" (SHA256) 02:EC:D4:CD:02:29:D2:31:3A:CA:9A:56:BD:4C:85:71:6A:8B:80:EB:E5:96:5D:97:41:C5:89:F5:23:B9:F6:97
3)在master上签发证书
# puppet cert --sign client
Notice: Signed certificate request for client
Notice: Removing file Puppet::SSL::CertificateRequest client at '/etc/puppet/ssl/ca/requests/client.pem'
#查看证书, " + " ,表示已经签名成功
# puppet cert -all
+ "client" (SHA256) 1F:41:43:6E:34:0E:69:4D:5C:51:40:92:57:CA:5F:F0:98:58:11:38:D6:2B:46:67:63:55:6E:DC:7E:F2:BC:BA
+ "master" (SHA256) DF:31:4C:9A:89:FF:34:7B:87:81:0D:03:B8:86:66:78:44:BD:02:6D:C1:C9:1F:0A:27:54:8A:31:32:47:1F:07
三、内容同步验证
1)在master上创建一个site.pp文件
# vi /etc/puppet/manifests/site.pp
node default { file { "/tmp/test.txt": content => "Hello, First puppet test!"} }
2)在client机进行验证,如果/tmp/test.txt文件生成并有内容,则说明功能正常。
# puppet agent --test
Info: Caching certificate for client
Info: Caching certificate_revocation_list for ca
Info: Caching certificate for client
Info: Caching catalog for client
Info: Applying configuration version '1403072815'
Notice: /Stage/Main/Node/File/ensure: defined content as '{md5}390b4c389233b9ae38a84ff8c731a8a1'
Info: Creating state file /var/lib/puppet/state/state.yaml
Notice: Finished catalog run in 0.04 seconds
#查看/tmp/目录
# cat /tmp/test.txt
Hello, First puppet test!
页:
[1]