三种注册方式
Puppet注册方式基本上有三种:手动注册,自动注册和预签名注册
1.手动注册
手动注册是由Agent端先发起证书申请请求,然后由Puppet server端确认证书方可注册成功,这种注册方式安全系数中等,逐一注册(puppet cert --sign certname)在节点数量较大的情况下是比较麻烦的,效率也低,批量注册(puppet cert --sign --all)效率很高,一次性便可注册所有的Agent的请求,但是这种方式安全系数较低,因为错误的请求也会被注册上。
2.自动注册
这种注册方式简单来讲是通过Puppet master端的ACL列表进行控制的,安全系统较低,也就是说符合预先定义的ACL列表中的所有节点请求不需要确认都会被自动注册上,也就是说你只需要知道ACL列表要求,其次能和PuppetMaster端通信便可轻易注册成功。当然,它的最大优点就是效率非常高.
(1)查询认证情况
root@10.1.1.33:puppet# puppet cert --list --all
+ "agent.domain.com" (SHA256) 3F:8E:AE:B8:04:2B:51:9B:7A:B3:1E:86:C0:21:3E:81:D6:2A:55:A4:17:15:CA:5E:7A:8F:95:EC:D3:83:41:C0
+ "localhost" (SHA256) E4:F5:F3:A9:99:E9:4D:11:53:87:BE:47:95:4C:98:48:58:2D:3D:80:7E:9C:D9:C2:36:93:56:B2:EA:A0:F1:7B
+ "puppet.domain.com" (SHA256) 5A:E1:80:AA:76:B6:81:22:55:B7:28:4B:AB:7C:B9:87:A8:DD:7E:3A:31:DF:0C:5A:61:8F:4B:D2:16:A4:B6:BF (alt names: "DNS:puppet", "DNS:puppet.domain.com")
(2)在master上清除客户端已经agent注册信息的证书
root@10.1.1.33:puppet# puppet cert --clean agent.domain.com
Notice: Revoked certificate with serial 7
Notice: Removing file Puppet::SSL::Certificate agent.domain.com at '/var/lib/puppet/ssl/ca/signed/agent.domain.com.pem'
Notice: Removing file Puppet::SSL::Certificate agent.domain.com at '/var/lib/puppet/ssl/certs/agent.domain.com.pem'
(3)在agent.domain.com端删除注册过的证书
root@10.1.1.33:puppet# puppet cert --clean agent.domain.com
Notice: Revoked certificate with serial 7
Notice: Removing file Puppet::SSL::Certificate agent.domain.com at '/var/lib/puppet/ssl/ca/signed/agent.domain.com.pem'
Notice: Removing file Puppet::SSL::Certificate agent.domain.com at '/var/lib/puppet/ssl/certs/agent.domain.com.pem'
(4)在Puppet master端编写ACL列表
root@10.1.1.33:puppet# cat autosign.conf
*.domain.com
root@10.1.1.33:puppet# /etc/init.d/puppetmaster restart
Stopping puppetmaster: [ OK ]
Starting puppetmaster: [ OK ]
(5)客户端申请注册证书.
root@10.1.1.34:ssl# puppet agent --test
Info: Creating a new SSL key for agent.domain.com
Info: Caching certificate for ca
Info: csr_attributes file loading from /etc/puppet/csr_attributes.yaml
Info: Creating a new SSL certificate request for agent.domain.com
Info: Certificate Request fingerprint (SHA256): FD:70:31:87:C6:44:EC:8D:18:0D:F5:10:E3:CE:5B:DC:EA:31:BD:BC:8C:C7:B2:80:F7:7E:2C:F2:4E:FB:12:90
Info: Caching certificate for agent.domain.com
Info: Caching certificate_revocation_list for ca
Info: Caching certificate for ca
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for agent.domain.com
Info: Applying configuration version '1418292313'
Notice: /Stage[main]/Test/File[/tmp/agent.txt]/ensure: defined content as '{md5}fc3ff98e8c6a0d3087d515c0473f8677'
Notice: Finished catalog run in 0.13 seconds
(6)服务端查看证书.
root@10.1.1.33:puppet# puppet cert --list --all
+ "agent.domain.com" (SHA256) FE:04:96:32:46:A4:54:BF:A9:4F:20:CA:EF:7E:F7:C6:A6:88:34:4A:D9:7E:50:54:FA:C0:10:29:87:F9:1C:6E
+ "client.domain.com" (SHA256) E3:B4:46:90:DF:85:37:77:48:BB:F9:FD:9F:13:DE:52:2F:00:1C:71:A3:BC:C2:E2:A5:34:4F:01:DB:27:02:F5
+ "localhost" (SHA256) E4:F5:F3:A9:99:E9:4D:11:53:87:BE:47:95:4C:98:48:58:2D:3D:80:7E:9C:D9:C2:36:93:56:B2:EA:A0:F1:7B
+ "puppet.domain.com" (SHA256) 5A:E1:80:AA:76:B6:81:22:55:B7:28:4B:AB:7C:B9:87:A8:DD:7E:3A:31:DF:0C:5A:61:8F:4B:D2:16:A4:B6:BF (alt names: "DNS:puppet", "DNS:puppet.domain.com")
3.预签名认证
预签名注册是在agent端未提出申请的情况下,预先在puppet master端生成agent端的证书,然后复制到节点对应的目录下即可注册成功,这种方式安全系数最高,但是操作麻烦,需要提前预知所有节点服务器的certname名称,其次需要将生成的证书逐步copy到所有节点上去。不过,如果你的系统中安装了kickstart或者cobbler这样的自动化工具,倒是可以将证书部分转换成脚本集成到统一自动化部署中.注:生产环境中建议此方式进行注册,既安全又可靠.
(1)查询认证情况
root@10.1.1.33:puppet# puppet cert --list --all
+ "agent.domain.com" (SHA256) 3F:8E:AE:B8:04:2B:51:9B:7A:B3:1E:86:C0:21:3E:81:D6:2A:55:A4:17:15:CA:5E:7A:8F:95:EC:D3:83:41:C0
+ "localhost" (SHA256) E4:F5:F3:A9:99:E9:4D:11:53:87:BE:47:95:4C:98:48:58:2D:3D:80:7E:9C:D9:C2:36:93:56:B2:EA:A0:F1:7B
+ "puppet.domain.com" (SHA256) 5A:E1:80:AA:76:B6:81:22:55:B7:28:4B:AB:7C:B9:87:A8:DD:7E:3A:31:DF:0C:5A:61:8F:4B:D2:16:A4:B6:BF (alt names: "DNS:puppet", "DNS:puppet.domain.com")
(2)在master上清除客户端已经agent注册信息的证书
root@10.1.1.33:puppet# puppet cert --clean agent.domain.com
Notice: Revoked certificate with serial 7
Notice: Removing file Puppet::SSL::Certificate agent.domain.com at '/var/lib/puppet/ssl/ca/signed/agent.domain.com.pem'
Notice: Removing file Puppet::SSL::Certificate agent.domain.com at '/var/lib/puppet/ssl/certs/agent.domain.com.pem'
(3)在agent.domain.com端删除注册过的证书
root@10.1.1.33:puppet# puppet cert --clean agent.domain.com
Notice: Revoked certificate with serial 7
Notice: Removing file Puppet::SSL::Certificate agent.domain.com at '/var/lib/puppet/ssl/ca/signed/agent.domain.com.pem'
Notice: Removing file Puppet::SSL::Certificate agent.domain.com at '/var/lib/puppet/ssl/certs/agent.domain.com.pem'
(4)puppet server端预先生成agent证书
puppetca --generate agent.domain.com
(5)agent节点生成目录结构
puppet agent --test
(6)puppet master端copy证书到agent.domain.com上
root@10.1.1.33:puppet#scp /var/lib/puppet/ssl/private_keys/agent.domain.com.pem agent.domain.com:/var/lib/puppet/ssl/private_keys/
root@10.1.1.33:puppet#scp /var/lib/puppet/ssl/certs/agent.domain.com.pem agent.domain.com:/var/lib/puppet/ssl/certs/
root@10.1.1.33:puppet#scp /var/lib/puppet/ssl/certs/ca.pem agent.domain.com:/var/lib/puppet/ssl/certs/ca.pem
常用命令
1.puppet master
puppet master 默认是以Ruby内建的WEBRick在后台运行的守护进程,同样也可以采用最常用的Web服务器apache和nginx替换WEBRick以提升性能.puppet master主要功能是编译配置文件,文件,模版,节点的自定义插件.
root@10.1.1.33:nodes# puppet master --help
puppet master [-D|--daemonize|--no-daemonize] [-d|--debug] [-h|--help]
[-l|--logdest syslog|<FILE>|console] [-v|--verbose] [-V|--version]
[--compile <NODE-NAME>]
* --daemonize: #-D发送到后台守护进程,默认选项
* --no-daemonize: #不发送到后台守护进程
* --debug: #完整调试
* --help: #输出帮助
* --logdest: #日志发送方式,默认是syslog
* --verbose: #显示详细信息
* --version: #打印puppet版本
* --compile: #以JSON的方式输出编译的catalog
使用--getconfig输出默认配置文件
root@10.1.1.33:puppet# puppet master --genconfig > puppet.conf
puppet不启用后台守护进程的方式运行.
root@10.1.1.33:puppet master --no-daemonize --verbose
2.puppet agent
puppet agent 在每个节点以守护进程方式运行,通常每30分钟向master请求一次,以确认新的信息并询问是否有变更.然后负责运行编译好的catalog代码
root@10.1.1.34:tmp# puppet agent --help
puppet agent [--certname <NAME>] [-D|--daemonize|--no-daemonize]
[-d|--debug] [--detailed-exitcodes] [--digest <DIGEST>] [--disable [MESSAGE]] [--enable]
[--fingerprint] [-h|--help] [-l|--logdest syslog|eventlog|<FILE>|console]
[--masterport <PORT>] [--no-client] [--noop] [-o|--onetime] [-t|--test]
[-v|--verbose] [-V|--version] [-w|--waitforcert <SECONDS>]
使用"--noop"参数,puppet运行catelog,但不执行配置root@10.1.1.34:tmp# puppet agent --noop
3.puppet apply
puppet apply 是puppet运行命令,主要在检测manifests时或在没有网络连接的情况下使用.不同于puppet agent,puppet apply在运行时不会连接master
root@10.1.1.34:tmp# puppet apply --help
puppet apply [-h|--help] [-V|--version] [-d|--debug] [-v|--verbose]
[-e|--execute] [--detailed-exitcodes] [-L|--loadclasses]
[-l|--logdest syslog|eventlog|<FILE>|console] [--noop]
[--catalog <catalog>] [--write-catalog-summary] <file>
(1) 将输出信息输出到日志文件
root@10.1.1.33:manifests# puppet apply -l /tmp/init.pp init.pp
root@10.1.1.33:manifests# cat /tmp/init.pp
Fri Dec 12 16:17:46 +0800 2014 Puppet (notice): Compiled catalog for puppet.domain.com in environment production in 0.04 seconds
Fri Dec 12 16:17:47 +0800 2014 Puppet (notice): Finished catalog run in 0.04 seconds
4.puppet cert
它用于管理本地证书,查看未签名证书,签署证书,废除证书,清除证书.
puppet cert <action> [-h|--help] [-V|--version] [-d|--debug] [-v|--verbose]
[--digest <digest>] [<host>]
常用操作:
clean #清除证书
fingerprint #打印证书指纹
generate #生成客户端证书
list #查看认证客户端列表
print #打印主机证书的全文信息
revoke #废除已认证的主机
sign #签署认证
verify #验证本地指定的认证命令参数:
--all #执行所有操作,包括'sign','clean', 'list', and 'fingerprint'
--digest #设置证书指纹加密的方式
--debug #启用完整调试模式|
--verbose #显示详细信息
--version #显示版本
(1)查看请求认证的客户端列表
root@10.1.1.33:nodes# puppet cert list
(2)为主机agent.domin.com签署验证
root@10.1.1.33:nodes# puppet cert sign agent.domain.com
(3)列出所有签名和未签名的证书
root@10.1.1.33:nodes# puppet cert list --all
+ "agent.domain.com" (SHA256) 3C:82:6A:E2:9B:8B:8F:8A:ED:C9:83:EB:64:47:6C:91:E5:8E:86:A6:B3:D7:1D:E5:4E:39:4D:04:5A:21:C5:86 #符号+表示已经签署过认证
"client.domain.com" (SHA256) E3:B4:46:90:DF:85:37:77:48:BB:F9:FD:9F:13:DE:52:2F:00:1C:71:A3:BC:C2:E2:A5:34:4F:01:DB:27:02:F5
(4)给所有未签署认证的请求颁发认证:
root@10.1.1.33:nodes# puppet cert sign --all
(5)查看所有已签署认证的客户端列表
root@10.1.1.33:nodes# puppet cert list --all
+ "agent.domain.com" (SHA256) 3C:82:6A:E2:9B:8B:8F:8A:ED:C9:83:EB:64:47:6C:91:E5:8E:86:A6:B3:D7:1D:E5:4E:39:4D:04:5A:21:C5:86
5.puppet kick
它用于连接到agent客户端主动运行puppet agent --test命令.类似主动触发配置