废话不多说了,下面记录下Puppet在Centos下的部署过程:
puppet是什么
puppet是一种基于ruby语言开发的Lnux、Unix、windows平台的集中配置管理系统。它使用自有的puppet描述语言,可管理配置文件file、用户user、cron任务、软件包、系统服务等系统实体。
puppet把这些系统实体称之为资源,puppet设计目标是简化对这些资源的管理以及妥善处理资源间的依赖关系。
puppet依赖于C/S(客户端/服务器)的部署架构。它需要在puppet服务器上安装puppet-server软件包(以下简称master),在需要管理的目标主机上安装puppet客户端软件(以下简称agent)。
当agent连接上master后,定义在master端的配置文件会被编译,然后在agent上运行。每个agent默认30分钟会连接一次master,确认配置信息的更新情况。但是这种方式在很多场景下不是很符合系统管理员的要求,所以很多系统管理员也会将agent通过crontab(任务计划)来管理,这样会更加灵活一些。
puppet优点
puppet的语法允许你创建一个单独的脚本,用来在你所有的目标主机上建立一个用户。所有的目标主机会依次使用适合本地系统的语法来解释和执行这个模块。如果这个配置是在Red Hat服务器上执行的话,建立用户使用useradd命令,如果这个配置是在FreddBSD服务器上执行的话,则使用adduser命令。
puppet另外一个卓越的地方就是它的灵活性。源于开源软件的天性,你可以自由地获得puppet的源代码。如果你遇到问题并且有能力处理的话,你可以修改或加强puppet的代码使其适用于你的环境,然后解决这个问题。
puppet也是易于扩展的。定制软件包的支持功能和特殊的系统环境配置能够快速简单地添加至puppet的安装程序中。
1)基本安装
机器信息(centos6.8) IP地址 主机名 角色 182.48.115.233 Master-node Master 182.38.115.235 Agent-node1 Agent 182.38.115.235 Agent-node2 Agent 182.38.115.235 Agent-node3 Agent 准备工作(在Master和Agent上都要准备的) 1)关闭selinux 2)关闭iptables,这是为了避免各种麻烦,你可以通过打开端口,而不需要关闭iptables 3)设置host文件,由于puppet需要用FQDN,一般实验环境都是没有dns,所以通过hosts文件设置 4)设置ntp,同步时间,这个也是必须的。 5)设置源,根据你希望使用的版本,设置不同的源.我是启用了EPEL和Puppet官方的源 0)关闭selinux和防火墙(Master和Agent都要做) [root@Master-node ~]# setenforce 0 [root@Master-node ~]# /etc/init.d/iptables stop 1)绑定hosts(Master和Agent都要做) [root@Master-node ~]# cat /etc/hosts ...... 182.48.115.233 Master-node 182.48.115.235 Agent-node1 182.48.115.236 Agent-node2 182.48.115.237 Agent-node3 [root@Agent-node1 ~]# cat /etc/hosts 182.48.115.235 Agent-node1 182.48.115.233 Master-node [root@Agent-node2 ~]# cat /etc/hosts 182.48.115.235 Agent-node2 182.48.115.233 Master-node [root@Agent-node3 ~]# cat /etc/hosts 182.48.115.235 Agent-node3 182.48.115.233 Master-node 2)同步时间(Master和Agent端都要做) [root@Master-node ~]# yum -y install ntp [root@Master-node ~]# ntpdate ntp.api.bz 3)安装Puppet Puppet 不在CentOS的基本源中,需要加入PuppetLabs 提供的官方源(Master和Agent都要操作) [root@Master-node ~]# wget http://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-1.noarch.rpm [root@Master-node ~]# yum install puppetlabs-release-6-1.noarch.rpm [root@Master-node ~]# yum update -----------Master端----------- [root@Master-node ~]# yum install -y ruby facter puppet-server 启动 [root@Master-node ~]# service puppet start [root@Master-node ~]# service puppetmaster start 设为自动开机 [root@Master-node ~]# chkconfig puppet on [root@Master-node ~]# chkconfig puppetmaster on ----------Agent端----------- [root@Agent-node1 ~]# yum install -y ruby facter puppet 启动 [root@Agent-node1 ~]# service puppet start 设置开机自启动 [root@Agent-node1 ~]# chkconfig puppet on 配置puppet [root@Agent-node1 ~]# vim /etc/puppet/puppet.conf //底部添加下面一行 ..... server = Master-node [root@Agent-node1 ~]# /etc/init.d/puppet restart
从日志中我们可以看出第一次启动master端时,puppet服务会在本地创建认证中心,给自己授权证书和key,这个我们可以在/var/lib/puppet/ssl看到那些证书和key。如下:
[root@Master-node ~]# tail -f /var/log/messages ...... Jul 25 15:02:13 puppet01 puppet-master[23689]: Signed certificate request for ca Jul 25 15:02:14 puppet01 puppet-master[23689]: Master-node has a waiting certificate request Jul 25 15:02:14 puppet01 puppet-master[23689]: Signed certificate request for Master-node Jul 25 15:02:14 puppet01 puppet-master[23689]: Removing file Puppet::SSL::CertificateRequest Master-node at '/var/lib/puppet/ssl/ca/requests/Master-node.pem' Jul 25 15:02:14 puppet01 puppet-master[23689]: Removing file Puppet::SSL::CertificateRequest Master-node at '/var/lib/puppet/ssl/certificate_requests/Master-node.pem' Jul 25 15:02:14 puppet01 puppet-master[23727]: Reopening log files Jul 25 15:02:14 puppet01 puppet-master[23727]: Starting Puppet master version 3.8.7 Jul 25 15:03:00 puppet01 puppet-master[23727]: puppet02.bkjk.cn has a waiting certificate request [root@Master-node ~]# ll /var/lib/puppet/ssl total 28 drwxr-xr-x 5 puppet puppet 4096 Jul 25 15:02 ca drwxr-xr-x 2 puppet puppet 4096 Jul 25 15:02 certificate_requests drwxr-xr-x 2 puppet puppet 4096 Jul 25 15:02 certs -rw-r--r-- 1 puppet puppet 967 Jul 25 15:02 crl.pem drwxr-x--- 2 puppet puppet 4096 Jul 25 15:02 private drwxr-x--- 2 puppet puppet 4096 Jul 25 15:02 private_keys drwxr-xr-x 2 puppet puppet 4096 Jul 25 15:02 public_keys 这个目录和/etc/puppet/puppet.conf文件中配置的ssldir路径有关系 也可以查看master端给自己授权的证书文件 [root@Master-node ~]# ll /var/lib/puppet/ssl/ca/signed total 4 -rw-r--r-- 1 puppet puppet 2029 Jul 25 15:02 Master-node.pem
2)建立master和agent之间的认证关系(三种注册方式)
Agent需要向服务器端发出请求, 让服务器对客户端进行管理. 这其实是一个证书签发的过程. 第一次运行puppet客户端的时候会生成一个SSL证书并指定发给Puppet服务端, 服务器端如果同意管理客户端,就会对这个证书进行签发。 Agent在第一次连接master的时候会向master申请证书,如果没有master没有签发证书,那么puppet agent和master的连接是否建立成功的,agent会持续等待master签发证书, 并会每隔2分钟去检查master是否签发证书。 Puppet注册方式基本上有三种:自动注册、手动注册和预签名注册。 -------------------------------------------------------------------------------------------------------------------------------------- 一、手动注册(批量效率高) 手动注册是由Agent端先发起证书申请请求,然后由Puppetserver端确认认证方可注册成功,这种注册方式安全系数中等,逐一注册(puppet cert --sign certnmame) 在节点数量较大的情况下是比较麻烦的,效率也低,批量注册(puppet cert --sign --all)效率很高,一次性便可注册所有的Agent的请求,但是这种方式安全系数较低, 因为错误的请求也会被注册上。 1)需要先在Agent节点申请注册(三台Agent节点机都要操作) 由于已经Agent的puppet.conf文件里设置了server地址,因此下面向Master请求认证的命令中不需要跟服务端地址。 否则需要在下面的命令中添加Master服务端地址,即添加"--server Master-node" [root@Agent-node1 ~]# puppet agent --test Info: Creating a new SSL key for agent-node1 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-node1 Info: Certificate Request fingerprint (SHA256): E0:B4:04:52:46:C0:D4:38:92:7B:EA:90:3A:5E:EF:D8:6E:85:D3:61:77:6A:34:10:24:0F:15:B6:1A:9C:13:EC Info: Caching certificate for ca Exiting; no certificate found and waitforcert is disabled 2)Master服务器端确定认证 现在Master服务器端查看认证情况 [root@Master-node ~]# puppet cert --list "agent-node1" (SHA256) E0:B4:04:52:46:C0:D4:38:92:7B:EA:90:3A:5E:EF:D8:6E:85:D3:61:77:6A:34:10:24:0F:15:B6:1A:9C:13:EC "agent-node2" (SHA256) FD:FC:10:22:48:BD:17:3C:6E:3E:C5:A1:32:6A:CD:E8:E7:47:33:F9:F2:34:45:C9:59:57:B1:0D:13:10:FE:37 "agent-node3" (SHA256) 55:C0:CA:EF:F1:1A:3F:E2:53:0D:A8:F6:32:EB:8C:D8:B2:C8:51:9F:0A:4B:4C:0A:78:C5:57:E6:49:02:FC:90 [root@Master-node ~]# puppet cert --list --all //加--all参数,就能查看到puppet给自己签发的本地证书了 "agent-node1" (SHA256) E0:B4:04:52:46:C0:D4:38:92:7B:EA:90:3A:5E:EF:D8:6E:85:D3:61:77:6A:34:10:24:0F:15:B6:1A:9C:13:EC "agent-node2" (SHA256) FD:FC:10:22:48:BD:17:3C:6E:3E:C5:A1:32:6A:CD:E8:E7:47:33:F9:F2:34:45:C9:59:57:B1:0D:13:10:FE:37 "agent-node3" (SHA256) 55:C0:CA:EF:F1:1A:3F:E2:53:0D:A8:F6:32:EB:8C:D8:B2:C8:51:9F:0A:4B:4C:0A:78:C5:57:E6:49:02:FC:90 + "master-node" (SHA256) DB:81:FB:58:D7:FF:DC:17:3C:C2:4D:7B:2E:DF:35:C2:F5:4D:B8:D2:AE:9D:EF:E0:73:44:11:07:C4:C2:72:23 以上结果中: 左边有+号的,表示已经签发,puppet首先会给自己签发一个本地证书;客户端的证书前没+号,这就等待服务端签发。 接着Master服务端签发证书,及注册Agent节点 [root@Master-node ~]# puppet cert --list agent-node1 [root@Master-node ~]# puppet cert --list agent-node2 [root@Master-node ~]# puppet cert --list agent-node3 [root@Master-node ~]# puppet cert --sign --all //上面三个命令是分别给单独的一个Agent颁发证书,效率低下!可以使用这个命令代替,表示签发所有Agent的证书 再次查看认证情况,发现已经都认证了(左边都有+号了) [root@Master-node ~]# puppet cert --list --all + "agent-node1" (SHA256) 86:61:2A:99:38:54:E3:FD:E0:8F:40:D4:2D:75:83:6F:64:B6:36:E1:B0:97:0D:B5:82:9C:69:95:D2:95:98:92 + "agent-node2" (SHA256) 63:BF:AA:C2:C5:1E:A6:64:47:72:85:B3:4B:32:3E:07:C3:70:8D:86:D3:86:53:1A:FF:F9:9E:93:46:46:CB:13 + "agent-node3" (SHA256) 41:B1:A7:3C:E3:7D:47:32:21:4F:25:8A:5E:96:77:1A:E0:FE:45:C3:42:0C:BC:D7:0A:0A:D1:E9:BF:FA:E1:96 + "master-node" (SHA256) DB:81:FB:58:D7:FF:DC:17:3C:C2:4D:7B:2E:DF:35:C2:F5:4D:B8:D2:AE:9D:EF:E0:73:44:11:07:C4:C2:72:23 另一种查看认证的方法: [root@Master-node ~]# tree /var/lib/puppet/ssl/ //可以使用"yum install -y tree" 安装tree命令 /var/lib/puppet/ssl/ ├── ca │ ├── ca_crl.pem │ ├── ca_crt.pem │ ├── ca_key.pem │ ├── ca_pub.pem │ ├── inventory.txt │ ├── private │ │ └── ca.pass │ ├── requests │ ├── serial │ └── signed │ ├── agent-node1.pem │ ├── agent-node2.pem │ ├── agent-node3.pem │ └── master-node.pem ├── certificate_requests ├── certs │ ├── ca.pem │ └── master-node.pem ├── crl.pem ├── private ├── private_keys │ └── master-node.pem └── public_keys └── master-node.pem 最后在Agent端进行motd模块测试(即客户端取回通过的证书) [root@Agent-node1 ~]# puppet agent --test //--test也可以替换为-t Info: Caching certificate for agent-node1 Info: Caching certificate_revocation_list for ca Info: Caching certificate for agent-node1 Warning: Unable to fetch my node definition, but the agent run will continue: Warning: undefined method `include?' for nil:NilClass Info: Retrieving pluginfacts Info: Retrieving plugin Info: Caching catalog for agent-node1 Info: Applying configuration version '1495876267' Info: Creating state file /var/lib/puppet/state/state.yaml Notice: Finished catalog run in 0.06 seconds ------------------------------------------------------------------------------- 也可以直接使用命令"puppet agent --no-daemonize --onetime --verbose --debug",打印证书申请过程中的详细信息 --no-daemonize 前台输出日志 --verbose 输入更加详细的日志 --debug 更加详细的日志,排错的时候使用 --test 表示测试,就带一个–test参数就可以 ------------------------------------------------------------------------------- -------------------------------证书管理------------------------------ 当出现问题需要重新申请证书或重新安装puppet时使用,需要注销证书和删除证书 注销证书既是要证书过期(--revoke) [root@Master-node ~]# puppet cert --revoke agent-node1 Notice: Revoked certificate with serial 10 [root@Master-node ~]# puppet cert --list --all //如下,过期的证书签名是"-"号 + "agent-node2" (SHA256) 63:BF:AA:C2:C5:1E:A6:64:47:72:85:B3:4B:32:3E:07:C3:70:8D:86:D3:86:53:1A:FF:F9:9E:93:46:46:CB:13 + "agent-node3" (SHA256) 41:B1:A7:3C:E3:7D:47:32:21:4F:25:8A:5E:96:77:1A:E0:FE:45:C3:42:0C:BC:D7:0A:0A:D1:E9:BF:FA:E1:96 + "master-node" (SHA256) DB:81:FB:58:D7:FF:DC:17:3C:C2:4D:7B:2E:DF:35:C2:F5:4D:B8:D2:AE:9D:EF:E0:73:44:11:07:C4:C2:72:23 - "agent-node1" (SHA256) 86:61:2A:99:38:54:E3:FD:E0:8F:40:D4:2D:75:83:6F:64:B6:36:E1:B0:97:0D:B5:82:9C:69:95:D2:95:98:92 (certificate revoked) [root@Master-node ~]# puppet cert --revoke --all //注销所有证书 上面只是让证书失效,客户端连接会失败,并没有删除证书文件。 删除证书(--clean) [root@Master-node ~]# puppet cert --clean agent-node1 //删除agent-node1证书 [root@Master-node ~]# puppet cert --clean --all //删除所有证书 证书签名的过期或删除需要重启puppetmaster服务后才能生效。 [root@Master-node ~]# /etc/init.d/puppetmaster restart Stopping puppetmaster: [ OK ] Starting puppetmaster: [ OK ] 重启后,puppet会给自己自动签发一个本地证书 [root@Master-node ~]# puppet cert --list --all + "master-node" (SHA256) 25:13:02:B7:01:44:08:E9:A0:C6:66:4F:A9:A9:93:2E:7E:E6:ED:E9:91:85:7B:65:E3:ED:26:FB:C6:7C:B6:56 注意删除证书到重新请求证书的流程: 在Master端删除证书(puppet cert --clean agent-node1) 在Agent端删除注册过的证书文件:rm -rf /var/lib/puppet/ssl/* 在Agent端重新请求证书(puppet agent ----test ) ----------------------------------------------------------------------------------------------------------------------------------------------- 二、自动注册(安全系数低,效率高) 这种注册方式简单来讲是通过Puppetmaster端的ACL列表进行控制的,安全系统较低,也就是说符合预先定义的ACL列表中的所有节点请求不需要确认都会被自动注册上, 也就是说你只需要知道ACL列表要求,其次能和PuppetMaster端通信便可轻易注册成功。当然,它的最大优点就是效率非常高。 1)清除Master端已经注册的agent的证书 [root@Master-node ~]# puppet cert --clean agent-node1 //可以一个个的针对单个agent节点进行清除 [root@Master-node ~]# puppet cert --clean --all //也可以清除所有agent节点的证书 2)在agent端删除注册的所有信息,包括证书。这个很重要!!当在PupperMaster端删除agent的证书后,一定要登录对应的agent节点上执行下面的操作:删除注册过的证书, 否则再次注册就会报错失败! [root@Agent-node1 ~]# rm -rf /var/lib/puppet/ssl/* 3)在master端编写ACL列表 设置master自动签发所有的证书 [root@Master-node ~]# vim /etc/puppet/puppet.conf //在文件底部添加下面内容 [main] autosign = true autosign = /etc/puppet/autosign.conf [root@Master-node ~]# vim /etc/puppet/autosign.conf //设置下面内容,*表示允许所有域下的主机注册本Master端的证书 * [root@Master-node ~]# /etc/init.d/puppet restart [root@Master-node ~]# service puppetmaster restart [root@Master-node ~]# puppet cert --list --all + "master-node" (SHA256) 47:D4:F5:FE:73:62:0B:51:BD:E6:BD:A5:1C:7E:04:75:72:80:5C:32:9C:E2:01:46:39:EA:3B:D9:F6:FC:A7:CE 接着在所有的Agent节点申请证书 [root@Agent-node1 ~]# puppet agent --test Info: Creating a new SSL key for agent-node1 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-node1 Info: Certificate Request fingerprint (SHA256): 79:F5:6B:9B:0C:38:68:B7:A6:C3:9E:E4:7E:19:76:8B:61:35:CA:D0:66:E4:81:B4:15:09:DB:24:ED:3F:E2:3F Info: Caching certificate for agent-node1 Info: Caching certificate_revocation_list for ca Info: Caching certificate for ca Info: Retrieving pluginfacts Info: Retrieving plugin Info: Caching catalog for agent-node1 Info: Applying configuration version '1495879417' Notice: Finished catalog run in 0.05 seconds 然后在Master端查看证书是否已经自动注册上了。如下,发现已经自动注册了 [root@Master-node ~]# puppet cert --list --all + "agent-node1" (SHA256) EE:EE:FE:C8:41:8D:C4:42:59:59:84:FB:A3:CA:F7:20:8A:94:F5:70:5A:2F:1E:A3:D3:48:B4:70:2F:2C:76:AA + "agent-node2" (SHA256) 00:C7:14:7D:1B:2F:D9:5D:B9:F5:A1:24:89:FE:65:C2:CF:C7:76:58:CC:61:4F:07:4D:89:22:B2:9B:33:EF:C5 + "agent-node3" (SHA256) 7C:24:5D:9A:BD:C6:A4:33:04:21:9E:9D:BA:F2:5F:1B:01:84:E1:C4:6C:95:2F:12:A9:7C:BE:3E:E8:48:BD:38 + "master-node" (SHA256) 99:8A:53:84:A4:BA:38:39:72:77:E5:11:47:1B:C2:29:BE:67:07:03:5D:08:8C:A3:85:49:3F:EF:B4:9A:C4:C3 最后在Agent节点测试 [root@Agent-node1 ~]# puppet agent --test Info: Retrieving pluginfacts Info: Retrieving plugin Info: Caching catalog for agent-node1 Info: Applying configuration version '1495879417' Notice: Finished catalog run in 0.07 seconds ----------------------------------------------------------------------------------------------------------------------------------------------- 三、预签名注册(推荐生产环境中使用此方式进行注册,既安全又可靠!) 预签名注册是在agent端未提出申请的情况下,预先在puppet master端生成agent端的证书,然后把证书复制到agent节点对应的目录下即可注册成功,这样可以避 免自动签名的危险。这种方式安全系数最高,但是操作麻烦,需要提前预知所有节点服务器的certname名称,其次需要将生成的证书逐步copy到所有节点上去。 不过,如果你的系统中安装了kickstart或者cobbler这样的自动化工具,倒是可以将证书部分转换成脚本集成到统一自动化部署中 1)清除Master端已经注册的agent的证书 [root@Master-node ~]# puppet cert --clean --all //清除所有注册过的证书,也可以指定某个Agent节点的证书清除 [root@Master-node ~]# puppet cert --list --all //查看证书是否已清除 [root@Master-node ~]# /etc/init.d/puppetmaster restart 2)在agent端删除注册的所有信息,包括证书。 [root@Agent-node1 ~]# rm -rf /var/lib/puppet/* 3)在Master端删除自动注册ACL列表 [root@Master-node ~]# mv /etc/puppet/autosign.conf /etc/puppet/autosign.conf.bak 4)在Master端预先生成Agent证书(这个只能针对agent端的节点一个个的生成证书了) [root@Master-node ~]# puppet cert generate agent-node1 //老版本使用命令"puppetca --generate agent-node1" [root@Master-node ~]# puppet cert generate agent-node2 [root@Master-node ~]# puppet cert generate agent-node3 查看证书 [root@Master-node ~]# puppet cert --list --all + "agent-node1" (SHA256) E0:57:E4:D4:2A:10:46:68:E7:58:DE:3C:6A:2C:9F:82:7B:5F:BC:6E:F9:84:E7:A2:F3:E3:9D:02:5E:CB:EC:80 + "agent-node2" (SHA256) F8:6F:55:37:8C:4D:D0:33:A5:EA:5E:2D:1A:EA:3E:52:27:9F:0A:65:E2:81:56:2E:7A:EF:67:8A:F6:37:8D:50 + "agent-node3" (SHA256) 50:9E:80:75:D8:13:2D:A4:CB:04:6C:2E:70:11:90:53:97:37:07:0D:F0:AB:66:40:60:87:4C:51:74:1A:00:ED + "master-node" (SHA256) 2A:EB:D3:60:C4:F6:57:12:9B:2E:7E:E8:3A:B8:11:B6:A4:57:F4:F9:91:7D:E7:E9:25:64:DD:51:C8:26:8E:75 6)然后把Master端预先生成的证书copy到agent端的各个节点上 [root@Agent-node1 ~]# mkdir -p /var/lib/puppet/ssl/private_keys [root@Agent-node1 ~]# mkdir -p /var/lib/puppet/ssl/certs [root@Agent-node1 ~]# rsync -e "ssh -p22" -avpgolr 182.48.115.233:/var/lib/puppet/ssl/private_keys/agent-node1.pem /var/lib/puppet/ssl/private_keys/ [root@Agent-node1 ~]# rsync -e "ssh -p22" -avpgolr 182.48.115.233:/var/lib/puppet/ssl/certs/agent-node1.pem /var/lib/puppet/ssl/certs/ [root@Agent-node1 ~]# rsync -e "ssh -p22" -avpgolr 182.48.115.233:/var/lib/puppet/ssl/certs/ca.pem /var/lib/puppet/ssl/certs/ [root@Agent-node2 ~]# mkdir -p /var/lib/puppet/ssl/private_keys [root@Agent-node2 ~]# mkdir -p /var/lib/puppet/ssl/certs [root@Agent-node2 ~]# rsync -e "ssh -p22" -avpgolr 182.48.115.233:/var/lib/puppet/ssl/private_keys/agent-node2.pem /var/lib/puppet/ssl/private_keys/ [root@Agent-node2 ~]# rsync -e "ssh -p22" -avpgolr 182.48.115.233:/var/lib/puppet/ssl/certs/agent-node2.pem /var/lib/puppet/ssl/certs/ [root@Agent-node2 ~]# rsync -e "ssh -p22" -avpgolr 182.48.115.233:/var/lib/puppet/ssl/certs/ca.pem /var/lib/puppet/ssl/certs/ [root@Agent-node3 ~]# mkdir -p /var/lib/puppet/ssl/private_keys [root@Agent-node3 ~]# mkdir -p /var/lib/puppet/ssl/certs [root@Agent-node3 ~]# rsync -e "ssh -p22" -avpgolr 182.48.115.233:/var/lib/puppet/ssl/private_keys/agent-node3.pem /var/lib/puppet/ssl/private_keys/ [root@Agent-node3 ~]# rsync -e "ssh -p22" -avpgolr 182.48.115.233:/var/lib/puppet/ssl/certs/agent-node3.pem /var/lib/puppet/ssl/certs/ [root@Agent-node3 ~]# rsync -e "ssh -p22" -avpgolr 182.48.115.233:/var/lib/puppet/ssl/certs/ca.pem /var/lib/puppet/ssl/certs/ 最后在各个Agent节点测试 [root@Agent-node1 ~]# puppet agent -t Info: Caching certificate_revocation_list for ca Info: Retrieving pluginfacts Info: Retrieving plugin Info: Caching catalog for agent-node1 Info: Applying configuration version '1495896021' Info: Creating state file /var/lib/puppet/state/state.yaml Notice: Finished catalog run in 0.07 seconds 在Master端查看证书情况 [root@Master-node ~]# tree /var/lib/puppet/ssl/ /var/lib/puppet/ssl/ ├── ca │ ├── ca_crl.pem │ ├── ca_crt.pem │ ├── ca_key.pem │ ├── ca_pub.pem │ ├── inventory.txt │ ├── private │ │ └── ca.pass │ ├── requests │ ├── serial │ └── signed │ ├── agent-node1.pem │ ├── agent-node2.pem │ ├── agent-node3.pem │ └── master-node.pem ├── certificate_requests ├── certs │ ├── agent-node1.pem │ ├── agent-node2.pem │ ├── agent-node3.pem │ ├── ca.pem │ └── master-node.pem ├── crl.pem ├── private ├── private_keys │ ├── agent-node1.pem │ ├── agent-node2.pem │ ├── agent-node3.pem │ └── master-node.pem └── public_keys ├── agent-node1.pem ├── agent-node2.pem ├── agent-node3.pem └── master-node.pem
3)Puppet的Dashboard搭建
puppet dashboard是GUI(图形用户界面)方式管理puppet,可以分析puppet运行日志。 1)安装mysql [root@Master-node ~]# yum install -y mysql mysql-devel mysql-server [root@Master-node ~]# vim /etc/my.cnf //在[mysqld]字段,增加下面一行内容 [mysqld] ...... max_allowed_packet = 32M 启动服务 [root@Master-node ~]# /etc/init.d/mysqld start [root@Master-node ~]# chkconfig mysqld on 设置mysql密码为"password" [root@Master-node ~]# mysqladmin -u root password 'password' 创建一个dashboard数据库 [root@Master-node ~]# mysql -ppassword mysql> CREATE DATABASE dashboard CHARACTER SET utf8; mysql> CREATE USER 'dashboard'@'localhost' IDENTIFIED BY 'password'; mysql> GRANT ALL PRIVILEGES ON dashboard.* TO 'dashboard'@'localhost'; mysql> FLUSH PRIVILEGES; 2)安装Passenger+Apache+Dashboard 使用Apache+Passenger部署高性能PuppetMaster,代替原来的WEBrick,提高并发性能 让Apache支持ruby。通过ruby gem方式安装passenger [root@Master-node ~]# gem install passenger 若是升级ruby,参考源码安装升级:http://www.cnblogs.com/kevingrace/p/5752382.html 3)配置Dashboard [root@Master-node ~]# vim /usr/share/puppet-dashboard/config/database.yml ........ production: database: dashboard username: dashboard password: password encoding: utf8 adapter: mysql 修改时区 [root@Master-node ~]# vim /usr/share/puppet-dashboard/config/environment.rb ....... config.time_zone = 'Beijing' 4)初始化数据库 [root@Master-node ~]# cd /usr/share/puppet-dashboard/ [root@Master-node puppet-dashboard]# rake RAILS_ENV=production db:migrate //rake是ruby下自带的命令,可以使用find命令找出 5)配置Apache 配置passenger(选择http服务软件): [root@Master-node ~]# passenger-install-apache2-module [root@Master-node ~]# find / -name mod_passenger.so /usr/local/ruby/lib/ruby/gems/2.4.0/gems/passenger-5.1.4/buildout/apache2/mod_passenger.so [root@Master-node ~]# cp /usr/local/ruby/lib/ruby/gems/2.4.0/gems/passenger-5.1.4/buildout/apache2/mod_passenger.so /etc/httpd/modules/ 整合Passenger和apache [root@Master-node ~]# yum install curl-devel httpd-devel [root@Master-node ~]# vim /etc/httpd/conf.d/passenger.conf LoadModule passenger_module modules/mod_passenger.so <IfModule mod_passenger.c> PassengerRoot /usr/share/rubygems/gems/passenger-3.0.17 PassengerRuby /usr/bin/ruby PassengerHighPerformance on PassengerMaxPoolSize 12 PassengerPoolIdleTime 1500 PassengerStatThrottleRate 120 RailsAutoDetect On </IfModule> <VirtualHost *:80> ServerName huanqiu.puppet.com DocumentRoot "/usr/share/puppet-dashboard/public/" <Directory "/usr/share/puppet-dashboard/public/"> Options None AllowOverride AuthConfig Order allow,deny allow from all </Directory> ErrorLog /var/log/httpd/huanqiu.puppet.com_error.log LogLevel warn CustomLog /var/log/httpd/huanqiu.puppet.com_access.log combined ServerSignature On </VirtualHost> 启动服务 [root@Master-node ~]# /etc/init.d/httpd start [root@Master-node ~]# chkconfig httpd on 6)配置puppet 让Dashboard使用Reports,现在默认agent是已经启用Report的功能,所以就不需要设置agent,只需要设置Server端就可以! [root@Master-node ~]# vim /etc/puppet/puppet.conf ....... [master] reports = store, http reporturl = http://huanqiu.puppet.com:80/reports/upload 重启puppetmaster 服务 [root@Master-node ~]# /etc/init.d/puppetmaster restart 这时候可以直接用 http://ip 访问puppet Dashboard