Puppet master-agent模型工作过程:
基于ssl xmlrpc进行通信,端口8140/tcp
agent:默认每隔30分钟向master发送node name和facts,并请求catalog
master:验证客户端身份,查找与其相关的site mainfests,编译生成catalog,并发送给客户端
环境搭建:
OS:CentOS 7
Puppet:3.6.2
master:安装puppet,puppet-server,facter
agent:安装puppet,facter
配置过程:
配置前提:
A.master和agent的时间必须要同步
B.master和agent之间进行SSL通信,需要依赖于HOSTNAME(由DNS解析而来),故测试时需要编辑本地的hosts文件:
1.master端配置
首先以不启动守护进程方式运行一遍,看看有没有问题
# puppet master -v --no-daemonize
如图所示,没有问题就可以启动puppetmaster服务了
2.agent端配置
发送证书签署请求给master
# puppet agent --server=node1.bzy.com -v
3.master端给agent端签署证书
# puppet cert list
# puppet cert sign node2.bzy.com
4.agent端获取证书
可以等待agent端获取证书,也可以手动再次执行以下命令获取证书
# puppet agent --server=node1.bzy.com -v
5.master端定义站点清单
位置:/etc/puppet/mainfests/site.pp
#node /^noded+.bzy.com/ { # include nginx::proxy #} node "node2.bzy.com" { include nginx::proxy }
如果有多个节点,依次写入即可。
到此步,配置基本成功了,由于puppet版本较多,有些细节可能不太一致,具体请查阅官方文档
测试用的模块:nginx
init.pp配置示例:
class nginx { package{'nginx': ensure => installed } } class nginx::webserver inherits nginx { file{'/etc/nginx/nginx.conf': source => 'puppet:///modules/nginx/nginx_web.conf', ensure => file, require => Package['nginx'], #notify => Service['nginx'] }-> service{'nginx': ensure => running, hasrestart => true, hasstatus => true, } } class nginx::proxy inherits nginx { file{'/etc/nginx/nginx.conf': ensure => file, content => template('nginx/nginx_proxy.conf.erb'), require => Package['nginx'], #notify => Service['nginx'] }-> service{'nginx': ensure => running } }
附:关于报错信息
1.
Could not prepare for execution: Could not create PID file
先察看是否与权限有关。如果有权限的话,察看是否有进程已启动:
# ps -ef | grep puppet
如果有,先kill掉,或者/etc/init.d/puppet stop后,然后重新输入指令。
2.
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not find class yum::repos for one-663.localdomain on node one-663.localdomain
在site.pp(或其他会import到site.pp的file.pp)中import 该class所在的"module_name"。即import "xxx"
3.
# puppet filebucket restore /etc/yum.repos.d/rh.repo 1bfcad49b3ffab391d5303ba58d26b64
Error: Could not run: Error 403 on SERVER: Forbidden request: 10.10.6.197(10.10.6.197) access to /file_bucket_file/md5/1bfcad49b3ffab391d5303ba58d26b64 [find] at :103
master端puppetmaster关掉了。重启即可。