Puppet
最后我们还得了解下puppet的一些配置和一些功能,主流用法在前面三章已经说的差不多了,这里我在记录下杂乱的点点滴滴。
puppet多环境支持
master环境配置端:
1 | [master] |
2 | environment = production,testing,development |
3 | |
4 | [production] |
5 | manifest = /etc/puppet/environments/production/manifests/site.pp |
6 | modulepath = /etc/puppet/environments/production/modules/ |
7 | fileserverconf = /etc/puppet/fileserver.conf |
8 | |
9 | [testing] |
10 | manifest = /etc/puppet/environments/production/manifests/site.pp |
11 | modulepath = /etc/puppet/environments/production/modules/ |
12 | fileserverconf = /etc/puppet/fileserver.conf |
13 | |
14 | [development] |
15 | manifest = /etc/puppet/environments/production/manifests/site.pp |
16 | modulepath = /etc/puppet/environments/production/modules/ |
17 | fileserverconf = /etc/puppet/fileserver.conf |
agent环境配置端:
1 | [agent] |
2 | environment = development |
可以通过以上配置在不同的应用环境中配置不同的puppet环境。
puppet的配置
puppet自带一个puppet的文件服务器,如三章中我们想要获得webserver的nginx.conf的配置文件可以通过如下属性配置获得:
1 | source => "puppet:///modules/webserver/nginx.conf" |
如果我们是通过以上的模块来获取文件,我们是不需要配置fileserver.conf的,如果我们想要从一个目录传输文件而不是一个模块,我们就需要在这个fileserver.conf中创建一个挂载点。
exmaple:
1 | [extra_files] |
2 | path /etc/puppet/files/ |
3 | allow * |
这个配置我们可以通过puppet:///extra_file/<file name>
来获取/etc/puppet/files/中的文件。
挂载点还可以使用三个以下占位符来作为路径的一部分:
- %H 节点的认证名(全名)
- %h 节点的短名
- %d 节点的域名
针对这个文件系统我们还可以进行权限控制,这个的控制需要在auth.conf中配置。
1 | path ~ ^/file_(metadata|content)/extra_files/ |
2 | auth yes |
3 | allow /^(.+)\.example\.com$/ |
4 | allow_ip 192.168.100.0/24 |
这个的生效结果是结合了puppet.conf与auth.conf,用于实现安全配置
auth.conf认证配置文件,为puppet提供acl类似的功能,主要实现puppet的restful的api接口的控制
1 | path:api的路径 |
2 | auth:是否需要证书认证的节点 |
3 | method: find(读) save(写) |
4 | allow:权限控制 |
puppet.conf主配置文件:
1 | [main] |
2 | vardir = /var/lib/puppet |
3 | confdir = /etc/puppet |
4 | logdir = /var/log/puppet |
5 | rundir = /var/run/puppet |
6 | ssldir = $vardir/ssl |
7 | fileserverconfig = /etc/puppet/fileserver.conf |
8 | manifestdir = /etc/puppet/manifests #可不指定默认读取此目录 |
9 | manifest = /etc/puppet/manifests/site.pp #主机文件默认读取 |
10 | modulepath = /etc/puppet/modules:/usr/share/puppet/modules |
11 | authconfig = /etc/puppet/namespaceauth.conf #如果开启Listen为true需要配置此文件 |
12 | pluginsync = true #插件同步配置对facter自定义有效 |
13 | reportdir = /var/lib/puppet/reports #报告文件生成目录,目录以主机名命令开头 |
14 | reports = log, foreman #报告的方式与类型 |
15 | environment = production 运行环境配置,默认为生产环境 |
16 | |
17 | [agent] |
18 | classfile = $vardir/classes.txt |
19 | localconfig = $vardir/localconfig |
20 | runinterval = 1800 #客户端默认探测时间,可按需求修改 |
21 | listen = true #是否监听,执行puppet kick时需要配置 |
22 | report = true #客户端的报告系统配置,不同于Master此项的主要目的是将报告发送至Master,主要用于客户端puppet.conf配置 |
23 | report_port = 8140 #监听端口,如果服务器配置有防火墙,需开放此端口 |
24 | report_server = server #默认不填,此时以下面的$server变量值为准 |
25 | server = server.domain.com |
26 | |
27 | [master] #服务端配置选项 |
28 | certname = server.domain.com #也可以不定义,以主机名为准 |
29 | reports = store, http, tagmail, log |
30 | reporturl = http://server.domain.com:3000/reports/upload #报告发送地址,可配置在dashboard或foreman配置文件中 |
31 | autosign = /etc/puppet/autosign.conf #自动认证配置文件 |
autosign.conf 自动签署配置
1 | *.jusene.com |
puppet master主动推送
在agent上配置:
1 | ~]# cat /etc/puppet/puppet.conf |
2 | [agent] |
3 | listen = true |
4 | ~]# cat /etc/puppet/auth.conf |
5 | path /run |
6 | auth any |
7 | method save |
8 | allow puppet.master.com |
9 | |
10 | 这里的path配置必须在path /前面,不然会报错 |
11 | |
12 | ~]# systemctl restart puppetagent |
13 | ~]# netstat -ntlp |
14 | Active Internet connections (only servers) |
15 | Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name |
16 | tcp 0 0 0.0.0.0:8139 0.0.0.0:* LISTEN 11502/ruby |
8139端口开放,测试主动推送:
1 | ~]# uppet kick -p 10 --host node2.localdomain |
2 | Warning: Puppet kick is deprecated. See http://links.puppetlabs.com/puppet-kick-deprecation |
3 | Warning: Failed to load ruby LDAP library. LDAP functionality will not be available |
4 | Triggering node2.localdomain |
5 | Getting status |
6 | status is success |
7 | node2.localdomain finished with exit code 0 |
8 | Finished |
成功