千家信息网

搭建Puppet服务

发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,使用virtualbox 安装两台虚拟机来搭建Puppet服务端和客户端的测试环境。系统版本: CentOS 7.6 64位内核版本: 3.10.0-957puppetserver版本: 5.3.10
千家信息网最后更新 2026年11月01日搭建Puppet服务

使用virtualbox 安装两台虚拟机来搭建Puppet服务端和客户端的测试环境。

系统版本: CentOS 7.6 64位
内核版本: 3.10.0-957
puppetserver版本: 5.3.10-1.el7
puppet-agent版本: 5.5.17-1.el7
机器名/IP地址:
服务端: pp-master / 192.168.31.123
客户端: pp-agent / 192.168.31.124


【准备】

关闭防火墙和SELINUX
将2台主机的IP和主机名添加到/etc/hosts里,确保互相可以ping同对方的主机名

【安装】
分别在pp-master,pp-agent下载并安装puppet repo
rpm -ivh https://yum.puppetlabs.com/puppet5/puppet5-release-el-7.noarch.rpm
生成puppet repo的文件路径 /etc/yum.repos.d/puppet5.repo

在pp-master上面安装puppetserver和puppet
yum install puppetserver puppet -y

在pp-agent上面安装puppet
yum install puppet -y

【配置】
puppet的配置文件 /etc/puppetlabs/puppet/puppet.conf

服务器端puppet.conf
默认配置如下:

[master]vardir = /opt/puppetlabs/server/data/puppetserverlogdir = /var/log/puppetlabs/puppetserverrundir = /var/run/puppetlabs/puppetserverpidfile = /var/run/puppetlabs/puppetserver/puppetserver.pidcodedir = /etc/puppetlabs/code

将如下main配置添加进服务器端puppet.conf

[main]certname = pp-masterserver = pp-masterenvironment = productionruninterval = 10mstrict_variables = true

certname(证书名)和server(服务器名)都设置为 pp-master
environment(环境)默认为production(生产环境)
runinterval(运行间隔时间)设置为10分钟
strict_variables(强制变量)设定为true

将如下main配置添加进客户端puppet.conf

[main]certname = pp-agentserver = pp-masterenvironment = productionruninterval = 10m

证书名为本机hostname: pp-agent
服务器端为pp-master
环境默认为production
运行间隔时间为10分钟

编辑hiera配置 /etc/puppetlabs/puppet/hiera.yaml

---:backends:  - yaml:yaml:  :datadir: "/etc/puppetlabs/code/environments/%{environment}/hieradata":hierarchy:  - "hosts/%{::trusted.certname}"  - common:yaml:# datadir is empty here, so hiera uses its defaults:# - /etc/puppetlabs/code/environments/%{environment}/hieradata on *nix# - %CommonAppData%\PuppetLabs\code\environments\%{environment}\hieradata on Windows# When specifying a datadir, make sure the directory exists.  :datadir:

客户端host配置存放在路径/etc/puppetlabs/code/environments/production/hieradata/hosts/pp-agent
配置内容:

---classes:  - helloworld

首先定义一个叫helloworld的模块用于测试

模块目录:
/etc/puppetlabs/code/environments/production/modules/helloworld
目录下有3个目录:

helloworld/├── files│   └── hw.txt├── manifests│   └── init.pp└── templates

files和templates目录下存放模板文件,该模板文件为hw.txt
manifests的init.pp文件用于定义模块需要哪些资源和操作

init.pp

class helloworld {  file { '/tmp/hw.txt':    ensure => 'file',    source => 'puppet:///modules/helloworld/hw.txt',    mode   => '0644',    owner  => 'root',    group  => 'root',  }}

该模块定义了一个helloworld的类,资源为file,其内容为"Hello world!".
'/tmp/hw.txt' 为客户端生成的文件路径和名称
ensure 定义该类型为文件,其他还有link, directory, 或者可以定义为present和absent表示该文件存在或不存在
mode为文件权限644
owner文件所有者为root
group文件组为root

【服务】
启动服务器端服务

systemctl start puppetserversystemctl start puppet

启动客户端服务
systemctl start puppet

客户端执行puppet agent -t 用户拉取配置

服务器端需要对证书签名,
puppet cert sign --all

【测试】

客户端执行puppet agent -t 命令后,可以看到文件已经生成

Notice: /Stage[main]/Helloworld/File[/tmp/hw.txt]/ensure: defined content as '{md5}59ca0efa9f5633cb0371bbc0355478d8'Notice: Applied catalog in 0.60 seconds

至此,一个简单的Puppet CS环境搭建完成。

文件 服务 配置 客户 客户端 服务器 环境 模块 版本 目录 主机 路径 测试 生成 内容 时间 模板 证书 资源 运行 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 互联网电商科技 互联网科技社 互联网金融 金融科技 互联网科技公司怎么样 互联网科技logo设计 融贸通互联网科技 佰商互联网科技有限公司 卓越科技互联网 招聘 中国最先进互联网科技公司 汉立互联网科技有限公司联系电话 哈尔滨新华互联网科技学院 金融科技与互联网金融相同和不同 科技互联网大厂 洛阳昕诺飞互联网科技有限公司 东莞新华互联网科技学校 徐州市互联网科技有限公司 滨湖区互联网智能科技产品有哪些 互联网科技圈年度人物 东风日产互联网科技公司叫什么 高科技和互联网的现代国家 广州大一互联网络科技有限公司 青岛互联网科技公司 深圳期待互联网科技 卫星互联网科技股票 新兴科技互联网创新大赛颁奖典礼 济南有互联网科技公司吗 烟台灵鸽互联网科技有限公司 易企秀互联网科技是做什么的 互联网科技接地气 米泉互联网科技专业怎么样
0