您的位置:首页 > 运维架构 > Linux

在CentOS 6.5上安装Puppet配置管理工具

2014-07-31 10:19 661 查看
http://os.51cto.com/art/201210/361880.htm
以下安装采用两台服务器,一台是 master.vpsee.com 用来安装 puppet-server 服务;一台是 client.vpsee.com 用来安装 puppet 客户端。Puppet 要求所有机器有完整的域名(FQDN),如果没有 DNS 服务器提供域名的话,可以在两台机器上设置主机名(注意要先设置主机名再安装 Puppet,因为安装 Puppet 时会把主机名写入证书,客户端和服务端通信需要这个证书):
# vi /etc/hosts  192.168.2.10    master master.vpsee.com  192.168.2.11    client client.vpsee.com
Puppet 要求所有机器上的时钟保持同步,所以需要安装和启用 ntp 服务(如果采用 CentOS-6.2-x86_64-minimal.iso 最小化安装,需要额外安装这个软件包)。
# yum install ntp   # chkconfig ntpd on   # ntpdate pool.ntp.org  29 Feb 15:22:47 ntpdate[15867]: step time server 196.25.1.1 offset 98.750417 sec   # service ntpd start  Starting ntpd:                                           [  OK  ]
安装 puppet 服务Puppet 需要 Ruby 的支持,如果要查看命令行帮助的话需要额外 ruby-rdoc 这个软件包:
# yum install ruby ruby-lib ruby-rdoc
Puppet 不在 CentOS 的基本源中,需要加入 PuppetLabs 提供的官方源:
# yum -y install wget   # wget http://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-1.noarch.rpm   # yum install puppetlabs-release-6-1.noarch.rpm   # yum update
在 master 上安装和启用 puppet 服务:
# yum install puppet-server   # chkconfig puppet on   # service puppetmaster start  Starting puppetmaster:                                    [  OK  ]
关闭 iptables:
# /etc/init.d/iptables stop  iptables: Flushing firewall rules:                         [  OK  ]  iptables: Setting chains to policy ACCEPT: filter          [  OK  ]  iptables: Unloading modules:                               [  OK  ]
安装 puppet 客户端在 client 上安装 puppet 客户端:
# yum install puppet
Puppet 客户端使用 HTTPS 和服务端(master)通信,为了和服务器端通信必须有合法的 SSL 认证,第一次运行 puppet 客户端的时候会生成一个 SSL 证书并指定发给 Puppet 服务端。
# puppet agent --no-daemonize --onetime --verbose --debug --server=master.vpsee.com
Puppet 服务端接受到客户端的证书后必须签字(sign)才能允许客户端接入,sign 后用 puppet cert list –all 查看会发现 client.vpsee.com 前面多了一个 + 后,表示 “加入” 成功:
# puppet cert list --all    client.vpsee.com (65:3C:20:82:AE:F6:23:A8:0A:0B:09:EF:05:64:1D:BB)  + master.vpsee.com   (AF:A0:32:78:D4:EB:D3:EE:02:1C:62:1C:83:3C:46:EC) (alt names: DNS:master, DNS:master.vpsee.com)   # puppet cert --sign client.vpsee.com  notice: Signed certificate request for client.vpsee.com  notice: Removing file Puppet::SSL::CertificateRequest client.vpsee.com at '/var/lib/puppet/ssl/ca/requests/client.vpsee.com.pem'   # puppet cert list --all  + client.vpsee.com (65:3C:20:82:AE:F6:23:A8:0A:0B:09:EF:05:64:1D:BB)  + master.vpsee.com   (AF:A0:32:78:D4:EB:D3:EE:02:1C:62:1C:83:3C:46:EC) (alt names: DNS:mas
这样,客户端和服务端就配置好了,双方可以通信了。Hello, world现在可以在服务端写个小例子来测试一下。这个例子作用很简单,用来在客户端的 /tmp 目录下新建一个 helloworld.txt 文件,内容为 hello, world. 在服务端编写代码:
# vi /etc/puppet/manifests/site.pp  node default {          file {                  "/tmp/helloworld.txt": content => "hello, world";          }  }
在客户端上执行 puppet,运行成功后会在 /tmp 看到新生成的 helloworld.txt:
$ puppet agent --test --server=master.vpsee.com  warning: peer certificate won't be verified in this SSL session  info: Caching certificate for client.vpsee.com  info: Caching certificate_revocation_list for ca  info: Caching catalog for client.vpsee.com  info: Applying configuration version '1330668451'  notice: /Stage[main]//Node[default]/File[/tmp/helloworld.txt]/ensure: defined content as '{md5}e4d7f1b4ed2e42d15898f4b27b019da4'  info: Creating state file /home/vpsee/.puppet/var/state/state.yaml  notice: Finished catalog run in 0.03 seconds   $ cat /tmp/helloworld.txt   hello, world
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: