这是一篇 todo 文章,可以快速将 puppetserver 部署起来,经常遇到的坑也会写出来,但是自己不踩吭记忆是没有成长的(不仅仅是收获经验,重要的是增加了学习的能力),如果不缺时间的话,强烈建议看官方文档:https://puppet.com/docs/puppet/7/server/install_from_packages.html

安装 master

通过源来安装

1
2
sudo rpm -Uvh https://yum.puppet.com/puppet7-release-el-8.noarch.rpm
sudo yum install puppetserver

启动 master 服务

1
sudo systemctl start puppetserver

如果报错 Found master private key '/etc/puppetlabs/puppet/ssl/private_keys/localhost.localdomain.pem' but master public key '/etc/puppetlabs/puppet/ssl/public... 需要把 ssl 目录删除 sudo rm -rf /etc/puppetlabs/puppet/ssl/*已经上线的 master,请自己考虑后果再决定),再尝试启动

修改 dns 解析

解析 puppet 到 master 的 ip 即可

或者绑定 hosts, 如果是 hosts,客户端和服务器都需要绑定 hosts 到 master 的 ip

1
10.10.0.10  puppet

安装 puppet-agent

安装 agnet 需要先启用仓库

1
2
sudo rpm -Uvh https://yum.puppet.com/puppet7-release-el-8.noarch.rpm
sudo yum install puppet-agent

anget 连接 server

手动签名认证

1
2
3
4
5
6
7
8
9
#] puppet agent --test

Info: Creating a new RSA SSL key for agent
Info: csr_attributes file loading from /etc/puppetlabs/puppet/csr_attributes.yaml
Info: Creating a new SSL certificate request for agent
Info: Certificate Request fingerprint (SHA256): A3:CA:C3:B1:69:C9:97:3D:3A:BB:A4:F0:E5:15:34:A5:74:B5:86:08:E1:A9:02:A6:D4:91:12:04:6A:89:76:70
Info: Certificate for agent has not been signed yet
Couldn't fetch certificate from CA server; you might still need to sign this agent's certificate (agent).
Exiting now because the waitforcert setting is set to 0.

这时候需要在 master 节点上面允许 agnet 的证书,以下是 master 节点执行:

1
2
3
4
5
# 查看还没签名的证书
puppetserver ca list

# 给所有证书签名
puppetserver ca sign --all

自动签名认证

自动认证需要编写 ACL 规则,一个简单的规则如下:

1
2
3
#] vim /etc/puppetlabs/puppet/autosign.conf

*.localhost.com

然后重新启动 master 服务即可

部署代码

然后把清单文件 (.pp) 放到 master 的 /etc/puppetlabs/code/environments/production/manifests
modules 放到 /etc/puppetlabs/code/modules

其他证书操作

吊销证书

如果不想让某个 agent 来连接 master,可以在 master 上面把证书撤销

1
puppetserver ca revoke --certname agent_name

清理证书

比如说重装了系统,需要 master 重新生成证书

1
puppetserver ca clean --certname agent_name