阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Puppet的安装部署实例

109次阅读
没有评论

共计 4537 个字符,预计需要花费 12 分钟才能阅读完成。

关于 puppet 的说明这里就不详细介绍了,下面我们直接开始 puppet 的部署安装吧!

特别说明:请注意客户端和服务器端版本要一致。如果版本不一致的话,那么高版本的只能是 puppet server, 另一台只能作为 puppet 客户端,也就是说 puppet 服务端的版本可以大于或者等于客户端版本。

1. 关闭防火墙
[root@puppet01~]service iptables stop
[root@puppet01~]chkconfig iptables off

2. 设置 selinux
[root@puppet01~]sed -i’s#SELINUX=enforcing#SELINUX=disabled#g’ /etc/selinux/config

3. 修改服务端跟客户端 hosts 文件, 添加 IP 和主机名称
[root@puppet01~]# cat /etc/hosts
127.0.0.1  localhost localhost.localdomain localhost4localhost4.localdomain4
::1        localhost localhost.localdomainlocalhost6 localhost6.localdomain6
192.168.1.231 puppetserver 
192.168.1.232 puppetclient

4. 服务端安装 puppetmaster
rpm-Uvh http://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-1.noarch.rpm
yum install puppet-server –y

5. 客户端安装 puppet
rpm-Uvh http://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-1.noarch.rpm
yum install puppet -y

6. 服务端开启 puppetmaster 服务
/etc/init.d/puppetmasterstart

7. 客户端证书申请
puppetagent –server puppetserver –test

8. 服务端查看证书是否生成
[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

9. 服务端颁发证书
1. 可以为特定的主机颁发证书命令:puppetcert –s 
2. 给所有的主机颁发证书命令:puppetcert –s and –a 
为客户端颁发证书:
puppetcert –s puppetclient #后面是主机名

10. 客户端 /tmp 下面创建个 test.txt 文件, 做测试
touchtest.txt
# 服务端下面编辑 site.pp
vi /etc/puppet/manifests/site.pp 
node default {
file {
“/tmp/test.txt”: content => “helo,test!”; 
  } 
}

11. 客户端测试
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

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

13. 重新生成证书:
因为很多时候需要更换主机名称,所以需要重新认证
1. 首先在客户端删除:rm –rf /var/lib/puppet/ssl 文件夹
2. 然后在服务端删除:puppet cert–clean puppetclient
3. 最后重新获取证书:puppet agent–server puppetserver –test

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

15.puppetrun 的使用 (puppet kick)
# 在服务器端使用 puppetrun 这个命令可以给客户端发送一段信号,告诉客户端立刻跟服务器同步
1.    修改客户端上的 puppet 配置文件
vim /etc/puppet/puppet.conf
在[agent]下方添加
listen = true #目的是让 puppet 监听 8139 端口
2.    修改客户端的 puppet 的 /etc/sysconfig/puppet 文件
vim /etc/sysconfig/puppet
PUPPET_SERVER=puppetserver  #server 主机名称
3.    在客户端新建 namespaceauth.conf 文件
[puppetrunner]
allow *
4.    在客户端修改 auth.conf, 在 paht / 的前面添加以下内容:
#test
path /run
method save
allow *
5.    最后重启 puppet 服务
/etc/init.d/puppet restart
6.    在服务端测试命令:
puppet kick –d host puppetclient
#code 0 表示成功

16. 文件同步
1. 首先编辑 fileserver.conf 文件:
[root@masterpuppet]# vim fileserver.conf
[files]    定义模块名称è后面的 site.pp 里面要调用这个名称
path/opt/
allow192.168.1.0/24
 
2. 然后编辑 site.pp 文件:
[root@masterpuppet]# vim manifests/site.pp
file{“/opt”:  # 传输的文件名称这个可以随便写
source=>”puppet:///files/”, #要传输的文件
recurse=> true;  # 传送该目录下所有文件
}
#puppet://” 等价于主配置文件 puppet.config 中的 modulepath 值
 
3. 最后执行命令
puppet agent –server puppetserver –test

 

Puppet 学习系列:

Puppet 学习一:安装及简单实例应用 http://www.linuxidc.com/Linux/2013-08/88710.htm

Puppet 学习二: 简单模块配置和应用 http://www.linuxidc.com/Linux/2013-08/88711.htm

相关阅读:

有关 Puppet agent 端三种备份恢复方案探讨研究 http://www.linuxidc.com/Linux/2013-07/87885.htm
选择更安全的方式注册你的 Puppet 节点 http://www.linuxidc.com/Linux/2013-07/87884.htm
通过配置 SSH 深刻理解 Puppet 的语法及工作机制 http://www.linuxidc.com/Linux/2013-07/87882.htm
Puppet 利用 Nginx 多端口实现负载均衡 http://www.linuxidc.com/Linux/2013-02/79794.htm
CentOS(5 和 6)下 Puppet 的 C / S 模式实例 http://www.linuxidc.com/Linux/2011-12/50502.htm

Puppet 的详细介绍:请点这里
Puppet 的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-03/115506.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-20发表,共计4537字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中