Puppet目录结构 配置文件
目录结构
- 源码目录结构
待补充。。。 - 主配置文件及目录结构
默认配置文件都放在/etc/puppet下。目录结构如下:
/etc/puppet
|-- auth.conf
|-- autosign.conf
|-- files/
|-- fileserver.conf
|-- mainfests/
|-- site.pp
|-- module/
|-- _apache
|-- template/
|-- mainfests/
|-- init.pp
|-- file/
|-- puppet.conf
|-- ssl/
|-- tagmail.conf
|--namespaceauth.conf
主要配置文件介绍
1. puppet.conf
/etc/puppet/puppet.conf
配置文件是Master的守护进程的主配置文件,文件定义了Master的运行环境、启动加载文件、Puppet的配置管理程序和授权Agent的证书目录等主要信息。守护进程启动前会根据此配置文件信息对系统环境进行预检,预检成功后守护进程才会启动。
1.1 puppet.conf配置文件的位置
企业版本:/etc/puppletlabs/puppet
社区版本:/etc/puppet
1.2 puppet.conf配置文件格式
puppet.conf
被划为3个区段,每一区段用来配置puppet的一个特定部分。
[agent] 段用于Agent部分配置;
[master]段用于Master部分配置;
[main]段用于全局配置。
puppet所有组件都遵循[main]段指定的配置。
例如:
[main]
# 指定了puppet服务器的地址
server = puppet.example.com
# 是否实时刷新日志到磁盘
autoflash = false
# 日志目录
logdir = /var/log/puppet
# puppet进程pid文件存放目录
rundir = /var/run/puppet
[master]
# 报告存放目录,客户端的每次执行会执行一份以日期+时间命名yaml文件报告
reportdir = /var/lib/puppet/reports
# 自动授权签名配置文件
autosign = true
autosign = /etc/puppet/autosign.conf
# puppetmaster服务端监听地址
bindaddress = 0.0.0.0
# puppetmaster服务端监听端口
masterport = 8140
# 通过此参数看到执行过程中的过程和变化
evaltrace = true
[agent]
# 客户端的名字
certname = puppet.example.com
# 是否后台运行
daemonize = true
# 是否允许证书自动覆盖,默认不允许,每个证书的有效期是5年
allow_duplicate_certs = ture
# 是否上传客户端对recources的执行结果(puppet2.7以上自动开启)
report = true
# 上传的方式
reports = store, http
# store上传时的地址
report_server = puppet.example.com
# store上传时的端口
report_port = 8140
# http上传时的地址
reporturl = http://192.168.1.1:3000/reports/upload
# 客户端执行间隔(20min),如果不设置默认为30min
runinterval = 20m
# 是否在执行时间上另加一个随机时间(0到最大随机时间之间的一个整数值)
splay = true
# 加的随机时间的最大长度
splaylimit = 10m
# 客户端获取配置的超时时间
configtimeout = 2m
# 日志记录是否加颜色
color = ansi
# 是否忽略本地缓存
ignorecache = true
1.3 puppet.conf配置文件案例
puppet.conf是master守护进程的主要配置文件,在修改puppet.conf配置文件之前,首先通过以下命令来生成一份puppet.conf配置文件:
# puppet 2.x
puppetmastered --genconfig
# puppet 3.x (puppet3以上版本不再提供puppetmastered命令)
puppet master --genconfig
默认生成的配置文件有200多个参数,但是实际不是所有参数都用得到,也不是所有参数都需要更改,很多参数可以保持默认值。关于master的参数配置信息,可以参考官方网站.
以下是puppet.conf配置文件的常用配置参数:
[master]
bindaddress = 0.0.0.0
masterport = 8140
ssldir = /etc/puppet/server_ssl
logdir = /data1/puppet
manifest = /etc/puppet/manifest/site.pp
modulepath = /etc/puppet/modules
certname = puppet.example.com
[agent]
report = true
各参数的含义:
- bindaddress: 指定网卡接口,如果不设定,默认绑定在IP地址0.0.0.0上。此参数通常用在特殊网络环境下配置监听指定的网卡。
- masterport: master启动后绑定的端口,默认8140.
- ssldir:master存放签名文件的配置路径。
- logdir: 存放agent上报日志的路径。
- manifest:anget连接master的起始配置的目录。
- modulepath:module是基础模块与配置文件的存放路径。
- certname:设置master的FQDN(全称域名),另外certname配置添加FQDN还可以解决证书的相关问题。
- report: 开启agent的日志上报开关。
2. auth.conf介绍
master本身是由webserver提供agent访问,如果没有权限控制,agent就可以遍历master服务器上所有资源,这是非常不安全的。auth.conf主要负责agent访问master上一些目录和配置文件的权限和认证,官方名称是HTTP Network API。为了网络访问安全,agent在访问master过程中,使用https协议进行通信交互,基本访问格式如下:
https://{server}:{port}/{environment}/{resource}/{key}
master会根据auth.conf中的配置来限制agent的来源(包括IP、域名或环境列与表等)。限制访问master某一个目录或一些目录的权限,有了auth.conf权限配置文件,就会使master服务器更加安全。
更多关于auth.conf的信息可以参考官网
2.1 auth.conf权限控制列表格式
path [~] {/path/to/resource|regex}
[environment {list of environment}]
[method {list of method}]
[auth[enthicated]{yes|no|on|off|any}]
[allow {hostname|certname|*}]
auth.conf配置文件包含7个参数,分别是path, environment, method, auth, allow, allow_ip和deny. 每个参数都有自己独立的值,通过这7个参数的自由组合,就形成了agent访问master目录的ACL。各个参数的含义如下:
- path:指定ACL的路径,后接系统路径、正则表达式、路径前缀和资源等信息。
- environment:它可以包含一个环境或多个环境列表,如果不设置默认为所有环境。puppet的环境主要用于灰度功能。
- method:包含find, search, save和destroy.可以在method后设置任意一个参数或用逗号做分割设置多参数,默认是设置所有参数。
- auth:包含yes或on,any和no或off。默认为yes或on。
- auth设置为yes或on,表示匹配哪些已经通过认证的agent请求。
- 设置为any,表示只匹配认证进行中和没有被认证的请求。
- 设置为no或off,表示陪陪未认证的agent请求,认证过的请求会跳过此ACL。
- allow: 它的值可以是hostname或certname,puppet2.7.1以后的版本还支持perl或ruby的正则表达式,如
allow /^[\w-]+.example.com$/
通过正则表达式来匹配hostname或certname。 - allow_ip:后接一个IP或一个IP段,表示允许指定的IP范围通过。
- deny:后接一个IP、多个IP、网段或域名等,表示禁止这些范围访问master的目录权限。
auth.conf配置文件举例
限定agent访问facts路径,只准许来自puppet1.example.com和puppet2.example.com的域访问。
path /facts
method find, search
auth yes
allow puppet1.example.com, puppet2.example.com
3. namespaceauth.conf介绍
/etc/puppet/namespaceauth.conf用于指定访问puppet的名称空间。并非必要文件,只有当puppet.conf文件中的listen=true
时才需要用到该配置文件,否则Puppet会报will not start without authorization file namespaceauth.conf
这样的错误。以下为namespaceauth.conf配置内容:
[fileserver]
allow *.domain.com
[puppetmaster]
allow *.domain.com
[puppetrunner]
allow culain.domain.com
[puppetbucker]
allow *.domain.com
[puppetreports]
allow *.domain.com
[resources]
allow server.domain.com
4. autosign.conf介绍
用于自动签名证书功能,需要管理员手动创建。默认agent访问master时管理员需要手动授权agent证书签名。
允许所有来源agent自动授权证书签名:
# cat /etc/puppet/autosign.conf
*
允许某域名的agent自动授权:
# cat /etc/puppet/autosign.conf
*.example.com
5. fileserver.conf介绍
fileserver.conf是master目录的挂载配置文件,包含master的挂载目录位置和挂载目录的授权信息等。并非必要文件,只有在agent服务器从master获取一个文件或文件列表是才会用到。fileserver.conf配置模板如下:
[mount_point]
path /path/to/files
allow *.example.com
deny *.wireless.example.com
6. tagmail.conf介绍
tagmail.conf是puppet发送邮件程序的配置文件。master支持在检测到某一资源发生变化时,通过邮件通知一个或多个系统管理员的功能。通过修改master和agent上的配置文件就可以实现这个需求。开启邮件配置功能需要以下几个步骤:
1. 在agent的puppet.conf中设置 report = true, 打开上报开关(2.7以上版本自动打开)。
2. 在master的puppet.conf中设置 report = tagmail, 设置tagmail报告处理器。
3. 在master的puppet.conf中设置reportfrom值,用来发送邮件的邮箱名称,默认是“Report@系统FQDN名”,同时还要设置发送邮件的服务器smtpserver或sendmail。
* sendmail: 默认为/usr/bin/sendmail
* smtpserver: 默认为空
4. 在master的puppet.conf中设置 tagmap = /etc/puppet/tagmail.conf.
5. 将管理员追加到tagmail.conf中,例如:
all:log-archive@example.com
webserver, !mailserver: httpadmins@example.com
emerg,crit: james@example.com, zach@example.com