关于Zabbix和MySQL安装就不在说明,请自行参考相关文档
复制官方MySQL监控的userparameter到安装目录,我这里是采用的3.4.1源码安装,安装目录在/usr/local/zabbix目录,如果你是rpm包安装请自行寻找文件和目录cp zabbix-3.4.1/conf/zabbix_agentd/userparameter_mysql.conf /usr/local/zabbix/etc/zabbix_agentd.conf.d/
使用root用户登录到MySQL并授权一个专门监控使用的用户,当然也可以直接使用root,但不安全推荐使用普通用户,并且指定需要的权限即可#登录数据库
mysql -uroot -p
#下面是需要在数据库里面执行的命令,为了安装请不要指定all权限,也不要指定所有库,并且需要有一个安全的密码
grant all on *.* to "username"@"localhost" identified by "USER_PASSWORD";
编辑/usr/local/zabbix/etc/zabbix_agentd.conf.d/userparameter_mysql.conf[root@db ~]# cat /usr/local/zabbix/etc/zabbix_agentd.conf.d/userparameter_mysql.conf
# For all the following commands HOME should be set to the directory that has .my.cnf file with password information.
# Flexible parameter to grab global variables. On the frontend side, use keys like mysql.status[Com_insert].
# Key syntax is mysql.status[variable].
UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | HOME=/var/lib/zabbix mysql -N | awk '{print $$2}'
# Flexible parameter to determine database or table size. On the frontend side, use keys like