puppet
前面已经讲解了puppet的基础语法。下面讲解一下puppet的agent/master工作模型。
agent:默认每隔30分钟去向master发送node name和facts,并且请求catalog
master:验证客户端身份,查找与其相关的site manifest,编译生成catalog,并且发送给客户端
期间要验证双方的证书
master服务端:puppet,puppet-server,facter
agent客户端:puppet,facter
master 的安装
yum -y install puppet-server
配置文件:
主配置文件: /etc/puppet/puppet.conf
显示或设置配置参数。
[root@localhost puppet]# puppet config print
daemonize = true
cert_inventory = /var/lib/puppet/ssl/ca/inventory.txt
disable_warnings =
report = true
plugindest = /var/lib/puppet/lib
......
手动生成或完成配置文件:
master:
puppet master --genconfig > /etc/puppet/puppet_default.conf
agent:
puppet agent --genconfig >> /etc/puppet/puppet_default.conf
生成证书。
puppet master -v --no-daemonize
启动puppetmaster。
# service puppetmaster start
# chkconfig puppetmaster on
agent端的安装
# yum -y install puppet facter
发送证书签署请求给master
# puppet agent --server=master.wjx.com --no-daemonize --verbose
Info: Creating a new SSL key for node1.wjx.com
Info: Caching certificate for ca
Info: csr_attributes file loading from /etc/puppet/csr_attributes.yaml
Info: Creating a new SSL certificate request for node1.wjx.com
Info: Certificate Request fingerprint (SHA256): 48:1F:CD:5D:4D:23:2E:27:7E:A1:3E:97:5B:75:43:5F:8A:F0:25:00:46:A0:08:8D:BA:6A:84:CD:EE:9D:7B:AD
Info: Caching certificate for ca
此时,在master端。查看待签署的证书
# puppet cert list
"node1.wjx.com" (SHA256)
...
直接签署证书
# puppet cert sign node1.wjx.com
Notice: Signed certificate request for node1.wjx.com
Notice: Removing file Puppet::SSL::CertificateRequest node1.wjx.com at '/var/lib/puppet/ssl/ca/requests/node1.wjx.com.pem'
在master端
1.安装所有要使用到的模块。
2.定义站点清单/etc/puppet/manifests/site.pp。
node 'NODE_NAME' {
.... puppet code ....
}
在签证书后的等待一段时间,在agent端可以看到如下输出:
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for node1.wjx.com
Info: Applying configuration version '1491833546'
Info: Creating state file /var/lib/puppet/state/state.yaml
证明证书已经生效
取消签署证书的方法。
在master端
首先查看所有的签署证书。
# puppet cert list --all
+ "node1.wjx.com" (SHA256) ......
+ "puppet.wjx.com" (SHA256) ......
清除证书
uppet cert clean node1.wjx.com
Notice: Revoked certificate with serial 3
....
在agent端
删除 /var/lib/puppet/ssl/*
重新去执行
# puppet agent --server=puppet.wjx.com
节点的功能相近的主机事先按照统一格式命名。
node /^web\d+\.wjx\.com/ {
... puppet node ...
}
下一节去讲解如何使用puppet去自动化配置一个简易的web架构。