Puppet是目前互联网主流三大自动化运维工具(Puppet、Ansible、Saltstack)之一,puppet是一种Linux、Unix平台的集中配置管理系统,所谓配置管理系统,就是管理及其里面诸如文件、用户、进程、软件包等资源
一、Puppet入门简介
puppet可以运行在一台服务器端,每个客户端通过SSL证书连接到服务端,得到本机器的配置列表,然后根据列表来完成配置工作,所以如果硬件性能比较高,维护管理上千上万台机器是非常轻松的,前提是客户端的配置、服务器路径、软件需要保持一致
Puppet是开源的基于Ruby的系统配置管理工具,Puppet工作流程为Puppet是一个C/S架构,所有的Puppet客户端同一个服务器端的Puppet通信,每个Puppet客户端每半小时(可以设置)连接一次服务器端,下载最新的配置文件,并且严格按照配置文件来配置服务器,配置完成以后Puppet客户端可以反馈给服务器端一个消息,如果报错会给服务器端反馈一个消息
二、Puppet工作原理
Puppet master与agent完整工作流程图。
1、原理框图
2、具体工作流程
3、Puppet工作原理详解
- 客户端Puppetd 调用本地facter,facter会探测出该主机的常用变量,例如主机名、内存大小、IP地址等。然后Puppetd把这些信息发送到Puppet服务端;
- Puppet服务端检测到客户端的主机名,然后会检测manifest中对应的node配置,并对这段内容进行解析,facter发送过来的信息可以作为变量进行处理;
- Puppet服务器匹配Puppet客户端相关联的代码才能进行解析,其他的代码不解析,解析分为几个过程,首先是语法检查,然后会生成一个中间的伪代码,之后再把伪代码发给Puppet客户端;
- Puppet客户端接收到伪代码之后就会执行,执行完后会将执行的结果发送给Puppet服务器;
- Puppet服务端再把客户端的执行结果写入日志。
三、Puppet安装配置
Puppet工作为C/S模式,构建Puppet平台需安装Puppet Server端和client端,安装之前准备好系统环境。需要联网
版本 | IP | 主机名 | 描述 |
---|---|---|---|
Centos7.5-1804 | 192.168.100.100 | puppet-server | Puppet服务端,已关闭防火墙与selinux |
Centos7.5-1804 | 192.168.100.101 | puppet-client | Puppet客户端,已关闭防火墙与slinux |
1、Puppet服务端安装
#更改主机名
[root@linuxli ~]# hostnamectl set-hostname puppet-server
#设置hosts映射
[root@puppet-server ~]# echo -e "192.168.100.100 puppet-server\n192.168.100.101 puppet-client" >>/etc/hosts
#配置yum源
[root@puppet-server ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@puppet-server ~]# yum -y install epel-release
#安装puppet-server
[root@puppet-server ~]# yum -y install puppet-server
#启动puppet-server服务
[root@puppet-server ~]# systemctl enable puppetmaster.service
[root@puppet-server ~]# systemctl start puppetmaster.service
2、Puppet客户端安装
#更改主机名
[root@linuxli ~]# hostnamectl set-hostname puppet-client
#设置hosts映射
[root@puppet-client ~]# echo -e "192.168.100.100 puppet-server" >>/etc/hosts
#配置yum源
[root@puppet-client ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@puppet-client ~]# yum -y install epel-release
#安装puppet客户端
[root@puppet-client ~]# yum -y install puppet
#启动puppet服务
[root@puppet-client ~]# systemctl enable puppetagent.service
[root@puppet-client ~]# systemctl start puppetagent.service
3、Puppet客户端申请证书
Puppet客户端与Puppet服务端是通过SSL隧道通信的,客户端安装完成后,首次使用需向服务器端申请Puppet通信证书,Puppet客户端第一次连接服务器端会发起证书申请。
[root@puppet-client ~]# puppet agent --server puppet-server --test
Info: Caching certificate for ca
Info: csr_attributes file loading from /etc/puppet/csr_attributes.yaml
Info: Creating a new SSL certificate request for puppet-client
Info: Certificate Request fingerprint (SHA256): 09:D3:71:C8:64:5B:C2:92:70:48:16:E2:97:4E:4E:AD:CD:4D:03:81:57:41:FD:C1:55:A8:1E:C9:95:D3:F4:42
Info: Caching certificate for ca
Exiting; no certificate found and waitforcert is disabled
4、Puppet服务端颁发证书
Puppet客户端向服务器发起证书申请,服务器必须审核证书,如果不审核,客户端与服务器端无法进行后续正常通信。
[root@puppet-server ~]# puppet cert --list
"puppet-client" (SHA256) 09:D3:71:C8:64:5B:C2:92:70:48:16:E2:97:4E:4E:AD:CD:4D:03:81:57:41:FD:C1:55:A8:1E:C9:95:D3:F4:42
[root@puppet-server ~]# puppet cert -s puppet-client
Notice: Signed certificate request for puppet-client
Notice: Removing file Puppet::SSL::CertificateRequest puppet-client at '/var/lib/puppet/ssl/ca/requests/puppet-client.pem'
[root@puppet-server ~]# puppet cert --list --all
+ "puppet-client" (SHA256) 3B:EC:D3:3D:98:5C:40:8E:AF:89:BE:05:AF:F3:C5:26:03:67:36:AC:80:11:C5:B9:8C:3A:0E:E5:78:10:E0:ED
+ "puppet-server" (SHA256) F2:37:44:C5:01:A6:F1:6D:F1:42:0A:C4:72:2B:5C:92:FA:27:F6:68:03:30:0B:0B:28:A2:CD:A3:42:9F:38:C5
- puppet cert –list:查看申请证书的客户端主机名;