zabbix配置自动发现警告、监控mariadb主从复制
zabbix配置自动发现警告、监控mariadb主从复制
一、 配置zabbix自动发现警报
1、 配自动发现客户端
1)
安装zabbix客户端
[[email protected] ~]# rm -rf /etc/yum.repos.d/CentOS-*
[[email protected] ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[[email protected] ~]# yum -y install zabbix-agent
2)
修改zabbix客户端配置文件
[[email protected] ~]# vim /etc/zabbix/zabbix_agentd.conf
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=192.168.100.10
ServerActive=192.168.100.10
Hostname=192.168.100.20
Include=/etc/zabbix/zabbix_agentd.d/*.conf
#UnsafeUserParameters=0
[[email protected]~]# vim /etc/zabbix/zabbix_agentd.conf
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=192.168.100.10
ServerActive=192.168.100.10
Hostname=192.168.100.30
Include=/etc/zabbix/zabbix_agentd.d/*.conf
#UnsafeUserParameters=0
3)
启动zabbix客户端服务
[[email protected] ~]# systemctl start zabbix-agent
[[email protected] ~]# systemctl enable zabbix-agent
[[email protected]~]# systemctl start zabbix-agent
[[email protected]~]# systemctl enable zabbix-agent
2、 配置自动发现规则
1)
配置中设置自动发现
2)
设置自动发现规则
3、 配置自动添加主机
1)
设置计算机群组
2)
创建计算机群组
4、 设置自动发现动作
1)
修改默认自动发现
2)
设置自动IP地址自动发现
3)
设置自动发现动作
4)
检查客户端是否自动连接
5)
查看硬盘
5、 设置邮箱
1)
配置163邮箱支持zabbix发送电子邮件
2)
手机扫描二维码
3)
获取授权验证码
4)
SMTP服务器地址
6、 设置收发邮件警报
1)
创建警报类型
2)
配置接收zabbix警报账户
7、 设置用户警报
1)
设置用户
2)
设置信息警报
3)
设置警报触发器
4)
设置异常警报
默认接收人:故障{TRIGGER.STATUS}==>服务器{HOSTNAME1} 发生 {TRIGGER.NAME}故障!
默认信息:
异常主机:{HOST.NAME}
告警 IP:{HOST.IP}
告警时间:{EVENT.DATE}-{EVENT.TIME}
告警等级:{TRIGGER.SEVERITY}
告警项目:{TRIGGER.KEY1}
告警信息:{TRIGGER.NAME}
问题详情:{ITEM.NAME}:{ITEM.VALUE}
当前状态:{TRIGGER.STATUS}:{ITEM.VALUE1}
事件 ID:{EVENT.ID}
来自zabbix监控平台
5)
警报维护操作
6)
配置故障恢复
恢复主题:恢复{TRIGGER.STATUS}==>服务器{HOSTNAME1}: {TRIGGER.NAME}已恢复!
恢复信息:
恢复主机:{HOST.NAME}
恢复 IP:{HOST.IP}
恢复时间:{EVENT.RECOVERY.TIME}
等级:{TRIGGER.SEVERITY}
告警项目:{TRIGGER.KEY1}
恢复信息:{TRIGGER.NAME}
问题详情:{ITEM.NAME}:{ITEM.VALUE}
当前状态:{TRIGGER.STATUS}:{ITEM.VALUE1}
事件 ID:{EVENT.ID}
来自zabbix监控平台
8、 配置100.20的触发器
1)
配置触发器空间低于百分之90发送警报
2)
Zabbix服务器添加NAT网卡联网
3)
写入测试文件
[[email protected] ~]# dd if=/dev/zero of=./1.iso bs=10M count=1000
[[email protected] ~]# dd if=/dev/zero of=./2.iso bs=10M count=1000
[[email protected] ~]# dd if=/dev/zero of=./3.iso bs=10M count=1000
4)
查看警报
5)
登陆163邮件查看警报
二、监控mariadb主从复制
1、配置监控mariadb主从复制
1)
安装zabbix客户端
[[email protected] ~]# rm -rf /etc/yum.repos.d/CentOS-*
[[email protected] ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[[email protected] ~]# yum -y install zabbix-agent
[[email protected] ~]# yum -y install zabbix-agent
2)
修改zabbix客户端主配置文件
[[email protected] ~]# vim /etc/zabbix/zabbix_agentd.conf
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=192.168.100.10
ServerActive=192.168.100.10
Hostname=192.168.100.40
Include=/etc/zabbix/zabbix_agentd.d/*.conf
#UnsafeUserParameters=0
[[email protected] ~]# vim /etc/zabbix/zabbix_agentd.conf
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=192.168.100.10
ServerActive=192.168.100.10
Hostname=192.168.100.50
Include=/etc/zabbix/zabbix_agentd.d/*.conf
#UnsafeUserParameters=0
3)
启动zabbix客户端
[[email protected] ~]# systemctl start zabbix-agent
[[email protected] ~]# systemctl enable zabbix-agent
[[email protected] ~]# systemctl start zabbix-agent
[[email protected] ~]# systemctl enable zabbix-agent
4)
把mariadb主从服务器添加到zabbix监控
2、安装mariadb数据库
1)
安装mariadb数据库
[[email protected] ~]# yum -y install mariadb mariadb-server
[[email protected] ~]# yum -y install mariadb mariadb-server
2)
启动mariadb数据库服务
[[email protected] ~]# systemctl start mariadb
[[email protected] ~]# systemctl enable mariadb
3)
设置访问数据库密码
[[email protected] ~]# mysqladmin -uroot password
New password:
Confirm new password:
[[email protected] ~]# mysqladmin -uroot password
New password:
Confirm new password:
3、配置ntp同步时间
1)
修改ntp主配置文件
[[email protected] ~]# vim /etc/ntp.conf
18 restrict 192.168.100.0 mask 255.255.255.0 nomodify notrap
19 server 127.127.1.0
20 fudeg 127.127.1.0 stratum 8
2)
启动ntp服务
[[email protected] ~]# systemctl start ntpd
[[email protected] ~]# systemctl enable ntpd
3)
从节点同步时间
[[email protected] ~]# ntpdate 192.168.100.40
22 Apr 00:01:22 ntpdate[1789]: step time server 192.168.100.40 offset -0.877339 sec
4、配置mariadb主从复制
1)
修改mariadb主的配置文件
[[email protected] ~]# vim /etc/my.cnf
[mysqld]
log-bin=mysql-bin
log-slave-updates=true
server-id=10
[[email protected] ~]# systemctl restart mariadb
2)
修改mariadb从的配置文件
[[email protected] ~]# vim /etc/my.cnf
[mysqld]
log-bin=mysql-bin
server-id=20
relay-log=relay-log-bin
relay-log-index=relay-slave-bin.index
[[email protected] ~]# systemctl restart mariadb
3)
授权数据复制账户slave密码[email protected]
[[email protected] ~]# mysql -uroot [email protected]
MariaDB [(none)]> grant replication slave on . to ‘slave’@‘192.168.100.%’ identified by ‘[email protected]’;
Query OK, 0 rows affected (0.01 sec)
4)
配置主从复制
[[email protected] ~]# mysql -uroot [email protected]
MariaDB [(none)]> show master status;
[[email protected] ~]# mysql -uroot [email protected]
MariaDB [(none)]> change master to master_host=‘192.168.100.40’,master_user=‘slave’,master_password=‘[email protected]’,master_log_file=‘mysql-bin.000001’,master_log_pos=401;
Query OK, 0 rows affected (0.01 sec)
5)
启动slave查看
MariaDB [(none)]> start slave;
MariaDB [(none)]> show slave status\G;
5、配置监控mariadb
1)
添加脚本
[[email protected] ~]# vim /etc/zabbix/mysql.sh
#/bin/bash
mysql -uroot [email protected] -e “show slave status\G” | grep -E “Slave_IO_Running|Slave_SQL_Running” | grep -c Yes
[[email protected] ~]# chmod +x /etc/zabbix/mysql.sh
[[email protected] ~]# sh /etc/zabbix/mysql.sh
2
2)
客户端加载脚本
[[email protected] ~]# vim /etc/zabbix/zabbix_agentd.conf
UserParameter=mysql.replication,sh /etc/zabbix/mysql.sh
[[email protected] ~]# systemctl restart zabbix-agent
3)
监控mariadb主从复制状态