编写Zabbix模块
1.创建模块目录
[root@master ~]# mkdir -p /etc/puppet/modules/zabbix/{manifests,templates}
2.创建manifests文件
服务器端保存着所有对客户端服务器的配置代码,在puppet里面叫做manifest. 客户端下载manifest之后,可以根据manifest对服务器进行配置,例如软件包管理,用户管理和文件管理等等。
Zabbix Agent程序采用官方提供的软件源,客户端配置文件采用模板方式进行文件下载,由于客户端需要指定Zabbix Server,因此配置文件采用变量进行传递,最后使用“->”指定资源之间的依赖顺序关系。
[root@master ~]# vim /etc/puppet/modules/zabbix/manifests/init.pp
class zabbix {
package { 'zabbix-agent':
ensure => installed,
require => Yumrepo["zabbix"],
}
yumrepo { 'zabbix':
baseurl => "http://repo.zabbix.com/zabbix/2.4/rhel/\$releasever/\$basearch/",
descr => "Zabbix Official Repository",
enabled => 1,
gpgcheck => 0,
}
file { '/etc/zabbix/zabbix_agentd.conf':
content => template("zabbix/zabbix_agentd_conf.erb"),
ensure => file,
}
service { 'zabbix-agent':
ensure => "running",
hasstatus => true,
enable => true,
subscribe => [ File["/etc/zabbix/zabbix_agentd.conf"] ],
}
Package ["zabbix-agent"] -> File ["/etc/zabbix/zabbix_agentd.conf"] -> service ["zabbix-agent"]
}
3.创建模板文件
[root@master ~]# vim /etc/puppet/modules/zabbix/templates/zabbix_agentd_conf.erb
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
EnableRemoteCommands=1
LogRemoteCommands=1
Server=<%= zabbix_server %>
Hostname=<%= fqdn %>
ListenIP=<%= ipaddress %>
Include=/etc/zabbix/zabbix_agentd.d/
4.创建节点文件
[root@master ~]# mkdir /etc/puppet/manifests/nodes
[root@master ~]# vim /etc/puppet/manifests/nodes/agentgroup.pp
node /^agent\d+\.redking\.com$/ {
$zabbix_server = "zabbix.redking.com"
include zabbix
}
5.修改site.pp将测试节点载入Puppet
[root@master ~]# vim /etc/puppet/manifests/site.pp
Package {
allow_virtual => true,
}
import "nodes/agentgroup.pp"
节点agent.redking.com测试
[root@agent ~]# puppet agent --test

客户端已经自动安装zabbix-agent并开启服务。
Zabbix Web界面测试
设置Discovery规则

设置Actions


Monitoring界面








===================END===================
Puppet 学习系列:
Puppet 学习一:安装及简单实例应用 http://www.linuxidc.com/Linux/2013-08/88710.htm
Puppet学习二:简单模块配置和应用 http://www.linuxidc.com/Linux/2013-08/88711.htm
相关阅读:
有关Puppet agent端三种备份恢复方案探讨研究 http://www.linuxidc.com/Linux/2013-07/87885.htm
选择更安全的方式注册你的Puppet节点 http://www.linuxidc.com/Linux/2013-07/87884.htm
通过配置SSH深刻理解Puppet的语法及工作机制 http://www.linuxidc.com/Linux/2013-07/87882.htm
Puppet利用Nginx多端口实现负载均衡 http://www.linuxidc.com/Linux/2013-02/79794.htm
CentOS(5和6)下Puppet的C/S模式实例 http://www.linuxidc.com/Linux/2011-12/50502.htm
Puppet 的详细介绍:请点这里
Puppet 的下载地址:请点这里
更多CentOS相关信息见CentOS 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=14
本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-01/111921.htm
