|
1.节点管理节点node即,agent。每个节点文件定义主机名时可以是一个、一组。所有节点都需要在site.pp中进行定义,采用import的方式进行引用。puppet在进行验证时,都是以主机名(hostname)进行。例子:(1)单节点以主机名命名节点配置文件vi /etc/puppet/manifests/nodes/test.domian.com.ppnode 'test.domian.com' {include nginx$vhost = 'linuxone.org'}在site.pp中引用 vi /etc/puppet/manifests/site.ppimport "nodes/test.domian.com.pp"
(2)节点分组vi /etc/puppet/manifests/nodes/testgroups.ppnode 'test1.domian.com' {include nginx$vhost = 'linuxone.org'}node 'test2.domian.com' {include nginx$vhost = 'linuxone.org'}node 'test3.domian.com' {include nginx$vhost = 'linuxone.org'}也可以使用正则表达式定义:node /^test\d+\.domian\.com$/{include nginx$vhost = 'linuxone.org'}再在site.pp中引用 vi /etc/puppet/manifests/site.ppimport "nodes/testgroups.pp"
(3)nodes下面也可以有多个节点配置文件,在site.pp中引用所有。如果存在多个目录,只需要引入多个目录.例如:vi /etc/puppet/manifests/site.ppimport "nodes/test/*.pp"import "nodes/test2/*.pp"
或者:import "nodes/*/*.pp"
2. 节点继承2.1采用定义一个basenode默认节点的方法进行配置,其他主机节点采用"inherits"继承basenode的配置信息,具体如下node basenode {$my_puppet_server = "10.42.0.10"$my_local_network = "10.42.0.0/24"}node 'www.domain.com' inherits basenode{include generalinclude httpd:php}如果所继承的变量$my_ntp_server 的值与默认basenode不同,可以直接在节点中重新声明。
2.2默认类与默认节点定义默认节点配置与定义默认类baseclass的目的相同:为所有节点应用相同全局变量并进行系统环境初始化。定义默认类general,并将所有节点需要引用的类通过incluse到general中。class general {include yumincluse hostsinclude puppet}
2.3还可以定义default,如果没有明确定义一个节点,将默认按default操作。例如:node default {$my_puppet_server = "10.42.0.10"$my_local_network = "10.42.0.0/24"include ntp}
3.factor管理3.1Factor是puppet跨平台的系统性能分析库。它能发现并报告每个节点的信息,在puppet代码中以变量的形式存在。在安装puppet时,默认会安装factor在puppet中自定义变量中是通过在配置文件中定义变量的值进行content传递,factor是通过命令或许系统信息传递自定义变量:$var = "welocome"file {'welcome':path => '/tmp/welcome',content => $var,}factor使用:host { 'self':ensure => present,ipadd => $ipaddress,name => $fqdn,}
3.2 factor常用变量$factor可以查看agent相关factor信息$operatingsystem $fqdn$ipaddress$memory$hostname$processor$swap
4.标签tag通过tag,puppet可以实现资源的引用、判断,主要功能:收集资源,分析报告,限制catalog运行。tag元参数用于为资源加标签,tag函数用于为容器添加标签,tagged函数用于判断一个容器是否有某个标签4.1自动分配标签自用分配标签有两种:资源和容器。在编写manifests时,所使用资源都会被自动分配标签。比如,在nginx类中定义了package, service, file三个资源类型,那么该类将会自动收到nginx、file这样的标签资源所在的类、自定义类型、节点,即是这个资源的容器。资源会从所在容器中获取标签。如果资源或者容器的title中含有符号“/”,那么它将不会成为这个资源的tag。4.2 tag函数为容器加标签。类名就是这个类的标签。使用tag函数给类加标签,需要在最开始添加。例如,以下类ssh含有两个标签class ssh {tag("security"),service {'sshd':ensure => present,enable => true,}}
4.3 tagged 函数识别容器标签tagged函数能识别类名、函数名等识别,但是资源是无法用tagged进行判断的。例如:node 'agent.domain.com'{include testif tagged("filebucket") ----------------此处会报错{notify {"this is a file"} }if tagged("test"){notify {"this is a class"}}}
4.4资源标签在服务端查看资源自动分配的标签是使用puppet master 命令的--compile选项实现的例如: puppet master --compile agent.domain.com
注: 本文是《puppet实践》学习笔记。 |
|