Puppet – 实践

本篇将通过一个例子来演示Puppet使用过程。我们将通过Puppet在所有从机上创建一个文件,这也是一个常见场景,例如在所有从机上创建配置文件。

1. Puppet主机上编写manifest文件

编辑manifest文件:

vim /etc/puppet/manifests/site.pp

在这个site.pp文件中,添加如下内容:

# 在从机上创建文件
file { '/tmp/puppet-test.txt':
  ensure => file,
  content => 'This is a test file',    # 文件内容
}

保存后,退出。

注意 manifest使用的是Puppet编程语言,详情可以参考官网文档

2. Puppet从机上同步配置

Puppet从机会定期(每隔30分钟)与主机同步配置。如果想主动同步,可以执行:

puppet agent -t

执行详情:


[root@qikegu2 ~]# puppet agent -t Info: Retrieving pluginfacts Info: Retrieving plugin Info: Loading facts Info: Caching catalog for qikegu2 Info: Applying configuration version '1567564335' Notice: /Stage[main]/Main/File[/tmp/puppet-test.txt]/ensure: defined content as '{md5}f6b2bb5e0a13844c8b261e2695415f90' Notice: Finished catalog run in 0.04 seconds

3. Puppet从机上检查同步配置结果

根据主机上的manifest文件,会在从机上创建/tmp/puppet-test.txt,检查一下该文件:

[root@qikegu2 ~]# cat /tmp/puppet-test.txt
This is a test

可以看到该文件已经被正确创建。这里我们只展示了一个从机,多个从机的情况下,puppet会更有用。



浙ICP备17015664号-1 浙公网安备 33011002012336号 联系我们 网站地图  
@2019 qikegu.com 版权所有,禁止转载