简单说明:
依据《CentOS7实验机模板搭建部署》克隆实验机192.168.77.210,部署Zabbix 3.0 LTS
配置邮件告警功能,配置自动发现功能,配置action对发现的主机自动监控并邮件告警
部署安装Zabbix 3.0 LTS:
# 主机名和hosts解析部署
HOSTNAME=zabbix
hostnamectl set-hostname "$HOSTNAME"
echo "$HOSTNAME">/etc/hostname
echo "$(grep -E '127|::1' /etc/hosts)">/etc/hosts
echo "$(ip a|grep "inet "|grep -v 127|awk -F'[ /]' '{print $6}') $HOSTNAME">>/etc/hosts
# 安装MySQL
yum -y install mariadb-server mariadb
systemctl restart mariadb
systemctl enable mariadb
# 使用官方yum源安装Zabbix
# https://www.zabbix.com/download?zabbix=3.0&os_distribution=centos&os_version=7&db=MySQL
cd /tmp
axel https://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
rpm -ivh /tmp/zabbix-release-3.0-1.el7.noarch.rpm
yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent
# 建库,导入zabbix库
mysql
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
flush privileges;
quit;
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -pzabbix zabbix
# 修改配置文件,启动
sed -i 's/# DBPassword=.*/&\nDBPassword=zabbix/g' /etc/zabbix/zabbix_server.conf
sed -i 's|# \(php_value date.timezone\) Europe/Riga|\1 Asia/Shanghai|g' /etc/httpd/conf.d/zabbix.conf
cd /etc/zabbix/
sed -i 's/^Server=127.0.0.1/Server=zabbix/g' zabbix_agentd.conf
sed -i 's/^ServerActive=127.0.0.1/ServerActive=zabbix:10051/g' zabbix_agentd.conf
sed -i "s/^\(Hostname=\).*/\1$(hostname)/g" zabbix_agentd.conf
systemctl restart zabbix-server zabbix-agent httpd
systemctl enable zabbix-server zabbix-agent httpd
# 网页配置 http://192.168.77.210/zabbix
# 默认用户名和密码 Admin/zabbix
配置邮件告警功能:
配置自动发现功能并测试:
1° 依据《CentOS6实验机模板搭建部署》克隆测试机 192.168.77.250 并部署:
# 主机名和hosts解析部署
hostname zabbixtest
echo "$(grep -E '127|::1' /etc/hosts)">/etc/hosts
echo "$(ifconfig eth0|grep inet|awk -F'[ :]' '{print $13}') $(hostname)">>/etc/hosts
echo "192.168.77.210 zabbix_server">>/etc/hosts
sed -i "s/^HOSTNAME.*$/HOSTNAME=$(hostname)/g" /etc/sysconfig/network
ping -c 3 $(hostname)
# 使用官方yum源安装配置Zabbix agent
cd /tmp
wget https://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm
rpm -ivh /tmp/zabbix-release-3.0-1.el6.noarch.rpm
yum -y install zabbix-agent
cd /etc/zabbix/
sed -i 's/^Server=127.0.0.1/Server=zabbix_server/g' zabbix_agentd.conf
sed -i 's/^ServerActive=127.0.0.1/ServerActive=zabbix_server:10051/g' zabbix_agentd.conf
sed -i "s/^\(Hostname=\).*/\1$(hostname)/g" zabbix_agentd.conf
chkconfig zabbix-agent on
/etc/init.d/zabbix-agent start
2° 网页添加自动发现功能
Configuration——>Discovery——>Create discovery rule
# 因为设置的Delay为60秒,时间较短,会造成 Zabbix discoverer processes more than 75% busy
# 并且使自动发现任务无法生效,因此要调整参数,重启server
sed -i 's|# StartDiscoverers=1|StartDiscoverers=50|g' /etc/zabbix/zabbix_server.conf
systemctl restart zabbix-server
# 该参数最大可以设置成250,需要对应的调整mysql的连接数
# sed -i 's/^\[mysqld\]$/&\nmax_connections = 400/g' /etc/my.cnf
# sed -i 's/^\[mysqld\]$/&\nmax_user_connections = 8000/g' /etc/my.cnf
# sed -i 's/^\[mysqld\]$/&\nmax_connect_errors = 65535/g' /etc/my.cnf
# systemctl restart mariadb
Monitoring>Discovery——>Status of discovery
配置Action自动添加OS并邮件告警:
Configuration——>Actions——>Event source: Discovery——>Create action
此处可以看出,可以依据下线状态的主机进行操作,比如删除掉下线主机
[TOC]