0.环境介绍

系统版本: centos 6.6
IP与主机名:
master01.cheney.com  =>  192.168.1.100
agent01.cheney.com   =>  192.168.1.101

1.agent安装

#安装puppet官方源
rpm -ivh https://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm
#导入GPG秘钥
rpm --import https://yum.puppetlabs.com/RPM-GPG-KEY-puppetlabs

#安装agent
yum install ruby ruby-libs ruby-shadow puppet

2.配置hosts文件

ps:在上一篇我们安装了dnsmasq,如果你是跟着做的话可以直接在"/etc/resolv.conf"文件里吧dns指向dnsmasq服务器的IP,然后在dnsmasq服务器的hosts文件上添加

master01.cheney.com    192.168.1.100
agent01.cheney.com     192.168.1.101

即可实现域名解析,如果没有安装dnsmasq,那么两台的hosts文件都需要在hosts文件里添加刚刚的两条记录.

3.修改master的配置文件

vim /etc/puppet/puppet.conf

[master]     #定义master段
bindaddress = 0.0.0.0    #服务器监听地址,四个零表示所有
masterport = 8140     #master监听端口
ssldir = /etc/puppet/server_ssl    #ssl认证文件路径
logdir = /data1/puppet    #日志文件路径
manifest = /etc/puppet/manifests/site.pp    #agent连接master时的起始配置文件
modulepath = /etc/puppet/modules      #模块目录
certname = master01.chency.com        #master的FQDN,全称域名

[agent]     #定义agent段
report = true    #开启agent上报日志功能

4.配置site.pp文件

vim /etc/puppet/manifests/site.pp

notify{"hello world":}    #notify的作用是发送'hello world'的内容到agent终端

5.启动master

puppet master --verbose
#启动后可以查询端口,也可以查询日志文件来看启动状态
netstat -tunlp |grep 8140
tcp    0    0    0.0.0.0:8140        0.0.0.0:*         LISTEN      5956/ruby

6.启动agent

puppet agent --server=master01.cheney.com --test
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for agent01.cheney.com
Info: Applying configuration version '1426151646'
Notice: hello world               #看到这行表示我们之前的配置是成功的
Notice: /Stage[main]/Main/Notify[hello world]/message: defined 'message' as 'hello world'
Notice: Finished catalog run in 0.33 seconds

PS:由于我之前已经做过ssl认证,所以出现的内容可能和你们不一样,你们要在master文件手动通过认证

puppet cert sign 'agent01.cheney.com'

之后再次启动agent就可以看到正确的信息了