Puppet 和 Kerberos 服务使用模具提供配置文件。
Puppet 是用于管理许多系统的配置的工具包。在 Oracle Solaris 上,Puppet 应用程序通过 SMF 进行管理。
当您安装 system/management/puppet 软件包时,会获得两个 SMF 服务实例:puppet:master 和 puppet:agent。缺省情况下这两个实例处于禁用状态。
当您启用这些实例后,下面的命令会显示 puppet:master 和 puppet:agent 都是合同服务:
$ svcs -p puppet STATE STIME FMRI online 17:19:32 svc:/application/puppet:agent 17:19:32 2565 puppet online 17:19:32 svc:/application/puppet:master 17:19:32 2567 puppet
下面的命令显示有关合同服务启动的进程的更多信息:
$ ps -o pid,args -p 2565,2567 PID COMMAND 2565 /usr/ruby/1.9/bin/ruby /usr/sbin/puppet agent --logdest /var/log/puppet/puppet- 2567 /usr/ruby/1.9/bin/ruby /usr/sbin/puppet master --logdest /var/log/puppet/puppet
从 ps 输出中可以看出,puppet 向 /var/log/puppet 中的日志文件写入内容:
$ ls /var/log/puppet puppet-agent.log puppet-master.log
Puppet 需要使用名为 /etc/puppet/puppet.conf 的配置文件。/usr/sbin/puppet 应用程序从 /etc/puppet/puppet.conf 读取配置信息,而非从 application/puppet 服务实例中设置的属性读取。为了提供必要的配置文件,每个 puppet 实例均提供一个模具文件和 configfile 属性组。configfile 属性组告知 svcio 实用程序运行和创建指定的配置文件。模具文件用于将服务属性值数据以正确的格式写入配置文件。
下面的命令显示类型为 configfile 的属性组中的所有 puppet 服务属性。此输出显示 puppet 服务的两个实例都具有 configfile 属性,而且属性值相同。每个 puppet 服务实例都提供配置文件的路径、配置文件的模式和模具文件的路径。
$ svcprop -g configfile puppet svc:/application/puppet:master/:properties/puppet_stencil/mode astring 0444 svc:/application/puppet:master/:properties/puppet_stencil/path astring /etc/puppet/puppet.conf svc:/application/puppet:master/:properties/puppet_stencil/stencil astring puppet.stencil svc:/application/puppet:agent/:properties/puppet_stencil/mode astring 0444 svc:/application/puppet:agent/:properties/puppet_stencil/path astring /etc/puppet/puppet.conf svc:/application/puppet:agent/:properties/puppet_stencil/stencil astring puppet.stencil
以下命令将确认这些实例属性均继承自父服务。
$ svccfg -s puppet listprop -l all puppet_stencil puppet_stencil configfile manifest puppet_stencil/mode astring manifest 0444 puppet_stencil/path astring manifest /etc/puppet/puppet.conf puppet_stencil/stencil astring manifest puppet.stencil $ svccfg -s puppet:agent listprop -l all puppet_stencil $ svccfg -s puppet:master listprop -l all puppet_stencil
对于您的基础结构,您可能需要其他实例,例如 puppet:agent1 和 puppet:agent2 实例。在这种情况下,您需要为每个实例定制属性值和添加属性,如修改 Puppet 配置文件中所示。
下面是配置文件 /etc/puppet/puppet.conf 的初始内容:
# WARNING: THIS FILE GENERATED FROM SMF DATA. # DO NOT EDIT THIS FILE. EDITS WILL BE LOST. # # See puppet.conf(5) and http://docs.puppetlabs.com/guides/configuring.html # for details.
模具文件的内容会告知您将哪些属性和其他信息写入配置文件。作为 puppet_stencil/stencil 属性值的 puppet.stencil 路径是相对于 /lib/svc/stencils 的路径。下面是模具文件 /lib/svc/stencils/puppet.stencil 的内容:
# WARNING: THIS FILE GENERATED FROM SMF DATA. # DO NOT EDIT THIS FILE. EDITS WILL BE LOST. # # See puppet.conf(5) and http://docs.puppetlabs.com/guides/configuring.html # for details. ; walk each instance and extract all properties from the config PG $%/(svc:/$%s:(.*)/:properties)/ { $%{$%1/general/enabled:? [$%2] $%/$%1/config/(.*)/ { $%3 = $%{$%1/config/$%3} } } }
在该模具文件中,svc:/$%s:(.*)/:properties(或 %1)可以扩展为 svc:/application/puppet:agent/:properties 和 svc:/application/puppet:master/:properties,其中 .*(或 %2)与所有实例匹配。实例名称则用于标记配置文件中的块。接下来出现的 .*(或 %3)与 %1 服务实例 config 属性组中的所有属性匹配。模具告知 svcio 将服务实例的属性名称和属性值写入配置文件。
如您在初始 Puppet 配置文件中所见,开始时仅将文本注释行写入配置文件。模具文件中 general/enabled 属性值的测试会阻止将属性值写入配置文件。下面的命令显示,缺省情况下 general/enabled 属性的值为 false:
$ svcprop -p general/enabled puppet svc:/application/puppet:master/:properties/general/enabled boolean false svc:/application/puppet:agent/:properties/general/enabled boolean false
使用 svcadm enable 命令启用实例不会更改 general/enabled 属性的值。当您将 general/enabled 属性的值更改为 true 并重新启动实例时,该实例 config 属性组中的所有属性都将写入到配置文件中。
$ svccfg -s puppet:agent setprop general/enabled=true $ svcprop -p general/enabled puppet:agent false $ svcadm refresh puppet:agent $ svcprop -p general/enabled puppet:agent true $ svcadm restart puppet:agent
下面的命令显示开始时 config 属性组中的唯一属性是每个实例的日志文件的路径:
$ svcprop -p config puppet svc:/application/puppet:master/:properties/config/logdest astring /var/log/puppet/puppet-master.log svc:/application/puppet:agent/:properties/config/logdest astring /var/log/puppet/puppet-agent.log
已启用实例的 config 属性已添加至配置文件中使用该实例名称标记的块。
# WARNING: THIS FILE GENERATED FROM SMF DATA. # DO NOT EDIT THIS FILE. EDITS WILL BE LOST. # # See puppet.conf(5) and http://docs.puppetlabs.com/guides/configuring.html # for details. [agent] logdest = /var/log/puppet/puppet-agent.log
Puppet 配置文档指出配置文件可以具有 [main]、[agent] 和 [master] 块。[main] 块中的配置同时适用于 agent 和 master 块。对于 Puppet 代理,[agent] 块中的配置会覆盖 [main] 块中的相同配置。对于 Puppet 主体,[master] 块中的配置会覆盖 [main] 块中的相同配置。如果您想要针对代理和主体共用的配置提供 [main] 块,请为该实例创建一个 puppet:main 实例以及相应的 config 属性。
以下命令说明如何将配置添加到 Puppet 配置文件中。
$ svccfg -s puppet:agent svc:/application/puppet:agent> setprop config/report=true svc:/application/puppet:agent> setprop config/pluginsync=true svc:/application/puppet:agent> refresh svc:/application/puppet:agent> exit $ svcadm restart puppet:agent $ cat /etc/puppet/puppet.conf # WARNING: THIS FILE GENERATED FROM SMF DATA. # DO NOT EDIT THIS FILE. EDITS WILL BE LOST. # # See puppet.conf(5) and http://docs.puppetlabs.com/guides/configuring.html # for details. [agent] logdest = /var/log/puppet/puppet-agent.log pluginsync = true report = true
类似的命令可以用于删除属性和更改属性值。请参见Chapter 4, 配置服务。要添加 main 实例,请使用 svccfg add 命令,如添加服务实例中所示。
另一个使用模具的 Oracle Solaris 服务示例是 Kerberos。下面的命令显示 configfile 属性组为 krb5_conf,模具文件为 /lib/svc/stencils/krb5.conf.stencil,配置文件为 /etc/krb5/krb5.conf。
$ svcprop -g configfile svc:/system/kerberos/install:default krb5_conf/disabled boolean true krb5_conf/group astring sys krb5_conf/mode integer 644 krb5_conf/owner astring root krb5_conf/path astring /etc/krb5/krb5.conf krb5_conf/stencil astring krb5.conf.stencil