搭建Puppet服务
admin
2023-03-03 07:22:08
0

使用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/puppetserver
logdir = /var/log/puppetlabs/puppetserver
rundir = /var/run/puppetlabs/puppetserver
pidfile = /var/run/puppetlabs/puppetserver/puppetserver.pid
codedir = /etc/puppetlabs/code

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

[main]
certname = pp-master
server = pp-master
environment = production
runinterval = 10m
strict_variables = true

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

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

[main]
certname = pp-agent
server = pp-master
environment = production
runinterval = 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 puppetserver
systemctl 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环境搭建完成。

相关内容

热门资讯

农田边毒水直流,比排污更刺眼的... 5月7日,总台《焦点访谈》曝光了徐州贾汪区农谷大道路边沟存在水体污染问题。全长12公里的路边沟满是污...
28岁女子坠亡,施工方谎报 近日,深圳龙岗区应急管理局公布了《龙岗龙城香港中文大学(深圳)医学院项目Ⅰ标“12·26”一般高处坠...
中国没有表演场地,高市早苗不必... 【文/观察者网专栏作者 吕超】56年前,时任西德总理的勃兰特在华沙犹太隔离区起义纪念碑前自发下跪,因...
卢希望当选为信阳市人民政府市长 信阳市第六届人民代表大会公告(第十九号)信阳市第六届人民代表大会第五次会议于2026年5月8日选举卢...
中坚科技及董事长被出具警示函 【大河财立方消息】5月8日消息,浙江证监局对浙江中坚科技股份有限公司及相关人员采取出具警示函措施的决...
今年河南首场高温来袭!淮河以北... 今年首场高温来袭受高空西北气流控制,近期我省以晴好天气为主,由于太阳辐射较强,全省将进入快速升温通道...
极氪回应“低价代购极氪新车”信... 【大河财立方消息】5月8日,极氪法务部发布关于保障用户购车安全及权益的重要提醒。极氪表示,“关注到网...
云南燃气灶维修价格表 燃气灶在日常使用中,由于长期受到高温和燃气的腐蚀,会出现各种故障,如火力不足、起火困难、火苗不稳等问...
涉及眼镜、电视、耳机等 人工智... 工业和信息化部、国家市场监督管理总局、商务部等部门今天(5月8日)联合发布《人工智能终端智能化分级》...
上门维修电视价格表 上门维修电视价格表因地区、品牌、型号等情况而异,以下是一般参考价格,仅供参考: 1. 电视开机无信...