您的位置:首页 > 其它

Puppet学习--基础安装和配置

2015-04-27 17:48 453 查看

0. 安装环境

客户端IPpuppet_client.example.net(192.168.1.10)
服务端IPpuppet_server.example.net(192.168.1.11)
OS版本CentOS release 6.6 x86_64
puppet版本3.7.5

1.预安装配置

需要在服务端和客户端进行一些必要的预安装配置,因此本节下面的命令需要在客户端和服务端均要执行。
(1) yum install ruby #安装ruby

(2) 修改/etc/hosts,写入两行:
192.168.1.10 puppet_client.example.net
192.168.1.11 puppet_server.example.net
(3) rpm -ivh http://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm #安装puppet仓库

2. 安装服务端

登录puppet_server.example.net,执行如下命令:
[root@puppet_server.example.net ~]# yum install puppet-server puppet –y #安装puppet服务端和客户端
[root@puppet_server.example.net ~]# puppet resource package puppet-server ensure=latest #更新puppet服务端
[root@puppet_client.example.net ~]# mv /etc/puppet/puppet.conf /etc/puppet/puppet.conf_bak #备份原配置文件
[root@puppet_client.example.net ~]# vim /etc/puppet/puppet.conf # 重新写入文件,文件内容如下:
[main]
logdir = /var/log/puppet
rundir = /var/run/puppet
ssldir = $vardir/ssl
[agent]
classfile = $vardir/classes.txt
localconfig = $vardir/localconfig
server = puppet_server.example.net
certname = puppetmaster_cert.example.net
[master]
certname = puppet_server.example.net
[root@puppet_server.example.net ~]# chkconfig puppetmaster on #设置puppetmaster服务开启启动
[root@puppet_server.example.net ~]# service puppetmaster start #启动puppetmaster

3. 安装客户端

登录puppet_client.example.net,执行如下命令:
[root@puppet_client.example.net ~]# yum install puppet –y #安装puppet客户端
[root@puppet_client.example.net ~]# puppet resource package puppet ensure=latest #更新puppet
[root@puppet_client.example.net ~]# mv /etc/puppet/puppet.conf /etc/puppet/puppet.conf_bak #备份原配置文件
[root@puppet_client.example.net ~]# vim /etc/puppet/puppet.conf # 重新写入文件,文件内容如下:
[main]
logdir = /var/log/puppet
rundir = /var/run/puppet
ssldir = $vardir/ssl
[agent]
classfile = $vardir/classes.txt
localconfig = $vardir/localconfig
server = puppet_server.example.net
certname = puppetmaster_cert.example.net
[root@puppet_client.example.net ~]# chkconfig puppet on #设置puppet服务开启启动/etc/puppet/puppet.conf
[root@puppet_client.example.net ~]# service puppet start #启动puppet

4. 客户端与服务端进行认证

客户端通过调试模式启动节点向puppetmaster端发起认证:
[root@puppet_client.example.net ~]# puppet agent –t
Info: Caching certificate for puppet_client.example.net
Info: Caching certificate for puppet_client.example.net
Info: Caching catalog for puppet_client.example.net
Info: Applying configuration version '1430120791'
Notice: Finished catalog run in 0.02 seconds
服务端确定认证:
[root@puppet_server.example.net ~]# puppet cert --list -all #查看所有证书,未认证的证书前面没有+号
[root@puppet_server.example.net ~]# puppet cert --sign -all #对所有证书进行认证
或者只对指定的证书进行认证:
[root@puppet_server.example.net ~]# puppet cert --sign “puppet_client.example.net” #对指定的证书进行认证
[root@puppet_server.example.net ~]# puppet cert --list -all #再次查看所有证书,证书前面已经有+号,表示已经认证通过

5. 客户端进行操作的一个简单例子

现在举一个最简单的例子说明一下如何使用。
假如我们需要在客户端上安装lsof命令,常规情况下我们需要运行yum install lsof -y命令,这只是RHEL、CentOS系统上的命令,而在Debian、Ubuntu等系统上则是用apt-get命令。如果需要安装lsof命令的系统比较多的话,就需要编写脚本判断系统版本进行安装了。但是在puppet中,可以通过以下方式简单的实现上述需求。
首先,在puppet服务端创建一个/etc/puppet/manifests/site.pp文件,内容如下:
[root@puppet_server.example.net ~]# vim /etc/puppet/manifests/site.pp
package{ 'lsof':
ensure => installed,
}
然后,在client端执行puppet agent -t命令:
[root@puppet_client.example.net ~]# puppet agent -t
Info: Caching catalog for puppet_client.example.net
Info: Applying configuration version '1430127711'
Notice: /Stage[main]/Main/Package[lsof]/ensure: created
Notice: Finished catalog run in 6.90 seconds
输出已经表明lsof包已经安装成功。查看一下:
[root@puppet_client.example.net ~]# rpm -q lsof
lsof-4.82-4.el6.x86_64
说明:puppet agent -t命令是在客户端手动运行agent程序。puppet客户端本身如果启动了puppet服务的话,puppet是可以自动间隔一段时间后去运行agent的,默认时间间隔为1800s。可以修改该时间间隔参数,修改客户端agent节点中的/etc/puppet/puppet.conf文件,修改[agent]下面的:runinterval = 100,单位为秒,然后重启puppet:service puppet restart。
本文出自 “烟花易冷” 博客,转载请与作者联系!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: