puppet安装配置及测试

#服务端跟客户端均关闭iptables

serviceiptables stop

chkconfigiptables off

 

#服务端跟客户端均关闭修改selinux
sed -i 'SELINUX/s/enforce/disabled' /etc/selinux/config

 

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

[root@puppet01~]# cat /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomainlocalhost6 localhost6.localdomain6

192.168.1.231puppetserver

192.168.1.232puppetclient

 

#服务端:

rpm-Uvh http://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-1.noarch.rpm

yuminstall puppet-server �Cy

 

 

 

#客户端:

rpm-Uvh http://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-1.noarch.rpm

yuminstall puppet -y 

 

 

#服务端开启puppetmaster服务

/etc/init.d/puppetmasterstart

 

#客户端证书申请

puppetagent --server puppetserver--test

 

#服务端查看证书是否生成

[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

 

#服务端颁发证书

#可以为特定的主机颁发证书命令:puppetcert �Cs

#给所有的主机颁发证书命令:puppetcert �Cs and �Ca

#为客户端颁发证书:

puppetcert --s puppetclient #后面是主机名

 

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

touchtest.txt

#服务端下面编辑site.pp

vi /etc/puppet/manifests/site.pp 

node default {  

file {  

"/tmp/test.txt": content => "helo,test!"; 

  }  

}

#客户端测试

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

 

#puppet自动认证

在服务端的puppet.conf配置文件里面[main]下方加入

autosign= true

然后重启puppetmaster服务。

#这样在客户端执行puppetd �Cserver=puppetserver�Ctest服务端会自动认证

 

#重新生成证书:

因为很多时候需要更换主机名称,所以需要重新认证

#首先在客户端删除:rm �Crf/var/lib/puppet/ssl 文件夹

#然后在服务端删除:puppet cert--clean puppetclient

#最后重新获取证书:puppet agent--server puppetserver �Ctest

 

#配置客户端自动同步:

#客户端配置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

 

#puppetrun的使用(puppet kick)

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

  1. 1.    修改客户端上的puppet配置文件
    vim /etc/puppet/puppet.conf
    在[agent]下方添加
    listen = true #目的是让puppet监听8139端口

  2. 2.    修改客户端的puppet的/etc/sysconfig/puppet文件
    vim /etc/sysconfig/puppet
    PUPPET_SERVER=puppetserver  #server主机名称

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

  4. 4.    在客户端修改auth.conf,在 paht / 的前面添加以下内容:
    #test
    path /run
    method save
    allow *

  5. 5.    最后重启puppet服务
    /etc/init.d/puppet restart

  6. 6.    在服务端测试命令:
    puppet kick �Cd host puppetclient
    #code 0表示成功


 


你可能感兴趣的:(自动化运维)