Zabbix和MPM监控MySQL
Zabbix和MPM监控MySQL
-
请参考《安装部署分布式监控系统Zabbix 2.06》 http://www.linuxidc.com/Linux/2013-07/86942.htm
-
注意:以下操作都是在被监控端执行的。
-
MPM下载及其依赖安装
MPM(PERFORMANCE MONITOR FOR MYSQL)依赖的相关Perl模块安装:
yum install perl-File-Which perl-libwww-perl perl-Digest-SHA1 perl-DBD-MySQL perl-Time-HiRes perl-Crypt-SSLeay
下载MPM并解压:
wget -c http://www.shinguz.ch/download/mysql_performance_monitor-latest.tar.gz
tar zxvf mysql_performance_monitor-latest.tar.gz -
Zabbix Web UI导入MPM模板
MPM模板:
tar zxvf mysql_performance_monitor_templates-0.9.1.tar.gz
cd mysql_performance_monitor_templates-0.9.1/xml
-
在Zabbix Web UI导入监控所需的模板(“Configuration”->”Templates”->”Import”):
Template_FromDual.MySQL.mpm.xml (监控mpm agent本身,这个必须导入)
Template_FromDual.MySQL.server.xml (监控Linux系统跟数据库使用相关的附加项)
Template_FromDual.MySQL.process.xml (监控各种Linux进程[比如:mysqld,ndbd])
Template_FromDual.MySQL.mysql.xml (监控MySQL常用状态变量)
Template_FromDual.MySQL.innodb.xml (监控InnoDB存储引擎状态变量)
Template_FromDual.MySQL.myisam.xml (监控MyISAM存储引擎状态变量)
Template_FromDual.MySQL.master.xml (监控MySQL主从复制的Master状态)
Template_FromDual.MySQL.slave.xml (监控MySQL主从复制的Slave状态)
MPM其它用途的模板:
Template_FromDual.MySQL.ndb.xml (监控MySQL Cluster)
Template_FromDual.MySQL.galera.xml (监控MySQL Galera Cluster)
Template_FromDual.MySQL.pbxt.xml (监控PBXT存储引擎状态变量)
Template_FromDual.MySQL.aria.xml (监控Aria存储引擎的状态变量)
Template_FromDual.MySQL.drbd.xml (监控DRBD设备状态信息) -
安装MPM和配置MPM Agent的Zabbix Keys
安装MPM:
tar zxvf mysql_performance_monitor_agent-0.9.1.tar.gz mv mysql_performance_monitor_agent-0.9.1 /usr/local/mysql_performance_monitor-agent
修改FromDualMySQLagent.pl中的zabbix_sender的路径:
cd /usr/local/mysql_performance_monitor-agent/ sed -i 's|/usr/local/bin|/usr/local/zabbix/bin/|g' FromDualMySQLagent.pl
将MPM Agent的Keys配置添加到Zabbix Agentd配置文件目录中:
cd /usr/local/zabbix/etc/zabbix_agentd.conf.d vi FromDual_MySQL_monitoring.conf # cat FromDual_MySQL_monitoring.conf
UserParameter=FromDual.MySQL.check,/usr/local/mysql_performance_monitor-agent/FromDualMySQLagent.pl /usr/local/mysql_performance_monitor-agent/etc/FromDualMySQLagent.conf
-
MPM Agent配置
创建MySQL监控用户mpm:
mysql> create user 'mpm'@'127.0.0.1' identified by '123456'; mysql> grant process, replication client on *.* to 'mpm'@'127.0.0.1'; mysql> flush privileges;
配置MPM Agent:
cd /usr/local/mysql_performance_monitor-agent/etc cp FromDualMySQLagent.conf.template FromDualMySQLagent.conf mkdir -p /var/log/zabbix mkdir -p /var/log/zabbix/cache touch /var/log/zabbix/FromDualMySQLagent.log chown -R zabbix:zabbix /var/log/zabbix chmod o+r /var/run/mysqld/mysqld.pid #这里要根据自己实际情况进行修改 vi FromDualMySQLagent.conf # cat FromDualMySQLagent.conf
[default] # Type of section: # mysqld for a normal MySQL database # ndbd for a MySQL cluster Type = mysqld # Debug levels are: # 1 is logging only errors # 2 is logging errors and warnings (this is the default) # 3 logs some informations messages as well # 4 logs everything (for debugging purposes only) Debug = 2 LogFile = /var/log/zabbix/FromDualMySQLagent.log # Directory where the Cache files should be written to: CacheFileBase = /var/log/zabbix/cache/FromDualAgentCache # If you agent is not located in the same time zone as your server # TimeShift = +0.0 # Information for MySQL connections: 下面的这几项需要修改 Username = mpm Password = 123456 MysqlHost = 127.0.0.1 MysqlPort = 3306 # Zabbix Server IP address 需要修改 ZabbixServer = 192.168.1.190 # If section is disabled Disabled = false # Possible modules for databases are: # process mysql myisam aria innodb pbxt ndb master slave drbd galera memcache # Possible modules for servers are: # mpm server # Usual modules are Modules = process mysql myisam innodb # Special parameter which is used for module ndb and process ClusterLog = /var/lib/mysql-cluster/ndb_1_cluster.log # MySQL Pid file, need read permission for zabbix user PidFile = /var/run/mysqld/mysqld.pid #这里也需要修改 [db_server] Type = mysqld Modules = mpm server # All MySQL databases here # Try to avoid section names with spaces! [192.168.1.191_MySQL_5.5.29] # This MUST match Hostname in Zabbix! 注意:该行及以下的几行需要取消注释 Type = mysqld MysqlPort = 3306 Modules = process mysql myisam innodb slave PidFile = /var/run/mysqld/mysqld.pid Debug = 1
注:这里监控的MySQL Server是MySQL主从复制的中的Slave机器.
查看mpm-agent的日志会报错,一个是mysql.pid文件读取权限的问题,这个可以自行解决。还有一个就是连接zabbix server的问题:解决方法如下:
安装MySQL MPM插件时,在zabbix web前端点击Monitoring->Latest data查看监控,没有生成监控数据
查看MPM的日志,发现下面报错
[root@localhost etc]# tail -f /var/log/zabbix/FromDualMySQLagent.log
15989:2017-04-10 07:59:44.725 - INFO: FromDual Performance Monitor for MySQL (0.9.1) run started.
15989:2017-04-10 07:59:44.945 - WARN: 192.168.174.187, 10051, db_server
15989:2017-04-10 07:59:44.945 - WARN: Connection to zabbix server failed (rc=1305)!
15989:2017-04-10 07:59:46.078 - WARN: 192.168.174.187, 10051, db_server
15989:2017-04-10 07:59:46.078 - WARN: Connection to zabbix server failed (rc=1305)!
解决方法:
注释掉Zabbix Agent端下面文件中的check语句
[root@localhost etc]# vim /usr/local/mysql_performance_monitor-agent/lib/sendData.pm
# $rc =
&FromDualMySQLagent::checkConnectionToZabbixServer($main::gParameter{'ZabbixServer'},
$main::gParameter{'ZabbixServerPort'}, $main::gParameter{'Hostname'});
之后关闭Agentd服务,删除cache文件夹里面的文件
[root@localhost cache]# cd /var/log/zabbix/cache
[root@localhost cache]# rm -rf *
之后重启Agentd服务