文章
服务器与存储管理
作者:Glynn Foster
2014 年 6 月发布
|
Puppet 是一种流行的开源配置管理工具,现已包含在 Oracle Solaris 11.2 中。管理员可以使用声明式语言描述其希望应用于一个或一组系统的系统配置,帮助自动完成重复的任务、快速部署应用和管理整个数据中心的变更。随着管理员管理的系统(包括虚拟化环境)越来越多,这些功能越来越重要。此外,自动化还可以减少手动配置中可能发生的人为错误。
Puppet 通常配置为使用客户端/服务器架构,其中节点(代理)定期连接到集中式服务器(主服务器)、检索配置信息并应用配置。Puppet 主服务器控制应用于每个连接节点的配置。
本文通过由一个主服务器 (master.oracle.com) 和一个代理 (agent.oracle.com) 组成的示例,介绍使用 Puppet 管理系统的基础知识。要了解有关 Puppet 的更多信息,包括更高级的配置管理选项,请阅读 Puppet 3 参考手册。
Puppet 可通过 Oracle Solaris 映像包管理系统信息库中的一个软件包获取,该软件包能够将系统定义为主服务器或代理。默认情况下,Oracle Solaris 11 介质未安装该软件包,如清单 1 中使用 pkg info 命令查询系统的输出所示:
root@master:~# pkg info -r puppet
Name: system/management/puppet
Summary: Puppet - configuration management toolkit
Description: Puppet is a flexible, customizable framework designed to help
system administrators automate the many repetitive tasks they
regularly perform. As a declarative, model-based approach to IT
automation, it lets you define the desired state - or the "what"
- of your infrastructure using the Puppet configuration
language. Once these configurations are deployed, Puppet
automatically installs the necessary packages and starts the
related services, and then regularly enforces the desired state.
Category: System/Administration and Configuration
State: Not installed
Publisher: solaris
Version: 3.4.1
Build Release: 5.11
Branch: 0.175.2.0.0.37.1
Packaging Date: April 14, 2014 08:03:48 PM
Size: 3.87 MB
FMRI: pkg://solaris/system/management/puppet@3.4.1,5.11-0.175.2.0.0.37.1:20140414T200348Z
清单 1
要安装 Puppet 软件包,请使用 pkg install 命令,如清单 2 所示:
root@master:~# pkg install puppet
Packages to install: 3
Mediators to change: 1
Services to change: 2
Create boot environment: No
Create backup boot environment: No
DOWNLOAD PKGS FILES XFER (MB) SPEED
Completed 3/3 18354/18354 56.1/56.1 216k/s
PHASE ITEMS
Installing new actions 21388/21388
Updating package state database Done
Updating package cache 0/0
Updating image state Done
Creating fast lookup database Done
Updating package cache 1/1
root@master:~# which puppet
/usr/sbin/puppet
清单 2
Puppet 安装完毕,现在该配置主服务器和代理了。本文将使用两个系统:一个充当 Puppet 主服务器,另一个作为代理节点。在现实中,可能有数百或数千个节点与一个或多个主服务器通信。
在 Oracle Solaris 11 上安装 Puppet 时,有两个服务可用,如清单 3 所示:一个服务用于主服务器,另一个服务用于代理:
root@master:~# svcs -a | grep puppet disabled 16:04:54 svc:/application/puppet:agent disabled 16:04:55 svc:/application/puppet:master
清单 3
Puppet 已与 Oracle Solaris 服务管理工具配置信息库集成,因此管理员可以利用分层配置(这有助于在更新过程中保留配置)。服务管理工具模板提供服务管理工具配置信息库中存储的配置与传统 Puppet 配置文件 (/etc/puppet/puppet.conf) 之间的无缝映射。
第一步是使用服务管理工具配置和启用主服务:
root@master:~# svccfg -s puppet:master setprop config/server=master.oracle.com root@master:~# svcadm enable puppet:master root@master:~# svcs puppet:master STATE STIME FMRI online 17:38:42 svc:/application/puppet:master
清单 4
正如您在清单 4 中看到的,Puppet 主服务现在处于联机状态。我们切换到主服务将控制的节点并进行配置。我们将 config/server 值设置成指向主服务器,如清单 5 所示:
root@agent:~# svccfg -s puppet:agent setprop config/server=master.oracle.com root@agent:~# svccfg -s puppet:agent refresh
清单 5
完成之后,即可使用带 --test 选项的 puppet agent 命令测试连接,如清单 6 所示。更重要的是,该步骤还将创建一个新的安全套接字层 (SSL) 密钥,并在代理与主服务器之间建立一个身份验证请求。
root@agent:~# puppet agent --test Info: csr_attributes file loading from /etc/puppet/csr_attributes.yaml Info: Creating a new SSL certificate request for agent.oracle.com Info: Certificate Request fingerprint (SHA256): E0:1D:0F:18:72:B7:CE:A7:83:E4:48 :D5:F8:93:36:15:55:0A:B9:C8:E5:B1:CE:D9:3E:0A:68:01:BE:F7:76:47 Exiting; no certificate found and waitforcert is disabled
清单 6
如果我们返回主服务器,可以使用 puppet cert list 命令查看来自连接的客户端的未处理的证书请求:
root@master:~# puppet cert list "agent.oracle.com" (SHA256) E0:1D:0F:18:72:B7:CE:A7:83:E4:48 :D5:F8:93:36:15:55: 0A:B9:C8 :E5:B1:CE:D9:3E:0A:68:01:BE:F7:76:47
清单 7
在清单 7 中,我们可以看到从 agent.oracle.com 发来一条请求。假定请求合法,我们现在可以继续,使用 puppet cert sign 命令签署该证书,如清单 8 所示:
root@master:~# puppet cert sign agent.oracle.com Notice: Signed certificate request for agent.oracle.com Notice: Removing file Puppet:SSL:CertificateRequest agent at '/etc/puppet/ssl/ca/requests/solaris.pem'
清单 8
现在重新回到代理,重新测试连接,确保已正确设置身份验证,如清单 9 所示:
root@agent:~# puppet agent --test Info: Caching certificate for agent.oracle.com Info: Caching certificate_revocation_list for ca Info: Caching certificate for agent.oracle.com Info: Retrieving plugin Info: Caching catalog for agent.oracle.com Info: Applying configuration version '1400782295' Notice: Finished catalog run in 0.18 seconds
清单 9
最后,启用代理服务,如清单 10 所示:
root@agent:~# svcadm enable puppet:agent root@agent:~# svcs puppet:agent STATE STIME FMRI online 18:20:32 svc:/application/puppet:agent
清单 10
Puppet 使用资源 和资源类型 的概念描述系统配置。资源的例子包括运行中的服务、软件包、文件或目录,以及系统上的用户。每种资源作为一种资源类型建模,这是一种较高级别的抽象,通过标题以及一系列属性和值定义。
Puppet 被设计成跨平台兼容,因此可以使用平台特定的提供者为类似资源创建不同实现。例如,使用 Puppet 安装软件包将在 Oracle Solaris 11 上使用映像包管理系统,在 Red Hat Enterprise Linux 上使用 RPM。此功能让管理员能够使用一套通用的配置定义管理多个平台。这种资源类型与提供者的组合称为 Puppet 资源抽象层 (RAL)。管理员可以使用声明式语言描述系统资源及其状态;这些信息存储在名为 manifests 的文件中。
要查看 Oracle Solaris 11 系统上可用的资源类型列表,我们可以使用带 --types 选项的 puppet resource 命令:
root@master:~# puppet resource --types address_object address_properties augeas boot_environment computer cron dns etherstub exec file filebucket group host interface interface_properties ip_interface ip_tunnel ipmp_interface k5login ldap link_aggregation link_properties macauthorization mailalias maillist mcx mount nagios_command nagios_contact nagios_contactgroup nagios_host nagios_hostdependency nagios_hostescalation nagios_hostextinfo nagios_hostgroup nagios_service nagios_servicedependency nagios_serviceescalation nagios_serviceextinfo nagios_servicegroup nagios_timeperiod nis notify nsswitch package pkg_facet pkg_mediator pkg_publisher pkg_variant protocol_properties resources router schedule scheduled_task selboolean selmodule service solaris_vlan ssh_authorized_key sshkey stage svccfg tidy user vlan vni_interface vnic whit yumrepo zfs zone zpool root@master:~# puppet resource --types | wc -l 72
清单 11
正如您在清单 11 中看到的,目前此系统上有 72 种资源类型可用。其中许多资源类型在核心 Puppet 产品中已经提供,因此在 Oracle Solaris 11 环境中并无甚意义。但是,拥有这些资源类型意味着,只要您想要,就可以作为代理管理非 Oracle Solaris 11 系统。我们可以使用带 --list 选项的 puppet describe 命令查看有关这些资源类型的更多信息,如清单 12 所示:
root@master:~# puppet describe --list These are the types known to puppet: address_object - Manage the configuration of Oracle Solaris ad ... address_properties - Manage Oracle Solaris address properties augeas - Apply a change or an array of changes to the ... boot_environment - Manage Oracle Solaris Boot Environments (BEs) computer - Computer object management using DirectorySer ... cron - Installs and manages cron jobs. Every cron re ... dns - Manage the configuration of the DNS client fo ... etherstub - Manage the configuration of Solaris etherstub ... exec - Executes external commands. It is critical th ... file - Manages files, including their content, owner ... filebucket - A repository for storing and retrieving file ... group - Manage groups. On most platforms this can onl ... host - Installs and manages host entries. For most s ... interface - This represents a router or switch interface. ... interface_properties - Manage Oracle Solaris interface properties ip_interface - Manage the configuration of Oracle Solaris IP ... ip_tunnel - Manage the configuration of Oracle Solaris IP ... ipmp_interface - Manage the configuration of Oracle Solaris IP ... k5login - Manage the `.k5login` file for a user. Specif ... ldap - Manage the configuration of the LDAP client f ... link_aggregation - Manage the configuration of Oracle Solaris li ... link_properties - Manage Oracle Solaris link properties macauthorization - Manage the Mac OS X authorization database. S ... mailalias - Creates an email alias in the local alias dat ... maillist - Manage email lists. This resource type can on ... mcx - MCX object management using DirectoryService ... mount - Manages mounted filesystems, including puttin ... nagios_command - The Nagios type command. This resource type i ... nagios_contact - The Nagios type contact. This resource type i ... nagios_contactgroup - The Nagios type contactgroup. This resource t ... nagios_host - The Nagios type host. This resource type is a ... nagios_hostdependency - The Nagios type hostdependency. This resource ... nagios_hostescalation - The Nagios type hostescalation. This resource ... nagios_hostextinfo - The Nagios type hostextinfo. This resource ty ... nagios_hostgroup - The Nagios type hostgroup. This resource type ... nagios_service - The Nagios type service. This resource type i ... nagios_servicedependency - The Nagios type servicedependency. This resou ... nagios_serviceescalation - The Nagios type serviceescalation. This resou ... nagios_serviceextinfo - The Nagios type serviceextinfo. This resource ... nagios_servicegroup - The Nagios type servicegroup. This resource t ... nagios_timeperiod - The Nagios type timeperiod. This resource typ ... nis - Manage the configuration of the NIS client fo ... notify - Sends an arbitrary message to the agent run-t ... nsswitch - Name service switch configuration data package - Manage packages. There is a basic dichotomy i ... pkg_facet - Manage Oracle Solaris package facets pkg_mediator - Manage Oracle Solaris package mediators pkg_publisher - Manage Oracle Solaris package publishers pkg_variant - Manage Oracle Solaris package variants protocol_properties - Manage Oracle Solaris protocol properties resources - This is a metatype that can manage other reso ... router - Manages connected router. schedule - Define schedules for Puppet. Resources can be ... scheduled_task - Installs and manages Windows Scheduled Tasks. ... selboolean - Manages SELinux booleans on systems with SELi ... selmodule - Manages loading and unloading of SELinux poli ... service - Manage running services. Service support unfo ... solaris_vlan - Manage the configuration of Oracle Solaris VL ... ssh_authorized_key - Manages SSH authorized keys. Currently only t ... sshkey - Installs and manages ssh host keys. At this p ... stage - A resource type for specifying run stages. Th ... svccfg - Manage SMF service properties with svccfg(1M) ... tidy - Remove unwanted files based on specific crite ... user - Manage users. This type is mostly built to ma ... vlan - Manages a VLAN on a router or switch. vni_interface - Manage the configuration of Solaris VNI inter ... vnic - Manage the configuration of Oracle Solaris Vi ... whit - Whits are internal artifacts of Puppet's curr ... yumrepo - The client-side description of a yum reposito ... zfs - Manage zfs. Create destroy and set properties ... zone - Manages Solaris zones.
清单 12
在深入讨论如何配置系统之前,我们先基于清单 11 和清单 12 中看到的资源类型使用 Puppet 查询系统。我们将使用相应的资源类型运行 puppet resource 命令。puppet resource 命令将当前系统状态转换成 Puppet 的声明式语言,后者可用于在其他系统上实施配置。例如,我们使用 service 资源类型查询本系统的服务状态:
root@master:~# puppet resource service
service { 'svc:/application/cups/scheduler:default':
ensure => 'running',
enable => 'true',
}
...
service { 'svc:/system/zones-install:default':
ensure => 'running',
enable => 'true',
}
service { 'svc:/system/zones-monitoring:default':
ensure => 'running',
enable => 'true',
}
service { 'svc:/system/zones:default':
ensure => 'running',
enable => 'true',
}
清单 13
在清单 13 中,我们可以看到由服务名标识的各资源的列表。每种资源有两个属性 — ensure 和 enable,各有一个关联的值。这是 Puppet 声明式语言的核心。资源可以描述为如清单 14 所示:
resource_type { 'title':
attribute1 => 'value1',
attribute2 => 'value2',
}
清单 14
每个 resource_type 有一个 title,是 Puppet 使用的标识字符串,对于每种资源类型必须是唯一的。属性描述资源的期望状态。大多数资源拥有一组必需的属性,同时还包括一组可选属性。此外,每种资源类型还有一个特殊属性 namevar,它由目标 系统使用,必须是唯一的。如果未指定 namevar,通常默认为 title。这在计划管理多个平台时很重要。例如,假设您希望确保在 Oracle Solaris 11 和 Red Hat Enterprise Linux 上都安装了 NTP 服务。可以将该资源统一命名为 ntp,但 Oracle Solaris 11 上可能会使用 service/network/ntp 作为 namevar,Red Hat Enterprise Linux 上可能会使用 ntpd 作为 namevar。
现在,我们使用 zone 资源类型查询主服务器上配置或安装的全局区域和任何非全局区域的当前状态:
root@master:~# puppet resource zone
zone { 'global':
ensure => 'running',
brand => 'solaris',
iptype => 'shared',
zonepath => '/',
}
清单 15
在清单 15 中,我们可以看到此系统上并无任何非全局区域,只有全局区域。
最后,我们通过查看 pkg_publisher 资源类型,看看配置了哪些映像包管理系统发布者,如清单 16 所示:
root@master:~# puppet resource pkg_publisher
pkg_publisher { 'solaris':
ensure => 'present',
enable => 'true',
origin => ['http://pkg.oracle.com/solaris/beta'],
searchfirst => 'true',
sticky => 'true',
}
清单 16
我们已经配置了 Puppet 主服务器和代理,稍微了解了资源类型以及如何声明资源,现在可以开始在代理上实施某些配置。
Puppet 使用主站点清单(位于 /etc/puppet/manifests/site.pp 中),管理员可在此集中定义应在所有代理系统上实施的资源。随着您更熟悉 Puppet,建议采用以下方法:
site.pp。本文不打算介绍 Puppet 类的使用,但是将使用 site.pp 定义资源。
为简单起见,我们来了解一下 file 资源类型。我们来修改 /etc/puppet/manifests/site.pp,在其中包括以下资源声明:
file { '/custom-file.txt':
ensure => 'present',
content => "Hello World",
}
清单 17
清单 17 所示声明使用 file 资源类型和两个属性(ensure 和 content)确保 custom-file.txt 文件存在于代理节点的根目录中,且该文件包括内容“Hello World”。
保存 /etc/puppet/manifests/site.pp 文件之后,我们可以使用 puppet apply 命令测试它是否有效。我们将使用 -v 选项增加输出的详细程度,并使用 --noop 选项确保不会进行任何更改(本质上就是试运行),如清单 18 所示:
root@master:~# puppet apply -v --noop /etc/puppet/manifests/site.pp Notice: Compiled catalog for master in environment production in 0.16 seconds Info: Applying configuration version '1400794990' Notice: /Stage[main]/Main/File[/custom-file.txt]/ensure: current_value absent, should be present (noop) Notice: Class[Main]: Would have triggered 'refresh' from 1 events Notice: Stage[Main]: Would have triggered 'refresh' from 1 events Notice: Finished catalog run in 0.27 seconds
清单 18
我们可以选择将该资源应用于主服务器本身:删除 --v 和 --noop 选项,再次运行 puppet apply,然后检查 custom-file.txt 文件是否存在及其内容,如清单 19 所示:
root@master:~# puppet apply /etc/puppet/manifests/site.pp Notice: Compiled catalog for master in environment production in 0.16 seconds Notice: /Stage[main]/Main/File[/custom-file.txt]/ensure: created Notice: Finished catalog run in 0.28 seconds root@master:~# ls -la /custom-file.txt -rw------- 1 root root 15 May 22 21:45 /custom-file.txt root@master:~# cat /custom-file.txt Hello World
清单 19
默认情况下,代理每隔 30 分钟(如果需要,可在配置中更改此时间间隔)联络主服务器一次。通过查看 custom-file.txt 文件是否出现并查看 /var/log/puppet/puppet-agent.log 中的 Puppet 代理日志,我们可以检查 Puppet 是否已实施此配置:
root@agent:~# ls -la /custom-file.txt -rw------- 1 root root 15 May 22 21:50 /custom-file.txt root@agent:~# cat /custom-file.txt Hello World root@agent:~# tail /var/log/puppet/puppet-agent.log .... 2014-05-22 21:50:17 +0000 /Stage[main]/Main/File[/custom-file.txt]/ensure (notice): created 2014-05-22 21:50:17 +0000 Puppet (notice): Finished catalog run in 0.21 seconds
清单 20
如清单 20 所示,配置成功实施,且已在代理系统上创建该文件。
Puppet 使用一个名为 Facter 的工具收集有关特定节点的信息,并将其发送到 Puppet 主服务器。此信息用于确定应将何种系统配置应用于节点。要查看有关某节点的某些“事实”,我们可以使用 facter 命令,如清单 21 所示:
root@master:~# facter osfamily Solaris root@master:~# facter operatingsystem Solaris root@master:~# facter ipaddress 10.0.2.15 root@master:~# facter hostname solaris
清单 21
要列出某节点的所有事实,我们可以使用 -p 选项:
root@master:~# facter -p architecture => i86pc facterversion => 1.6.18 hardwareisa => i386 hardwaremodel => i86pc hostname => solaris id => root interfaces => lo0,net0 ipaddress => 10.0.2.15 ipaddress6 => :: ipaddress_lo0 => 127.0.0.1 ipaddress_net0 => 10.0.2.15 ipaddress_net1 => 10.1.1.5 ... uptime => 0:22 hours uptime_days => 0 uptime_hours => 0 uptime_seconds => 1320 virtual => virtualbox
清单 22
如清单 22 所示,可查询给定系统上的各种不同事实。这些事实可作为全局变量在资源内公开,这些全局变量可帮助以编程方式决定应实施何种配置。
例如,我们来看看如何声明一个 file 资源才能用针对不同平台用不同内容填充一个文件。我们将使用 osfamily 事实检测平台:
$file_contents = $osfamily ? {
'redhat' => "Hello RHEL",
'solaris' => "Hello Oracle Solaris",
}
file { '/custom-file.txt':
ensure => 'present',
content => $file_contents,
}
清单 23
在清单 23 中,我们创建了一个名为 $file_contents 的新变量,并使用 osfamily 事实提供了一个条件检查。然后,将根据不同平台类型为文件分配不同的内容。
管理各种系统的配置时,管理员可能希望提供一些条件逻辑来控制如何将节点与相应配置匹配。为此,我们可以在清单中使用 node 关键字。例如,如果希望匹配名为 agent1.oracle.com 的特定主机的配置,可以使用清单 24 所示的内容:
node agent1.oracle.com {
# Include resources here
}
清单 24
或者,为了匹配 agent1.oracle.com 和 agent2.oracle.com,但为 agent3.oracle.com 提供单独的资源定义,可以使用清单 25 所示内容:
node agent1.oracle.com, agent2.oracle.com {
# Include resources here
}
node agent3.oracle.com {
# Include other resources here
}
清单 25
使用 default 作为节点名是特殊的,可以在节点与其他节点定义不匹配时有一个回退配置。回退配置可以定义成如清单 26 所示:
node default {
# Insert other resources here
} 清单 26
我们已经介绍了 Puppet 的基础知识,下面看看为支持管理 Oracle Solaris 11.2 系统而添加的特定资源类型和提供者。这些资源类型让管理员能够管理许多 Oracle Solaris 技术,包括打包、服务、ZFS、Oracle Solaris 区域和各种网络配置。
我们首先看看 zone 资源类型。为了更好地了解可以设置哪些属性,我们将再次使用 puppet describe 命令查看文档:
root@master:~# puppet describe zone
zone
====
Manages Solaris zones.
Parameters
----------
- **archive**
The archive file containing an archived zone.
- **archived_zonename**
The archived zone to configure and install
- **brand**
The zone's brand type
- **clone**
Instead of installing the zone, clone it from another zone.
If the zone root resides on a zfs file system, a snapshot will be
used to create the clone; if it resides on a ufs filesystem, a copy of
the
zone will be used. The zone from which you clone must not be running.
- **config_profile**
Path to the config_profile to use to configure a solaris zone.
This is set when providing a sysconfig profile instead of running the
sysconfig SCI tool on first boot of the zone.
- **ensure**
The running state of the zone. The valid states directly reflect
the states that `zoneadm` provides. The states are linear,
in that a zone must be `configured`, then `installed`, and
only then can be `running`. Note also that `halt` is currently
used to stop zones.
Valid values are `absent`, `configured`, `installed`, `running`.
- **id**
The numerical ID of the zone. This number is autogenerated
and cannot be changed.
- **install_args**
Arguments to the `zoneadm` install command. This can be used to create
branded zones.
- **iptype**
Displays exclusive or shared instance of IP.
- **name**
The name of the zone.
- **sysidcfg**
The text to go into the `sysidcfg` file when the zone is first
booted. The best way is to use a template:
# $confdir/modules/site/templates/sysidcfg.erb
system_locale=en_US
timezone=GMT
terminal=xterms
security_policy=NONE
root_password=<%= password %>
timeserver=localhost
name_service=DNS {domain_name=<%= domain %> name_server=<%= nameserver %>}
network_interface=primary {hostname=<%= realhostname %>
ip_address=<%= ip %>
netmask=<%= netmask %>
protocol_ipv6=no
default_route=<%= defaultroute %>}
nfs4_domain=dynamic
And then call that:
zone { myzone:
ip => "bge0:192.168.0.23",
sysidcfg => template("site/sysidcfg.erb"),
path => "/opt/zones/myzone",
realhostname => "fully.qualified.domain.name"
}
The `sysidcfg` only matters on the first booting of the zone,
so Puppet only checks for it at that time.
- **zonecfg_export**
Contains the zone configuration information. This can be passed in
in the form of a file generated by the zonecfg command, in the form
of a template, or a string.
- **zonepath**
The path to zone's file system.
Providers
---------
solaris
清单 27
在清单 27 中,我们可以看到其中一个名为 zonecfg_export 的属性可以让我们提供区域配置文件。现在我们使用 zonecfg 命令快速创建一个区域,如清单 28 所示。暂时将该区域命名为 testzone,但使用 zone 资源类型时可以更改区域名称。
root@master:~# zonecfg -z testzone
Use 'create' to begin configuring a new zone.
zonecfg:testzone> create
create: Using system default template 'SYSdefault'
zonecfg:testzone> export -f /tmp/zone.cfg
zonecfg:testzone> exit
root@master:~# cat /tmp/zone.cfg
create -b
set zonepath=/system/zones/%{zonename}
set autoboot=false
set autoshutdown=shutdown
set ip-type=exclusive
add anet
set linkname=net0
set lower-link=auto
set configure-allowed-address=true
set link-protection=mac-nospoof
set mac-address=auto
end
清单 28
现在,我们可以在清单中定义区域了,如下所示:
zone { 'myzone':
zonecfg_export => '/tmp/zone.cfg',
ensure => 'installed',
}
清单 29
在清单 29 中,您会注意到我们提供了值 /tmp/zone.cfg 作为区域配置文件,并将 ensure 属性设置为 installed。值 ensure 与区域状态 configured、installed 和 running 匹配。在本例中,我们将在代理节点上创建一个名为 myzone 的区域。应用配置之后,等待看节点上会发生什么:
root@agent:~# zoneadm list -cv ID NAME STATUS PATH BRAND IP 0 global running / solaris shared - myzone installed /system/zones/myzone solaris excl
清单 30
正如我们在清单 30 可以看到的,区域现已配置和安装完毕,可以引导了。
现在,我们将使用 package 资源类型通过映像包管理系统添加新的软件包。
首先确认软件包现在未安装在代理节点上,如清单 31 所示:
root@agent:~# pkg info nmap
pkg: info: no packages matching the following patterns you specified are
installed on the system. Try specifying -r to query remotely:
nmap
root@agent:~# pkg info -r nmap
Name: diagnostic/nmap
Summary: Network exploration tool and security / port scanner.
Description: Nmap is useful for inventorying the network, managing service
upgrade schedules, and monitoring host or service uptime.
Category: System/Administration and Configuration
State: Not installed
Publisher: solaris
Version: 6.25
Build Release: 5.11
Branch: 0.175.2.0.0.37.1
Packaging Date: April 14, 2014 06:21:31 PM
Size: 18.47 MB
FMRI: pkg://solaris/diagnostic/nmap@6.25,5.11-0.175.2.0.0.37.1:20140414T182131Z
清单 31
这种的资源定义很简单。我们只需将标题设置为 nmap 并确保该软件包存在,如清单 32 所示:
package { 'nmap':
ensure => 'present',
}
清单 32
稍后即可检查代理节点,确保软件包已正确安装,如清单 33 所示:
root@agent:~# pkg info nmap
Name: diagnostic/nmap
Summary: Network exploration tool and security / port scanner.
Description: Nmap is useful for inventorying the network, managing service
upgrade schedules, and monitoring host or service uptime.
Category: System/Administration and Configuration
State: Installed
Publisher: solaris
Version: 6.25
Build Release: 5.11
Branch: 0.175.2.0.0.37.1
Packaging Date: April 14, 2014 06:21:31 PM
Size: 18.47 MB
FMRI: pkg://solaris/diagnostic/nmap@6.25,5.11-0.175.2.0.0.37.1:20140414T182131Z
清单 33
我们之前曾提到过 Puppet 实施配置。因此,我们试着从代理节点删除该软件包:
root@agent:~# pkg uninstall nmap
Packages to remove: 1
Services to change: 1
Create boot environment: No
Create backup boot environment: No
Planning linked: 0/1 done; 1 working: zone:myzone
Planning linked: 1/1 done
Downloading linked: 0/1 done; 1 working: zone:myzone
Downloading linked: 1/1 done
PHASE ITEMS
Removing old actions 913/913
Updating package state databasea Done
Updating package cache 1/1
Updating image state Done
Creating fast lookup database Done
Executing linked: 0/1 done; 1 working: zone:myzone
Executing linked: 1/1 done
Updating package cache 1/1
root@agent:~# which nmap
no nmap in /usr/bin /usr/sbin
清单 34
如清单 34 所示,目前未安装该软件包。但当代理节点稍后联络主服务器时,软件包一定已经重新安装,如清单 35 所示:
root@agent:~# pkg info nmap
Name: diagnostic/nmap
Summary: Network exploration tool and security / port scanner.
Description: Nmap is useful for inventorying the network, managing service
upgrade schedules, and monitoring host or service uptime.
Category: System/Administration and Configuration
State: Installed
Publisher: solaris
Version: 6.25
Build Release: 5.11
Branch: 0.175.2.0.0.37.1
Packaging Date: April 14, 2014 06:21:31 PM
Size: 18.47 MB
FMRI: pkg://solaris/diagnostic/nmap@6.25,5.11-0.175.2.0.0.37.1:20140414T182131Z
清单 35
举一个最简单的例子,使用以下资源定义用 zfs 资源类型创建一个 ZFS 数据集。我们还会将一个名为 readonly 的属性设置为 on,如清单 36 所示:
zfs { 'rpool/test':
ensure => 'present',
readonly => 'on',
}
清单 36
我们很快可以确认创建了一个新的 ZFS 数据集并且设置了 readonly 数据集属性,如清单 37 所示:
root@agent:~# zfs list rpool/test NAME USED AVAIL REFER MOUNTPOINT rpool/test 31K 31.8G 31K /rpool/test root@agent:~# zfs get readonly rpool/test NAME PROPERTY VALUE SOURCE rpool/test readonly on local
清单 37
如前所述,所有 Puppet 配置均通过服务管理工具模板管理。应避免直接编辑 /etc/puppet/puppet.conf,因为当 Puppet 服务管理工具服务重新启动时,此类编辑将丢失。相反,可以使用 svccfg 和 puppet.conf(5) 中定义的配置属性实现配置,如清单 38 所示:
root@master:~# svccfg -s puppet:master setprop config/<option> = "<value>" root@master:~# svccfg -s puppet:master refresh
清单 38
使用服务管理工具存储 Puppet 配置还可以非常轻松地配置 Puppet 环境,这在将数据中心划分成任意数量的环境时非常有用。
例如,可以让 Puppet 主服务器管理开发环境和生产环境的配置。这可以通过创建 Puppet 服务的新服务管理工具实例轻松实现,如清单 39 所示:
root@master:~# svccfg -s puppet svc:/application/puppet> add production svc:/application/puppet> add dev svc:/application/puppet> exit root@master:~# svccfg -s puppet:production setprop config/modulepath = \ "$confdir/environments/$environment/modules:$confdir/modules" root@master:~# svccfg -s puppet:dev setprop config/manifest = "$confdir/manifests/site-dev.pp"
清单 39
Puppet 是一个出色的工具,适合希望在数据中心中跨多种平台实施配置管理的管理员。本文简要介绍了 Puppet 的一小部分功能。通过对一组新的基于 Oracle Solaris 11 的资源类型(包括打包、服务配置、联网、虚拟化和数据管理)的支持,管理员现在可以得益于先前在基于 Linux 的平台上实现的那种自动化。
下面是一些 Puppet 资源:
以下是有关 Oracle Solaris 11 的一些资源:
Glynn Foster 是 Oracle Solaris 首席产品经理。他负责多个技术领域,包括 OpenStack、Oracle Solaris 映像包管理系统、安装和配置管理。
| 修订版 1.0,2014 年 5 月 30 日 |