搭建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环境搭建完成。

相关内容

热门资讯

空调连续工作多久需要停机休息 空调连续工作的时间取决于多个因素,包括空调的型号、功率、使用环境和维护情况等。一般来说,空调可以连续...
空调哪个符号是除湿的 空调除湿功能通常用一个水滴形状的符号表示。不同品牌和型号的空调遥控器可能会有所差异,但一般来说,除湿...
格力空调多长时间加一次氟利昂 1、一般情况下,空调对氟利昂的使用量是非常小的,所以在空调使用了四年左右的时候再考虑加也没问题。2、...
空调用多长时间需要加氟一次 一般情况下是五年。当出现以下这几种情况时,空调才需要加氟。1、空调的室内机和室外机各有两个接口,当接...
格调生活·C标思享荟:卡萨帝在... 9月12日的郑州龙湖金融岛,夜风轻拂,灯光璀璨。“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑...
品牌价值破千亿、高端份额持续领... 9月12日,“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑州站”在郑州龙湖金融岛举办。2026...
空调主板坏了修800还是换新的 空调主板坏了是修还是换新,需要考虑多个因素,以下是一些建议:1. 维修成本:如果维修费用较低,比如 ...
空调开多久需要休息多长时间 问题:空调开多久需要休息多长时间回答:1、在使用空调的过程中,一般空调开7~8个小时左右需要休息2~...
中央空调多长时间清洗一次 1、一般空调开机前清洗一次即可,空调开机中间时段再清洗一次,空调关机时清洗一次,这样比较合理。2、空...
中央空调氟利昂多久加一次 看空调制热和制冷程度,很多人的观点认为氟利昂必须一年放一次,其实这个观点是错误的,理解上面有点偏差,...