概述
zabbix配置钉钉报警
一、服务版本
linux:7.5-1804
zabbix:4.0.22
mysql:5.7.17
nginx:1.16.1
php:5.4.16
python-pip:2.7.5
二、部署zabbix利用自带模板监控mysql数据库
1、可以参照网上的文档,这里不再赘述
三、配置mysql利用zabbix
1、IP规划
Hostname | ip | 服务 |
---|---|---|
zabbix-server | 192.168.43.10 | zabbix-server、zabbix-agent、MySQL、nginx、php、python-pip |
zabbix-agent-mysql | 192.168.43.11 | MySQL |
2、利用zabbix自带模板实现对mysql监控
a.在zabbix-agent-mysql的MySQL里授权
[root@zabbix-agent-mysql ~]# mysql -uroot -p
mysql> grant select on *.* to “zabbix”@”%” identified by “123456”;
3、修改UnsafeUserParameter参数
[root@zabbix-agent-mysql ~]# grep UnsafeUserParameters /etc/zabbix/zabbix_agent.conf
### Option: UnsafeUserParameters
UnsafeUserParameters=1
4、编写监控脚本
[root@zabbix-agent-mysql ~]# vim /etc/zabbix/script/chk_mysql.sh
#!/bin/bash
MySQlBin=/usr/bin/mysql
MySQLAdminBin=/usr/bin/mysqladmin
Host=192.168.43.11
User=zabbix
Password=123456
if [[ $# == 1 ]];then
case $1 in
Uptime)
result=`$MySQLAdminBin -u$User -p$Password -h$Host status 2>/dev/null
|cut -f2 -d":"|cut -f1 -d"T"`
echo $result
;;
Com_update)
result=`$MySQLAdminBin -u$User -p$Password -h$Host extended-status 2>/dev/null
|grep -w "Com_update"|cut -d"|" -f3`
echo $result
;;
Slow_queries)
result=`$MySQLAdminBin -u$User -p$Password -h$Host status 2>/dev/null
|cut -f5 -d":"|cut -f1 -d"O"`
echo $result
;;
Com_select)
result=`$MySQLAdminBin -u$User -p$Password -h$Host extended-status 2>/dev/null
|grep -w "Com_select"|cut -d"|" -f3`
echo $result
;;
Com_rollback)
result=`$MySQLAdminBin -u$User -p$Password -h$Host extended-status 2>/dev/null
|grep -w "Com_rollback"|cut -d"|" -f3`
echo $result
;;
Questions)
result=`$MySQLAdminBin -u$User -p$Password -h$Host status 2>/dev/null
|cut -f4 -d":"|cut -f1 -d"S"`
echo $result
;;
Com_insert)
result=`$MySQLAdminBin -u$User -p$Password -h$Host extended-status 2>/dev/null
|grep -w "Com_insert"|cut -d"|" -f3`
echo $result
;;
Com_delete)
result=`$MySQLAdminBin -u$User -p$Password -h$Host extended-status 2>/dev/null
|grep -w "Com_delete"|cut -d"|" -f3`
echo $result
;;
Com_commit)
result=`$MySQLAdminBin -u$User -p$Password -h$Host extended-status 2>/dev/null
|grep -w "Com_commit"|cut -d"|" -f3`
echo $result
;;
Bytes_sent)
result=`$MySQLAdminBin -u$User -p$Password -h$Host extended-status 2>/dev/null
|grep -w "Bytes_sent" |cut -d"|" -f3`
echo $result
;;
Bytes_received)
result=`$MySQLAdminBin -u$User -p$Password -h$Host extended-status 2>/dev/null
|grep -w "Bytes_received" |cut -d"|" -f3`
echo $result
;;
Com_begin)
result=`$MySQLAdminBin -u$User -p$Password -h$Host extended-status 2>/dev/null
|grep -w "Com_begin"|cut -d"|" -f3`
echo $result
;;
*)
echo -e "