Puppet学习--基础安装和配置
0. 安装环境客户端IPpuppet_client.example.net(192.168.1.10)服务端IPpuppet_server.example.net(192.168.1.11)OS版本CentOS>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,执行如下命令:
# yum install puppet-server puppet –y #安装puppet服务端和客户端
# puppet resource package puppet-server ensure=latest#更新puppet服务端
# mv /etc/puppet/puppet.conf /etc/puppet/puppet.conf_bak #备份原配置文件
# vim /etc/puppet/puppet.conf# 重新写入文件,文件内容如下:
logdir = /var/log/puppet
rundir = /var/run/puppet
ssldir = $vardir/ssl
> localconfig = $vardir/localconfig
server = puppet_server.example.net
certname = puppetmaster_cert.example.net
certname = puppet_server.example.net
# chkconfig puppetmaster on#设置puppetmaster服务开启启动
# service puppetmaster start#启动puppetmaster
3. 安装客户端
登录puppet_client.example.net,执行如下命令:
# yum install puppet –y #安装puppet客户端
# puppet resource package puppet ensure=latest#更新puppet
# mv /etc/puppet/puppet.conf /etc/puppet/puppet.conf_bak #备份原配置文件
# vim /etc/puppet/puppet.conf# 重新写入文件,文件内容如下:
logdir = /var/log/puppet
rundir = /var/run/puppet
ssldir = $vardir/ssl
> localconfig = $vardir/localconfig
server = puppet_server.example.net
certname = puppetmaster_cert.example.net
# chkconfig puppet on#设置puppet服务开启启动/etc/puppet/puppet.conf
# service puppet start#启动puppet
4. 客户端与服务端进行认证
客户端通过调试模式启动节点向puppetmaster端发起认证:
# 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
服务端确定认证:
# puppet cert --list -all #查看所有证书,未认证的证书前面没有+号
# puppet cert --sign -all#对所有证书进行认证
或者只对指定的证书进行认证:
# puppet cert --sign “puppet_client.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文件,内容如下:
# vim /etc/puppet/manifests/site.pp
package{ 'lsof':
ensure => installed,
}
然后,在client端执行puppet agent -t命令:
# puppet agent -t
Info: Caching catalog for puppet_client.example.net
Info: Applying configuration version '1430127711'
Notice: /Stage/Main/Package/ensure: created
Notice: Finished catalog run in 6.90 seconds
输出已经表明lsof包已经安装成功。查看一下:
# rpm -q lsof
lsof-4.82-4.el6.x86_64
说明:puppet agent -t命令是在客户端手动运行agent程序。puppet客户端本身如果启动了puppet服务的话,puppet是可以自动间隔一段时间后去运行agent的,默认时间间隔为1800s。可以修改该时间间隔参数,修改客户端agent节点中的/etc/puppet/puppet.conf文件,修改下面的:runinterval = 100,单位为秒,然后重启puppet:service puppet restart。
页:
[1]