1.安装mpm需要的相关依赖包:[保险起见,agent端也安装下面的依赖包]
- [root@client141 ~]# yum -y install perl-File-Which perl-libwww-perl perl-Digest-SHA1 perl-DBD-MySQL perl-Time-HiRes perl-Crypt-SSLeay
- # 上面perl-File-Which没有自带,需要自行下载安装(如果还提示perl包,根据需要安装相应perl版本)
- [root@client141 ~]# rpm -ivh perl-File-Which-1.09-5.1.noarch.rpm
2.下载mpm并解压:[解压后会产生两个压缩包]
- [root@client141 ~]# tar -zxvf mysql_performance_monitor-latest.tar.gz
- mysql_performance_monitor_agent-0.9.1.tar.gz
- mysql_performance_monitor_templates-0.9.1.tar.gz
3.在zabbixe服务端或者是web端解压模板文件:
- [root@client141 ~]# tar -zxvf mysql_performance_monitor_templates-0.9.1.tar.gz
- mysql_performance_monitor_templates-0.9.1/
- mysql_performance_monitor_templates-0.9.1/CHANGELOG
- mysql_performance_monitor_templates-0.9.1/xml/
- 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/clone_screen.txt
- 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
4.在zabbix server端或web导入相应模板文件:[加粗部分为需要导入的模板]
- [root@client141 ~]# cd mysql_performance_monitor_templates-0.9.1/xml/
- 在Zabbix Web UI导入监控所需的模板(“Configuration”->”Templates”->”Import”):
- 具体模板文件用途如下:
- Template_FromDual.MySQL.ndb.xml # 监控mysql cluster
- Template_FromDual.MySQL.security.xml
- Template_FromDual.MySQL.innodb.xml # 监控innodb存储引擎状态变量
- Template_FromDual.MySQL.mpm.xml # 监控mpm agent本身,这个必须导入
- Template_FromDual.MySQL.myisam.xml # 监控myisam存储引擎状态变量
- Template_FromDual.MySQL.mysql.xml # 监控mysql 常用状态变量
- Template_FromDual.MySQL.aria.xml # 监控aria存储引擎的状态变量
- Template_FromDual.MySQL.galera.xml # 监控 mysql galera cluster
- Template_FromDual.MySQL.slave.xml # 监控mysql主从复制中的slave的状态
- Template_FromDual.MySQL.server.xml # 监控linux系统跟数据库使用相关的附加项
- Template_FromDual.MySQL.master.xml # 监控mysql主从复制的master的状态
- Template_FromDual.MySQL.drbd.xml # 监控drbd 设备的状态信息
- Template_FromDual.MySQL.pbxt.xml # 监控pbxt存储引擎状态变量
- Template_FromDual.MySQL.process.xml # 监控各种linux进程(比如:mysqld,ndbd)
5.在客户端[mysql 数据库服务器端] 安装mysql_performance_monitor_agent
- [root@client100 ~]# tar -zxvf mysql_performance_monitor_agent-0.9.1.tar.gz
- [root@client100 ~]# mv mysql_performance_monitor_agent-0.9.1 /usr/local/mysql_performance_monitor_agent
- [root@client100 ~]# cd /usr/local/mysql_performance_monitor_agent/
- # 修改 FromDualMySQLagent.pl 文件,指定zabbix_sender的位置
- [root@client100 mysql_performance_monitor_agent]# sed -i 's|/usr/local/bin|/usr/bin|g' FromDualMySQLagent.pl
- # 编辑配置文件
- [root@client100 mysql_performance_monitor_agent]# cd etc/
- [root@client100 etc]# cp FromDualMySQLagent.conf.template /etc/FromDualMySQLagent.conf
- [root@client100 etc]# vim /etc/FromDualMySQLagent.conf
- [default]
- Type = mysqld
- Debug = 2
- #执行日志文件路径,需要zabbix用户可写权限
- LogFile = /var/log/zabbix/FromDualMySQLagent.log
- CacheFileBase = /var/log/zabbix/cache/FromDualAgentCache
- #需要在Mysql中进行授权
- Username = mpm
- Password = kongzhong
- MysqlHost = 127.0.0.1
- MysqlPort = 3306
- ZabbixServer = 192.168.1.141
- Disabled = false
- Modules = process mysql myisam innodb
- #ClusterLog = /var/lib/mysql-cluster/ndb_1_cluster.log
- # Mysql的PID文件,需要zabbix用户可读权限
- PidFile = /var/run/mysqld/mysqld.pid
- #[db_server]
- #Type = mysqld
- #Modules = mpm server
- #下面的主机名需要跟Zabbix Server里面定义的主机名一致
- [client100]
- Type = mysqld
- #这些模块必须在mysql数据库上已经实现了功能,如主从,如果没有配置主从,而添加了master模板,在执行过程中就会报错
- Modules = mpm server process mysql myisam innodb master
- PidFile = /var/run/mysqld/mysqld.pid
6.修改zabbix agent 配置文件:
- # 这个参数配置文件,是自己新建的
- [root@client100 ~]# vim /etc/zabbix/zabbix_agentd.d/FromDual_MySQL_monitoring.conf
- # 添加如下参数:
- UserParameter=FromDual.MySQL.check,/usr/local/mysql_performance_monitor_agent/FromDualMySQLagent.pl /etc/FromDualMySQLagent.conf
7.登陆数据库,授权相应的mpm用户,权限
- mysql> grant process,replication client on *.* to 'mpm'@'127.0.0.1' identified by 'kongzhong';
- mysql> flush privileges;
8.修改 FromDualMySQLagent.conf 配置文件相关目录的权限:
- # 创建相关日志存放目录:
- [root@client100 ~]# mkdir -p /var/log/zabbix/cache
- # 手动创建日志文件:
- [root@client100 ~]#touch /var/log/zabbix/FromDualMySQLagent.log
- # 修改目录权限:
- [root@client100 ~]#chown zabbix:zabbix /var/log/zabbix/ -R
- # 修改权限
- [root@client100 log]# chmod o+r /var/run/mysqld/mysqld.pid
- # zabbix-agent 重启
- [root@client100 etc]# /etc/init.d/zabbix-agent restart
9.上面配置完成后,就需要在zabbix web创建组和主机,关联相关模板,这里不演示了
10.简单测试:
(1).检查MPM插件的工作情况:
- [root@client100 ~]# /usr/local/mysql_performance_monitor_agent/FromDualMySQLagent.pl /etc/FromDualMySQLagent.conf
- 1
- # 返回值为1:表示MPM插件正常,重启zabbix_agent,加载mpm插件
(2).在实际中,如果怀疑是zabbix_agentd问题,使用如下测试方式:
- [root@client100 ~]# zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf -t FromDual.MySQL.check
- FromDual.MySQL.check [t|1]
- [root@client100 ~]# zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf -t system.uptime
- system.uptime [u|6518]
- # 以上能正常返回值,说明zabbix_agent是正常的
(3). 如果有错误的话,请查看/var/log/zabbix下的相关日志,很多是权限问题,注意查看修改
# 提示pid文件不可读:采用:usermod -G mysql zabbix
(4). 报如下故障时:
- ([root@client100 ~]# tail -f /var/log/zabbix/FromDualMySQLagent.log ),其他zabbix服务端、客户端日志都正常,无报错
- 5279:2014-03-17 15:26:39.853 - INFO: FromDual Performance Monitor for MySQL (0.9.1) run started.
- 5279:2014-03-17 15:26:39.867 - WARN: 192.168.1.141, 10051, db_server
- 5279:2014-03-17 15:26:39.867 - WARN: Connection to zabbix server failed (rc=1305)!
- 5279:2014-03-17 15:26:40.878 - WARN: 192.168.1.141, 10051, db_server
- 5279:2014-03-17 15:26:40.878 - WARN: Connection to zabbix server failed (rc=1305)!
- 5279:2014-03-17 15:26:40.882 - WARN: 192.168.1.141, 10051, 192.168.1.100
- 5279:2014-03-17 15:26:40.882 - WARN: Connection to zabbix server failed (rc=1305)!
- 5279:2014-03-17 15:26:41.890 - WARN: 192.168.1.141, 10051, 192.168.1.100
- 可采取措施如下步骤:
- 第一步:修改 FromDualMySQLagent.conf 配置文件,注释掉如下部分:[这些注释的部分,因为在zabbix web没有配置此主机]
- # [db_server]
- # Type = mysqld
- # Modules = mpm server
- [client100]
- Type = mysqld
- Mysqlport=3306
- Modules = mpm server process mysql myisam innodb master
- PidFile = /var/run/mysqld/mysqld.pid
- 第二步: 注释掉模块里检查zabbix server 的语句:
- [root@client100 ~]# vim /usr/local/mysql_performance_monitor_agent/lib/sendData.pm
- # 注释掉的语句如下:
- # $rc = &FromDualMySQLagent::checkConnectionToZabbixServer($main::gParameter{'ZabbixServer'}, $main::gParameter{'ZabbixServerPort'}, $main::gParameter{'Hostname'});
(5). 要注意 /var/log/zabbix/cache/ 目录下相关文件的权限,保证zabbix用户下
- [root@client100 ~]# cd /var/log/zabbix/cache/
- [root@client100 cache]# ll
- -rw-rw-r-- 1 zabbix zabbix 0 Mar 22 07:25 FromDualAgentCache.192.168.1.100.cache
- # 特别需要注意的是:此文件没有写入是正常的,因为程序自动清空了此文件,但如果说文件不停的变大,那就说明配置有问题,数据没有发出去
(6). 报如下错误,处理方式为:
- 12933:2014-03-22 06:52:06.005 - INFO: FromDual Performance Monitor for MySQL (0.9.1) run started.
- 12933:2014-03-22 06:52:06.019 - ERR : Load of cache file failed. rc=1301
- 12933:2014-03-22 06:52:07.029 - ERR : Load of cache file failed. rc=1301
- # 报此错了,上面的文件,也在不断变大,一般是上面文件有错,建议删掉文件,重新启动程序,让程序自己再重新创建个新文件(而不是清空文件)
(7).在zabbix web 端配置主机组时,主机组为 mysql database (可以设置为其他组,已经测试成功)