MPM插件部署
1.安装MPM依赖的相关perl模块
安装mpm需要的相关依赖包:[保险起见,agent端也安装下面的依赖包]
# yum -y install perl-File-Which perl-libwww-perl perl-Digest-SHA1 perl-DBD-MySQL perl-Time-HiRes perl-Crypt-SSLeay
# yum -y install perl-File-Which perl-libwww-perl perl-Digest-SHA1 perl-DBD-MySQL perl-Time-HiRes perl-Crypt-SSLeay
# yum -y install perl-CPAN.x86_64
# yum -y install which.x86_64
# yum -y install perl-LWP-Authen-Negotiate.noarch
# yum -y install perl-Digest-SHA1.x86_64
# yum -y install perl-Class-DBI-mysql.noarch
# yum -y install perl-Time-HiRes.x86_64
# yum -y install perl-Crypt-SSLeay.x86_64
下载MPM并解压:
[[email protected] zabbix]# wget http://www.shinguz.ch/download/mysql_performance_monitor-latest.tar.gz
[[email protected] zabbix]# tar xf mysql_performance_monitor-latest.tar.gz
[[email protected] zabbix]# ls -lrt
mysql_performance_monitor_agent-0.9.1.tar.gz
mysql_performance_monitor_templates-0.9.1.tar.gz
2.zabbix web 端导入MPM模版
在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)
3.安装MPM并且配置MPM Agent 的zabbix Keys,以实现zabbix挂接MPM
安装MPM Agent
在客户端[mysql 数据库服务器端] 安装mysql_performance_monitor_agent
[[email protected] ~]# tar xf mysql_performance_monitor_agent-0.9.1.tar.gz
[[email protected] ~]# mv mysql_performance_monitor_agent-0.9.1 /usr/local/mysql_performance_monitor_agent
# 修改 FromDualMySQLagent.pl 文件,指定zabbix_sender的位置
[[email protected] ~]# cd /usr/local/mysql_performance_monitor_agent
# sed -i "[email protected]/usr/local/[email protected]/usr/local/zabbix/[email protected]" FromDualMySQLagent.pl
将mpm Agent 的keys信息加入到zabbix_agentd的配置目录中
这个参数配置文件,是自己新建的
# cd /usr/local/zabbix/etc/zabbix_agent.conf.d/
# vim 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
4.MPM Agent 配置
创建MPM的Mysql监控用户
mysql> create user ‘mpm‘@‘127.0.0.1‘ identified by "123456";
Query OK, 0 rows affected (0.00 sec)
mysql> grant process,replication client on *.* to ‘mpm‘@‘127.0.0.1‘;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> grant process,replication client on *.* to ‘mpm‘@‘localhost‘ identified by "123456";
Query OK, 0 rows affected (0.00 sec)
配置 MPM Agent :
[[email protected] ~]# cd /usr/local/mysql_performance_monitor_agent/etc/
[[email protected] etc]# cp FromDualMySQLagent.conf.template FromDualMySQLagent.conf
[[email protected] etc]# mkdir -p /var/log/zabbix
[[email protected] etc]# mkdir -p /var/log/zabbix/cache
[[email protected] etc]# touch /var/log/zabbix/FromDualMySQLagent.log
[[email protected] etc]# chown -R zabbix:zabbix /var/log/zabbix
[[email protected] etc]# ll /data/3306/mysql.pid
-rw-rw---- 1 mysql mysql 5 May 6 16:36 /data/3306/mysql.pid
[[email protected] etc]# chmod o+r /data/3306/mysql.pid
[[email protected] etc]# vim FromDualMySQLagent.conf
[default]
Type = mysqld
Debug = 2
#执行日志文件路径,需要zabbix用户可写权限
LogFile = /var/log/zabbix/FromDualMySQLagent.log
CacheFileBase = /var/log/zabbix/cache/FromDualAgentCache
#需要在本机的Mysql中进行授权(需要什么权限?process,replication client)
Username = mpm
Password = 123456
MysqlHost = 127.0.0.1
MysqlPort = 3306
ZabbixServer = 192.168.1.214
Disabled = false
Modules = process mysql myisam innodb
#ClusterLog = /var/lib/mysql-cluster/ndb_1_cluster.log
# Mysql的PID文件,需要zabbix用户可读权限
PidFile = /data/3306/mysql.pid
# 下面这个不能注掉也不能改section名称,探测本机的mpm是否可用
[db_server]
Type = mysqld
Modules = mpm server
#下面的主机名需要跟Zabbix Server里面定义的主机名一致,名称随意起
[hostname1]
Type = mysqld
#这些模块必须在mysql数据库上已经实现了功能,如主从,如果没有配置主从,而添加了master模板,在执行过程中就会报错
Type = mysqld
MysqlPort = 3306
Modules = mpm server process mysql myisam innodb master
PidFile = /data/3306/mysql.pid
Debug = 1
[[email protected] etc]# cat FromDualMySQLagent.conf |egrep -v "^#|^$"
[default]
Type = mysqld
Debug = 2
LogFile = /var/log/zabbix/FromDualMySQLagent.log
CacheFileBase = /var/log/zabbix/cache/FromDualAgentCache
Username = mpm
Password = 123456
MysqlHost = 127.0.0.1
MysqlPort = 3306
ZabbixServer = 192.168.1.214
Disabled = false
Modules = process mysql myisam innodb
ClusterLog = /var/lib/mysql-cluster/ndb_1_cluster.log
PidFile = /data/3306/mysql.pid
[db_server]
Type = mysqld
Modules = mpm server
[mysqld_192.168.1.212] # This MUST match Hostname in Zabbix!
Type = mysqld
MysqlPort = 3306
Modules = process mysql myisam innodb slave
PidFile = /data/3306/mysql.pid
Debug = 1
[[email protected] etc]#
检查MPM插件工作状况:
[[email protected] etc]# /usr/local/mysql_performance_monitor_agent/FromDualMySQLagent.pl /usr/local/mysql_performance_monitor_agent/etc/FromDualMySQLagent.conf
1
[[email protected] etc]#
# 返回值为1:表示MPM插件正常,重启zabbix_agent,加载mpm插件
[[email protected] etc]# /etc/init.d/zabbix_agentd restart
Stopping Zabbix Agent: [ OK ]
Starting Zabbix Agent: [ OK ]
[[email protected] etc]#
Zabbix web 端操作
创建监控数据库组
创建监控主机
填写相关主机信息
添加模版
Zabbix Agent 出现错误
[[email protected] ~]# tail -f /usr/local/zabbix/logs/zabbix_agentd.log
1.查看zabbix_agentd.conf文件中的Hostname
[[email protected] etc]# grep Hostname /usr/local/zabbix/etc/zabbix_agentd.conf
Hostname=mysqld_192.168.1.212
2.在zabbix web页面Monitoring->Configuration->Hosts 页面更改Host name和zabbix_agentd.conf里面的Hostname一样。
3.重新启动zabbix-agent服务
[[email protected] etc]# /etc/init.d/zabbix_agentd restart
Stopping Zabbix Agent: [ OK ]
Starting Zabbix Agent: [ OK ]
[[email protected] etc]#
没解决还是这个错误:
17486:20160510:130427.528 no active checks on server [192.168.1.214:10051]: host [mysqld_192.168.1.212] not found
排除错误:
Zabbixserver是zabbix-3.0.2.tar.gz,zabbix web是zabbix-2.4.8.tar.gz,所以重新安装下zabbix server 为zabbix-2.4.8.tar.gz。
步骤没有问题,版本的问题。
解决下这个问题:
# egrep-v "^#|^$" /usr/local/zabbix/etc/zabbix_agentd.conf
PidFile=/tmp/zabbix_agentd.pid
LogFile=/tmp/zabbix_agentd.log
Server=127.0.0.1
ListenPort=10050
ServerActive=127.0.0.1
Hostname=Zabbixserver
# cdzabbix-2.4.8
# cpmisc/init.d/fedora/core5/zabbix_agentd /etc/init.d/
# vim/etc/init.d/zabbix_agentd
prog="ZabbixAgent"
ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_agentd"
CONF_FILE="/usr/local/zabbix/etc/zabbix_agentd.conf"
start(){
…
daemon $ZABBIX_BIN -c $CONF_FILE
…
}
[[email protected]_serverzabbix-2.4.8]# /etc/init.d/zabbix_agentd restart
停止 Zabbix Agent: [确定]
正在启动 Zabbix Agent: [确定]
[[email protected]_serverzabbix-2.4.8]#
搞定收工。