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并解压:


[root@localhost zabbix]# wget http://www.shinguz.ch/download/mysql_performance_monitor-latest.tar.gz

[root@localhost zabbix]# tar xf mysql_performance_monitor-latest.tar.gz

[root@localhost 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)

wKiom1cxdL6BZvVIAAH2JApnY2o809.png

wKiom1cxdM7gHAHuAADp_ppAdlA588.png

 

 wKioL1cxdbvDdjkbAAE2heDCT_I150.png

 


3.安装MPM并且配置MPM Agent 的zabbix Keys,以实现zabbix挂接MPM

安装MPM Agent

在客户端[mysql 数据库服务器端] 安装mysql_performance_monitor_agent

[root@192 ~]# tar xf mysql_performance_monitor_agent-0.9.1.tar.gz

[root@192 ~]# mv mysql_performance_monitor_agent-0.9.1 /usr/local/mysql_performance_monitor_agent


# 修改 FromDualMySQLagent.pl 文件,指定zabbix_sender的位置

[root@192 ~]# 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_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 :

[root@192 ~]# cd /usr/local/mysql_performance_monitor_agent/etc/

[root@192 etc]# cp FromDualMySQLagent.conf.template FromDualMySQLagent.conf

[root@192 etc]# mkdir -p /var/log/zabbix

[root@192 etc]# mkdir -p /var/log/zabbix/cache

[root@192 etc]# touch /var/log/zabbix/FromDualMySQLagent.log

[root@192 etc]# chown -R zabbix:zabbix /var/log/zabbix

[root@192 etc]# ll /data/3306/mysql.pid 

-rw-rw---- 1 mysql mysql 5 May  6 16:36 /data/3306/mysql.pid

[root@192 etc]# chmod o+r /data/3306/mysql.pid

[root@192 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


[root@192 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

[root@192 etc]#


检查MPM插件工作状况:

[root@192 etc]# /usr/local/mysql_performance_monitor_agent/FromDualMySQLagent.pl /usr/local/mysql_performance_monitor_agent/etc/FromDualMySQLagent.conf

1

[root@192 etc]#

# 返回值为1:表示MPM插件正常,重启zabbix_agent,加载mpm插件

[root@192 etc]# /etc/init.d/zabbix_agentd restart

Stopping Zabbix Agent:                                     [  OK  ]

Starting Zabbix Agent:                                     [  OK  ]

[root@192 etc]#


Zabbix web 端操作

创建监控数据库组

 wKioL1cxddah6OxqAAEbxsp56oE320.png

创建监控主机

 wKiom1cxdQTgWjLYAAGFR9sFTQ0079.png

填写相关主机信息

 wKioL1cxdeuCBTbAAADtEHRJAdA297.png

添加模版

 wKiom1cxdRzSVdx4AAEBZwPGVLE958.png

wKiom1cxdTOQxGfRAACFUt9j5Xg500.png

 

Zabbix Agent 出现错误

[root@192 ~]# tail -f /usr/local/zabbix/logs/zabbix_agentd.log

 wKioL1cxdiHRmHq-AABFu-R3DkM562.png

1.查看zabbix_agentd.conf文件中的Hostname

[root@192 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一样。 

 wKioL1cxdjKTVukHAACBeRGrYqs494.png

3.重新启动zabbix-agent服务

[root@192 etc]# /etc/init.d/zabbix_agentd restart

Stopping Zabbix Agent:                                     [  OK  ]

Starting Zabbix Agent:                                     [  OK  ]

[root@192 etc]#


没解决还是这个错误:

17486:20160510:130427.528 no active checks on server [192.168.1.214:10051]: host [mysqld_192.168.1.212] not found


 

排除错误:

Zabbixserverzabbix-3.0.2.tar.gzzabbix webzabbix-2.4.8.tar.gz,所以重新安装下zabbix server zabbix-2.4.8.tar.gz

wKiom1cxiXuzCyNdAAH-qREm4J4962.png

步骤没有问题,版本的问题。

解决下这个问题:

wKioL1cxim_Cpe2FAAEYvmrwAZs816.png

 

# 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

        …

 

[root@Zabbix_serverzabbix-2.4.8]# /etc/init.d/zabbix_agentd restart

停止 Zabbix Agent                                        [确定]

正在启动 Zabbix Agent                                    [确定]

[root@Zabbix_serverzabbix-2.4.8]#

wKiom1cxiaKgDfBNAAGSSPuj-1s627.png

搞定收工。