1.在mysql端(zabbix客户端)修改监控mysql的参数

[root@db01 ~]# vim /etc/my.cnf
[mysql]
auto-rehash
user=用户名
password=密码


[mysqladmin]
user=用户名

password=密码

[root@db01 ~]# vim /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | /usr/local/mysql-5.6.28/bin/mysql -S /tmp/mysql.sock -N | awk '{print $$2}'
UserParameter=mysql.size[*],echo "select sum($(case "$3" in both|"") echo "data_length+index_length";; data|index) echo "$3_length";; free) echo "data_free";; esac)) from information_schema.tables$([[ "$1" = "all" || ! "$1" ]] || echo " where table_schema='$1'")$([[ "$2" = "all" || ! "$2" ]] || echo "and table_name='$2'");" | /usr/local/mysql-5.6.28/bin/mysql -S /tmp/mysql.sock -N

UserParameter=mysql.ping,/usr/local/mysql-5.6.28/bin/mysqladmin -S /tmp/mysql.sock ping | grep -c alive
UserParameter=mysql.version,/usr/local/mysql-5.6.28/bin/mysql -S /tmp/mysql.sock -V

[root@db01 ~]# /etc/init.d/zabbix-agent restart
Shutting down Zabbix agent:       [  OK  ]
Starting Zabbix agent:            [  OK  ]
[root@db01 ~]#

2.在zabbix服务端测试命令

[root@db02 ~]# zabbix_get -s mysql的IP地址 -k "mysql.version"
mysql  Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1
[root@db02 ~]# zabbix_get -s mysql的IP地址 -k "mysql.ping"
0
[root@db02 ~]#

3.在zabbix控制台要监控的主机上附加mysql模板

zabbix监控mysql_第1张图片


4.绘制的图形

zabbix监控mysql_第2张图片

zabbix监控mysql_第3张图片