上章我们把zabbix的服务端和客户端都部署完成了,本章接着进行两部分的设置:
1 添加对mysql数据库主机的监控
2 添加对mysql数据库的监控
一、对数据库服务器主机监控
1 创建主机
步骤如下:组态>>主机>>创建主机
进入创建主机的界面,如下,填写信息后保存。
正确添加后状态是绿色的已启用:
2、为主机添加模板
模板添加完成后,出现绿色的表示监控成功了:
解决中文乱码问题:到windows中C:\Windows\Fonts选择一种喜欢的字体拷贝到/var/www/html/zabbix/fonts/下,替代里面的原文件。然后刷新即可
二、对mysql数据库监控(重点内容)
我们这里采用一款第三方插件:MPM(Performance Monitor for MySQL),关于该插件的具体下载及介绍请访问这里:http://www.fromdual.com/mpm-installation-guide
下面我们就开始安装和配置MPM来监控mysql数据库
1、安装配置MPM
1)安装perl依赖包
由于该插件是perl写的,需要在所有机器上安装perl依赖。
[root@node1 software]# yum install perl-File-Which perl-libwww-perl perl-Digest-SHA perl-DBD-MySQL perl-Time-HiRes perl-Crypt-SSLeay -y
2)zabbix web导入MPM模板文件
[root@node1 software]# tar zxvf mysql_performance_monitor-latest.tar.gz
-rw-rw-r--. 1 1000 1000 37667 4月 10 2013 mysql_performance_monitor_agent-0.9.1.tar.gz
-rw-rw-r--. 1 1000 1000 40991 4月 10 2013 mysql_performance_monitor_templates-0.9.1.tar.gz
[root@node1 software]# tar zxvf mysql_performance_monitor_templates-0.9.1.tar.gz
mysql_performance_monitor_templates-0.9.1/xml/Template_FromDual.MySQL.ndb.xml
mysql_performance_monitor_templates-0.9.1/xml/Template_FromDual.MySQL.security.xml
mysql_performance_monitor_templates-0.9.1/xml/Template_FromDual.MySQL.innodb.xml
mysql_performance_monitor_templates-0.9.1/xml/Template_FromDual.MySQL.mpm.xml
mysql_performance_monitor_templates-0.9.1/xml/Template_FromDual.MySQL.myisam.xml
mysql_performance_monitor_templates-0.9.1/xml/Template_FromDual.MySQL.mysql.xml
mysql_performance_monitor_templates-0.9.1/xml/Template_FromDual.MySQL.aria.xml
mysql_performance_monitor_templates-0.9.1/xml/Template_FromDual.MySQL.galera.xml
mysql_performance_monitor_templates-0.9.1/xml/Template_FromDual.MySQL.slave.xml
mysql_performance_monitor_templates-0.9.1/xml/Template_FromDual.MySQL.server.xml
mysql_performance_monitor_templates-0.9.1/xml/Template_FromDual.MySQL.master.xml
mysql_performance_monitor_templates-0.9.1/xml/Template_FromDual.MySQL.drbd.xml
mysql_performance_monitor_templates-0.9.1/xml/Template_FromDual.MySQL.pbxt.xml
mysql_performance_monitor_templates-0.9.1/xml/Template_FromDual.MySQL.process.xml
解压后会有两个文件,其中mysql_performance_monitor_templates-0.9.1.tar.gz主要是zabbix server web需要导入的模板文件,mysql_performance_monitor_agent-0.9.1.tar.gz文件则是zabbix客户端需要部署的客户端文件。
上面模板根据自己线上的业务选择合适的导入即可。其中mysql_performance_monitor_templates-0.9.1/xml/Template_FromDual.MySQL.mpm.xml必须要导入的。
然后到到zabbix web页面 组态>>模板>>汇入 进行导入:
3)安装MPM并且配置MPM agent的zabbix keys,以实现zabbix 挂接MPM
这些操作只在各个被监控的mysql服务器上进行。
[root@node2 software]# tar zxvf mysql_performance_monitor_agent-0.9.1.tar.gz
[root@node2 software]# mv mysql_performance_monitor_agent-0.9.1 /usr/local/mysql_performance_monitor-agent
修改FromDualMySQLagent.pl脚本中相应的zabbix_sender路径:
[root@node1 software]# cd /usr/local/mysql_performance_monitor-agent
[root@node1 mysql_performance_monitor-agent]# vim FromDualMySQLagent.pl
$ENV{PATH} .= $ENV{PATH} . ':/usr/local/zabbix/bin';
4)MPM Agent配置
创建MPM的MySQL监控用户:
(product)root@localhost [(none)]> grant process,replication client on *.* to 'mpm'@'127.0.0.1' identified by 'mpm';
Query OK, 0 rows affected (0.05 sec)
(product)root@localhost [(none)]> flush privileges;
Query OK, 0 rows affected (0.02 sec)
配置MPM Agent:
[root@node1 mysql_performance_monitor-agent]# cd /usr/local/mysql_performance_monitor-agent/etc
[root@node1 etc]# cp FromDualMySQLagent.conf.template FromDualMySQLagent.conf
[root@node1 logs]# mkdir /usr/local/zabbix/logs/mpm/cache -p
[root@node1 logs]# touch /usr/local/zabbix/logs/mpm/FromDualMySQLagent.log
[root@node1 logs]# chown -R zabbix.zabbix /usr/local/zabbix/logs/mpm
[root@node1 data]# chmod o+r /data/mysql/mysql_3306/data/darren.pid
[root@node1 data]# vim /usr/local/mysql_performance_monitor-agent/etc/FromDualMySQLagent.conf
[default]
Type = mysqld
Debug = 2
LogFile = /usr/local/zabbix/logs/mpm/FromDualMySQLagent.log
CacheFileBase = /usr/local/zabbix/logs/mpm/cache/FromDualAgentCache
# Information for MySQL connections:
Username = mpm
Password = mpm
MysqlHost = 127.0.0.1
MysqlPort = 3306
# Zabbix Server IP address
ZabbixServer = 192.168.245.133
Disabled = false
Modules = process mysql myisam innodb master slave
[db_server]
Type = mysqld
Modules = mpm server
# All MySQL databases here
[node2] # This MUST match Hostname in Zabbix!
Type = mysqld
MysqlPort = 3306
Modules = process mysql myisam slave innodb
PidFile = /data/mysql/mysql_3306/data/mysqlnode1.pid
[node2] # This MUST match Hostname in Zabbix!
Type = mysqld
MysqlPort = 3307
Modules = process mysql myisam slave innodb
PidFile = /data/mysql/mysql_3307/data/mysqlnode1.pid
5)在zabbix agent中注入MPM:
[root@node1 data]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
#在最后添加这行
UserParameter=FromDual.MySQL.check,/usr/local/mysql_performance_monitor-agent/FromDualMySQLagent.pl /usr/local/mysql_performance_monitor-agent/etc/FromDualMySQLagent.conf
6)检查MPM插件设置是否正确:输出1表示正常
[root@node1 data]# /usr/local/mysql_performance_monitor-agent/FromDualMySQLagent.pl /usr/local/mysql_performance_monitor-agent/etc/FromDualMySQLagent.conf
1
7)重启zabbix_agentd服务
[root@node2 data]# /etc/init.d/zabbix_agentd restart
停止 Zabbix Agent: [确定]
正在启动 Zabbix Agent: [确定]
终极问题:
3801:2014-05-09 14:53:26.283 - INFO: FromDual Performance Monitor for MySQL (0.9.1) run started.
3801:2014-05-09 14:53:26.301 - ERR : Load of cache file failed. rc=1301
3801:2014-05-09 14:53:26.301 - INFO: FromDual Performance Monitor for MySQL run finshed (rc=0).
遇到这个问题,始终解决不了,也就是生成监控数据了,但是无法发送给zabbix server,哪位大神遇到过请指教吧?对这个软件也是无语了,安装就遇到如此多的问题,果断舍弃了,浪费太多时间了,还是老老实实用percona-monitoring-plugins了!