Puppet是基于Ruby语言(早期的版本,4及之后的Server端采用Clojure语言)开发的、可以管理Unix(包括OS X)、Linux和Microsoft Windows平台的配置管理工具。同时面向研发及运维人员,是实现 DevOps 的重要工具之一。
创新互联是工信部颁发资质IDC服务器商,为用户提供优质的四川主机托管服务
统一配置管理软件
统一配置系统优化参数
定期检测服务是否运行
根据机器硬件环境自动为相应主机上的软件配置合理的属性
Puppet 通常运行在C/S模式下,服务器端称为 Puppet master,客户端称为 Agent,客户端主机称为 Node。Agent 通过标准的 SSL 加密认证的方式与 Master 建立连接,获取本机需要的配置信息。
在 Agent 未取得配置信息、或者已经达到配置状态时,Puppet 不会对系统进行改动,它只有在被要求的时候才修改系统,这是 Puppet 的一个关键特征,称为幂等性(Idempotency),这个修改过程称为一次配置运行(Configuration run)。
Agent 通常以守护进程的方式运行,默认每30分钟与 Master 进行一次交互,以确认配置项是否发生了变化,这个时间间隔可以根据自己的需求灵活调整。也可以以 cron 的方式运行或者手工触发 Agent。
大多数脚本语言(如 Shell Perl)是命令式或者过程式的,即“如何”达到想要的状态,而 Puppet 语言是描述式的,只需要描述最终状态是什么,不用关心是如何达到。例如安装 vim 软件包,手工安装时需要以下步骤:
1.连接到需要安装软件包的主机
2.检查 vim 是否安装
3.没有安装,需要根据主机的操作系统选择合适的命令安装,如 CentOS 使用 yum 命令,Ubuntu 使用 apt-get 命令
4.安装结束根据返回的结果确认是否安装成功。
使用 Puppet 安装vim,只需要定义一个资源,并且定义资源要达到的状态即可
package { ‘vim’:
ensure => present,
}
事物层是 Puppet 的工作引擎,一个 Puppet 事物包含配置一台 Agent 主机的完整过程,包括如下步骤:
版本选择:Puppet 最好的版本通常是最新的发布版
运行模式:服务器端-客户端模式和独立运行模式
DNS:Agent 每次连接 Master 时,都会使用域名
防火墙 :Puppet master 监听在 8140 端口,如果开启了防火墙必须放行 8140 端口,Iptables 配置如下:
iptables -A INPUT -p tcp -m state --state NEW --dport 8140 -j ACCEPT
iptables -A INPUT -p tcp -m state --state NEW -s 172.16.0.0/16 --sport 8140 -j ACCEPT
NTP 时钟同步
Puppetmaster:不能运行在Windows主机上
混合版本部署:服务端的版本必须比客户端高,4.x及以上不支持3.x及以下
硬件要求:2~4核CPU,4GB以上内存,大约可管理1000个节点
Yum-based systems
To enable the Puppet 5 Platform repository:
1 Choose the package based on your operating system and version.
The packages are located in the puppet5 directory of the yum.puppet.com repository and named using the following convention:
2 Use the rpm tool as root with the upgrade (-U) flag, and optionally the verbose (-v), and hash (-h) flags:
Enterprise Linux 7
sudo rpm -Uvh https://yum.puppet.com/puppet5/puppet5-release-el-7.noarch.rpm
Enterprise Linux 6
sudo rpm -Uvh https://yum.puppet.com/puppet5/puppet5-release-el-6.noarch.rpm
Enterprise Linux 5
wget https://yum.puppet.com/puppet5/puppet5-release-el-5.noarch.rpm
sudo rpm -Uvh puppet5-release-el-5.noarch.rpm
Note: For recent versions of Puppet, we no longer ship Puppet master components for RHEL 5. However, we continue to ship new versions of the puppet-agent package for RHEL 5 agents.
Fedora 26
sudo rpm -Uvh https://yum.puppet.com/puppet5/puppet5-release-fedora-26.noarch.rpm
Fedora 25
sudo rpm -Uvh https://yum.puppet.com/puppet5/puppet5-release-fedora-25.noarch.rpm
SuSE Enterprise Linux 12
sudo rpm -Uvh https://yum.puppet.com/puppet5/puppet5-release-sles-12.noarch.rpm
SuSE Enterprise Linux 11
sudo rpm -Uvh https://yum.puppet.com/puppet5/puppet5-release-sles-11.noarch.rpm
Apt-based systems
To enable the Puppet 5 Platform repository:
1 Choose the package based on your operating system and version. The packages are located in the apt.puppet.com repository and named using the convention
2 Download the release package and install it as root using the dpkg tool and the install flag (-i):wget https://apt.puppetlabs.com/puppet5-release-wheezy.deb
3 sudo dpkg -i puppet5-release-wheezy.deb
4 Run apt-get update after installing the release package to update the apt package lists.
Ubuntu 16.04 Xenial Xerus
wget https://apt.puppetlabs.com/puppet5-release-xenial.deb
sudo dpkg -i puppet5-release-xenial.deb
sudo apt update
Ubuntu 14.04 Trusty Tahr
wget https://apt.puppetlabs.com/puppet5-release-trusty.deb
sudo dpkg -i puppet5-release-trusty.deb
sudo apt-get update
Debian 9 Stretch
wget https://apt.puppetlabs.com/puppet5-release-stretch.deb
sudo dpkg -i puppet5-release-stretch.deb
sudo apt-get update
Debian 8 Jessie
wget https://apt.puppetlabs.com/puppet5-release-jessie.deb
sudo dpkg -i puppet5-release-jessie.deb
sudo apt-get update
Debian 7 Wheezy
wget https://apt.puppetlabs.com/puppet5-release-wheezy.deb
sudo dpkg -i puppet5-release-wheezy.deb
sudo apt-get update
[root@master1 yum.repos.d]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[root@master1 yum.repos.d]# sudo rpm -Uvh https://yum.puppet.com/puppet5/puppet5-release-el-7.noarch.rpm
[root@master1 yum.repos.d]# yum list |grep puppet
puppet5-release.noarch 5.0.0-1.el7 installed
bolt.x86_64 0.17.2-1.el7 puppet5
pdk.x86_64 1.4.1.1-1.el7 puppet5
puppet-agent.x86_64 5.4.0-1.el7 puppet5
puppet-client-tools.x86_64 1.2.2-1.el7 puppet5
puppet-release.noarch 1.0.0-1.el7 puppet5
puppetdb.noarch 5.2.0-1.el7 puppet5
puppetdb-termini.noarch 5.2.0-1.el7 puppet5
puppetserver.noarch 5.2.0-1.el7 puppet5
razor-server.noarch 1.7.1-1.el7 puppet5
[root@master1 yum.repos.d]# sudo yum install -y puppetserver
[root@master1 puppetlabs]# pwd
/opt/puppetlabs
[root@master1 puppetlabs]# bin/puppet --version
5.4.0
[root@master1 puppetlabs]# server/bin/puppetserver --version
puppetserver version: 5.2.0
yum 安装 Master 时,也会安装 Agent 包,4.x及以上的安装路径为 /opt/puppetlabs/ 目录,配置文件路径为 /etc/puppetlabs/ 目录
[root@master1 yum.repos.d]# sudo yum install -y puppet-agent
Puppet5.x 的配置文件路径为 /etc/puppetlabs/puppet/ 目录下
puppet.conf 配置文件简介:
[main] 用于 Puppet 全局配置
[master] 用于 Puppet 的 Master 配置
[agent] 用于 Puppet 的 Agent 配置
[main]
server = master1.tongwen.life #指定 Puppet 服务端地址
autoflush = false #是否实时刷新日志到磁盘
logdir = /var/log/puppet #日志目录
rundir = /var/run/puppet #进程pid文件存放目录
[master]
reportdir = /var/lib/puppet/reports #报告存放目录
autosign = true #自动授权签名配置文件
autosign = /etc/puppet/autosign.conf
bindaddress = 0.0.0.0 #puppetserver 服务监听地址
masterport = 8140 #puppetserver 服务监听端口
evaltrace = true #定义为true,可以看到执行的过程与变化
[agent]
certname = www1.tongwen.life #客户端的主机名
daemonize = true #是否后台运行,true表示是
allow_duplicate_certs = true #是否允许证书自动覆盖,默认不允许,有效期5年
report = true #是否上传客户端对资源的执行结果
reports = store, http #上传的方式
report_server = master1.tongwen.life #store 上传地址
report_port = 8140
reporturl = http://localhost:3000/reports/upload
runinterval = 20m #客户端执行间隔,默认30m
splay = true #是否在执行时间上加一个随机时间,0到最大随机时间之间的整数
splaylimit = 10m #随机时间的最大长度
configtimeout = 2m #客户端获取配置超时时间
color = ansi #日志记录是否加颜色
ignorecache = true #是否忽略本地缓存
如果 Master 主机的内存配置小于2GB,需要修改Java初始内存
vi /etc/sysconfig/puppetserver
JAVA_ARGS="-Xms2g -Xmx2g
systemctl start puppetserver #启动server端
systemctl start puppet #启动agent
[root@master1 puppetlabs]# puppet cert list
"node1.tongwen.life" (SHA256) E9:62:D5:7A:AD:1F:1D:DD:8F:0F:36:16:50:0C:
[root@master1 puppetlabs]# puppet cert sign node1.tongwen.life
Signing Certificate Request for:
"node1.tongwen.life" (SHA256) E9:62:D5:7A:AD:1F:1D:DD:8F:0F:36:16:50:0C:11:D6:02:39:7B:CB:8C:87:C9:25:E0:F7:A2:D7:D9:55:3B:37
Notice: Signed certificate request for node1.tongwen.life
Notice: Removing file Puppet::SSL::CertificateRequest node1.tongwen.life at '/etc/puppetlabs/puppet/ssl/ca/requests/node1.tongwen.life.pem'
[root@master1 puppetlabs]# puppet cert sign --all #签批所有
在agent上执行 puppet agent --test 验证证书的认证结果,如果有报错,请检查时间是否同步。
[root@master1 puppetlabs]# ntpdate cn.ntp.org.cn
[root@master1 manifests]# pwd
/etc/puppetlabs/code/environments/production/manifests
vi site.pp
node 'node1.tongwen.life' {
package { 'vim':
ensure => present,
}
}
售后响应及时
7×24小时客服热线数据备份
更安全、更高效、更稳定价格公道精准
项目经理精准报价不弄虚作假合作无风险
重合同讲信誉,无效全额退款