Puppet – 2. 修改Puppet配置文件

2.1 Puppet 主机配置

设置主机名

首先,在Puppet主机中,使用vim编辑器编辑主机文件,设置IP地址和主机名。你可以使用任何其他编辑器,如vi、gedit等。

执行以下命令(主机):

# vim /etc/hosts

文件末尾,添加一行:

192.168.31.154 puppet puppet.qikegu.com

输入主机的ip地址,并给它一个域名。可以看到,在上面添加的这行中,192.168.31.154是Puppet主机IP地址,puppet puppet.qikegu.com是分配给Puppet主机的域名。

要查看电脑的IP地址,可使用以下命令:

# ifconfig

输出:


br-0b42f697dcd8: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 172.22.0.1 netmask 255.255.0.0 broadcast 172.22.255.255 ether 02:42:fa:7d:7f:29 txqueuelen 0 (Ethernet) RX packets 27539 bytes 27425773 (26.1 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 12476 bytes 1157370 (1.1 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.31.154 netmask 255.255.255.0 broadcast 192.168.31.255 inet6 fe80::6ace:9b1d:c11b:1f77 prefixlen 64 scopeid 0x20<link> ether 08:00:27:4c:65:36 txqueuelen 1000 (Ethernet) RX packets 27539 bytes 27425773 (26.1 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 12476 bytes 1157370 (1.1 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Puppet 主机配置文件

接下来,修改Puppet配置文件。

# vim /etc/puppet/puppet.conf

文件中的[main]栏中添加:

    dns_alt_names = puppet,puppet.qikegu.com # dns配置
    certname=puppet # 认证名称配置

文件完整内容如下所示:

[main]
    # The Puppet log directory.
    # The default value is '$vardir/log'.
    logdir = /var/log/puppet

    # Where Puppet PID files are kept.
    # The default value is '$vardir/run'.
    rundir = /var/run/puppet

    # Where SSL certificates are kept.
    # The default value is '$confdir/ssl'.
    ssldir = $vardir/ssl


    #####################
    # 新增下面2行
    dns_alt_names = puppet,puppet.qikegu.com # dns配置
    certname=puppet # 认证名称配置
    #####################

[agent]
    # The file in which puppetd stores a list of the classes
    # associated with the retrieved configuratiion.  Can be loaded in
    # the separate ``puppet`` executable using the ``--loadclasses``
    # option.
    # The default value is '$confdir/classes.txt'.
    classfile = $vardir/classes.txt

    # Where puppetd caches the local configuration.  An
    # extension indicating the cache format is added automatically.
    # The default value is '$confdir/localconfig'.
    localconfig = $vardir/localconfig

在这里的[main]部分,配置puppet主机名称。DNS可以让节点使用友好名称而不是IP地址进行通信。另外还需设置认证名称。

2.2 Puppet 从机配置

设置host名称

类似的,在Puppet从机中,使用vim编辑器编辑/etc/hosts文件。

执行以下命令(从机):

# vim /etc/hosts

文件末尾,添加2行:

192.168.31.100 puppetagent # 设置从机IP与名称
192.168.31.154 puppet puppet.qikegu.com #设置主机IP与名称

Puppet 从机配置文件

接下来,修改Puppet配置文件。

# vim /etc/puppet/puppet.conf

文件中的[agent]部分添加:

    server = puppet.qikegu.com # 设置这个puppet从机的puppet主机

文件完整内容如下所示:

[main]
    # The Puppet log directory.
    # The default value is '$vardir/log'.
    logdir = /var/log/puppet

    # Where Puppet PID files are kept.
    # The default value is '$vardir/run'.
    rundir = /var/run/puppet

    # Where SSL certificates are kept.
    # The default value is '$confdir/ssl'.
    ssldir = $vardir/ssl

[agent]
    #######################################
    # 新增下面1行
    server = puppet.qikegu.com # 设置这个puppet从机的puppet主机域名
    #######################################

    # The file in which puppetd stores a list of the classes
    # associated with the retrieved configuratiion.  Can be loaded in
    # the separate ``puppet`` executable using the ``--loadclasses``
    # option.
    # The default value is '$confdir/classes.txt'.
    classfile = $vardir/classes.txt

    # Where puppetd caches the local configuration.  An
    # extension indicating the cache format is added automatically.
    # The default value is '$confdir/localconfig'.
    localconfig = $vardir/localconfig


在这里的[agent]部分,为puppet代理设置puppet服务器名。这是非常关键的一步,puppet将从主机文件中查找puppet服务器域名,并连接到该服务器对应的IP地址。确保你输入了正确的服务器域名。



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