【博文推荐】CentOS6.6+Puppet3.7.3分布式部署Zabbix2.4监控系统(1)(2)
编写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并开启服务。
评论暂时关闭