一、相关说明
生产线上使用zabbix 2.4.5 对所有业务及系统网络进行监控,当然也需要监控mysql数据库相关的信息,zabbix自带的mysql监控模板就可以监控mysql,本文在zabbix 2.4.5版本下通过,其他版本请自行实验.
二、配置要监控的mysql
1、先授权让zabbixagent连接数据库:
以mysql roott身份登录到mysql
$mysql -uroot -p123456 -e"GRANT USAGE ON *.* TO ‘zabbixagent‘@‘localhost‘ IDENTIFIED BY ‘zbbixagent‘"; $GRANT USAGE,PROCESS,SUPER,REPLICATION CLIENT,REPLICATION SLAVE ON *.* TO ‘zabbixagent‘@‘localhost‘ IDENTIFIED BY ‘zabbixagent‘; $flush privileges;
或者:
#mysql -uroot -p -e"GRANT USAGE ON *.* TO ‘zabbixagent‘@‘localhost‘ IDENTIFIED BY ‘zabbixagent‘"
2、添加mysql配置文件
vim /etc/zabbix/.my.cnf
#Zabbix Agent [mysql] host=localhost user=zabbixagent password=zabbixagent socket=/data1/mysqldb/mysql/mysql.sock [mysqladmin] host=localhost user=zabbixagent password=zabbixagent socket=/data1/mysqldb/mysql/mysql.sock
注意:socket 具体放在那里,请修改前查看 cat /etc/my.cnf 里的路径
三、修改/etc/zabbix/zabbix_agent.conf
修改如下:
UnsafeUserParameters=1
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/
四、修改mysql模板参数
zabbix -2.4.4中自带mysql模板,默认就放在/etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
需要把HOME=/var/lib/zabbix 换成:HOME=/etc/zabbix
.,$s/\/var\/lib/\/etc/g(vim命令行模式全部替换)
重启zabbix_agent
#service zabbix_agent restart
如果不能出图或出现 Not supported 到zabbix服务器上tail -f /var/log/zabbix/zabbix_server.log
27659:20150428:111248.007 error reason for "ydnwy-01:mysql.status[Uptime]" changed: Received value [ERROR 2002 (HY000):
Can‘t connect to local MySQL server through socket ‘/data1/mysqldb/mysql/mysql.sock‘ (13)]
is not suitable for value type [Numeric (unsigned)] and data type [Decimal]
出现类似错误说明监控端mysql.sock访问有问题,请检查权限或
#ln -s /data1/mysqldb/mysql/mysql.sock /var/lib/mysql/mysql.sock
五、参考以下文档
http://lihuipeng.blog.51cto.com/3064864/1558971
本文出自 “学无止境,学以致用” 博客,请务必保留此出处http://dyc2005.blog.51cto.com/270872/1943405
原文地址:http://dyc2005.blog.51cto.com/270872/1943405