爱在莫斯科 发表于 2018-8-2 10:06:27

CentOS+Puppet分布式部署Zabbix监控系统

OS:CentOS-6.6-x86_64(Minimal)  
Puppet 3.7.3
  
Zabbix 2.4
  
Puppet/Zabbix master: master/zabbix.redking.com
  
Puppet/Zabbix agent:agent1~5.redking.com
  Puppet安装
  1.服务端安装puppet-server
  puppet不在CentOS的基本源中,需要加入PuppetLabs提供的官方源,Puppet Master服务器端安装puppet-server,自动匹配安装Facter等相关依赖包
# rpm -ivh http://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-7.noarch.rpm  
# yum install -y puppet-server
  
# chkconfig puppetmaster on
  
# service puppetmaster start
  2.客户端安装puppet
# rpm -ivh http://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-7.noarch.rpm  
# yum install -y puppet
  
# chkconfig puppet on
  
# service puppet start
  Puppet Master服务器配置
  1.配置自动认证
  允许所有redking.com域的主机自动颁发证书.创建autosign.conf文件
# cat > /etc/puppet/autosign.conf <<EOF  
> *.redking.com
  
> EOF
  
#
  Puppet Agent客户端配置
  1.修改客户端主配置文件puppet.conf来增加监听与指定服务端域名
# vim /etc/puppet/puppet.conf  

  
      listen = true
  
      server = master.redking.com
http://www.ahlinux.com/uploadfile/2015/0117/20150117091511559.jpg
  Puppet测试
  这样我们可以使用Puppet来管理Puppet,通过配置puppet modules的方式来管理所有puppet客户端,将配置文件应用到所有服务器。
  client需要向服务器端发出请求, 让服务器对客户端进行管理. 这其实是一个证书签发的过程. 第一次运行 puppet 客户端的时候会生成一个SSL证书并指定发给Puppet 服务端, 服务器端如果同意管理客户端,就会对这个证书进行签发,可以用这个命令来签发证书,由于我们已经在客户端设置了server地址,因此不需要跟服务端地址
  为了详细了解注册的过程和日后排错,可以增加参数,因为配置文件里
# puppet agent --testhttp://www.ahlinux.com/uploadfile/2015/0117/20150117091511124.jpg
  no-daemonize 前台输出日志
  verbose 输入更加详细的日志
  debug 更加详细的日志,排错的时候使用
  test 表示测试,就带一个test参数就可以
# puppet agent --no-daemonize --onetime --verbose --debug  服务端查看证书签发信息
# puppet cert list --allhttp://www.ahlinux.com/uploadfile/2015/0117/20150117091511175.jpg
  Zabbix Server安装
  1.配置软件仓库并安装Zabbix
# rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm  
# yum install -y zabbix-server-mysql zabbix-web-mysql mysql-server
  默认创建Zabbix运行的用户及组,创建Web服务器Apache虚拟主机配置文件。
  2.创建数据库并导入数据表
# rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm  
# yum install -y zabbix-server-mysql zabbix-web-mysql mysql-server
  
# service mysqld start
  
# chkconfig mysqld on
  
# mysqladmin -u root password '123456'
  
# mysql -uroot -p123456
  
mysql> create database zabbix character set utf8;
  
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
  
mysql> flush privileges;
  进入Zabbix数据库文件目录导入数据库信息
# cd /usr/share/doc/zabbix-server-mysql-2.4.3/create/  
# mysql -uroot -p123456 zabbix < schema.sql
  
# mysql -uroot -p123456 zabbix < images.sql
  
# mysql -uroot -p123456 zabbix < data.sql
  3.修改Zabbix配置文件配置数据库相关信息
# vim /etc/zabbix/zabbix_server.conf  
DBHost=localhost
  
DBName=zabbix
  
DBUser=zabbix
  
DBPassword=zabbix
  4.设置PHP默认时区
# vim /etc/php.ini  
date.timezone = PRC
  5.启动Zabbix和Apache服务
# service zabbix-server start  
# chkconfig zabbix-server on
  
# service httpd start
  
# chkconfig httpd on
  6.设置Zabbix
  Zabbix安装页面: http://zabbix.redking.com/zabbix/setup.php
http://www.ahlinux.com/uploadfile/2015/0117/20150117091512447.jpg
http://www.ahlinux.com/uploadfile/2015/0117/20150117091512313.jpg
  Zabbix后台界面
http://www.ahlinux.com/uploadfile/2015/0117/20150117091512459.jpg
  编写Zabbix模块
  1.创建模块目录
# mkdir -p /etc/puppet/modules/zabbix/{manifests,templates}  2.创建manifests文件
  服务器端保存着所有对客户端服务器的配置代码,在puppet里面叫做manifest. 客户端下载manifest之后,可以根据manifest对服务器进行配置,例如软件包管理,用户管理和文件管理等等。
  Zabbix Agent程序采用官方提供的软件源,客户端配置文件采用模板方式进行文件下载,由于客户端需要指定Zabbix Server,因此配置文件采用变量进行传递,最后使用“->”指定资源之间的依赖顺序关系。
# 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.创建模板文件
# 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.创建节点文件
# mkdir /etc/puppet/manifests/nodes  
# vim /etc/puppet/manifests/nodes/agentgroup.pp
  
node /^agent\d+\.redking\.com$/ {
  
$zabbix_server = "zabbix.redking.com"
  
include zabbix
  
}
  5.修改site.pp将测试节点载入Puppet
# vim /etc/puppet/manifests/site.pp  
Package {
  
allow_virtual => true,
  
}
  
import "nodes/agentgroup.pp"
  节点agent.redking.com测试
# puppet agent --testhttp://www.ahlinux.com/uploadfile/2015/0117/20150117091512733.jpg
  客户端已经自动安装zabbix-agent并开启服务。
  Zabbix Web界面测试
  设置Discovery规则
http://www.ahlinux.com/uploadfile/2015/0117/20150117091513467.jpg
  设置Actions
http://www.ahlinux.com/uploadfile/2015/0117/20150117091513663.jpg
http://www.ahlinux.com/uploadfile/2015/0117/20150117091513460.jpg
  Monitoring界面
http://www.ahlinux.com/uploadfile/2015/0117/20150117091514962.jpg
http://www.ahlinux.com/uploadfile/2015/0117/20150117091514526.jpg
http://www.ahlinux.com/uploadfile/2015/0117/20150117091514775.jpg
http://www.ahlinux.com/uploadfile/2015/0117/20150117091515359.jpg
http://www.ahlinux.com/uploadfile/2015/0117/20150117091515363.jpg
http://www.ahlinux.com/uploadfile/2015/0117/20150117091515905.jpg
http://www.ahlinux.com/uploadfile/2015/0117/20150117091515360.jpg
http://www.ahlinux.com/uploadfile/2015/0117/20150117091516774.jpg

[*]  本文来自:Linux学习教程网
页: [1]
查看完整版本: CentOS+Puppet分布式部署Zabbix监控系统