感谢支持
我们一直在努力

使用Zabbix + MPM全面监控MySQL

Zabbix和MPM监控MySQL

  • 环境说明

    A: 192.168.1.190, 系统CentOS 6.3,部署Zabbix Server
    B: 192.168.1.191, 系统CentOS 6.3,部署Zabbix Agent, MySQL 5.5.29 (MySQL Slave)

  • MPM/Zabbix监控结构及部署步骤

    MPM/Zabbix监控结构:

    mpm_arch

    MPM/Zabbix监控MySQL的大概步骤如下:

    • 安装部署Zabbix
    • 下载安装MPM(Performance Monitor for MySQL)及其依赖的Perl模块
    • 导入MPM模板
    • 创建host group(可选)
    • 创建host (即MPM agent配置中的database)
      值得注意的是:Hostname必须与MPM agent配置中的所使用的一致
    • 将选择的模板关联到创建的host
    • 配置MPM agent
    • 将MPM agent”挂钩”到Zabbix agent
      # cat /path_to_zabbix_agent_conf/zabbix_agentd.conf
      UserParameter=FromDual.MySQL.check,/path_to_mpm_agent/FromDualMySQLagent.pl \
      /path_to_mpm_agent_conf/FromDualMySQLagent
    • 重启Zabbix agent
  • 安装部署Zabbix

    请参考《安装部署分布式监控系统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机器.

  • 开始监控MySQL
    Zabbix Web UI创建host (192.168.1.191_MySQL_5.5.29):
  • host_mysql_1

    host_mysql_2

    重启Zabbix Agentd:

    # /etc/init.d/zabbix_agentd restart
    

    Zabbix Web UI的”Monitoring”->”Latest data”可以查看监控情况:

    mpm_snapshot

    推荐阅读:

    CentOS 6.3下Zabbix安装部署 http://www.linuxidc.com/Linux/2013-05/83786.htm

    Zabbix分布式监控系统实践 http://www.linuxidc.com/Linux/2013-06/85758.htm

    CentOS 6.3下Zabbix监控apache server-status http://www.linuxidc.com/Linux/2013-05/84740.htm

    CentOS 6.3下Zabbix监控MySQL数据库参数 http://www.linuxidc.com/Linux/2013-05/84800.htm

    更多关于ZABBIX 的详细信息,或者下载地址请点这里

赞(0) 打赏
转载请注明出处:服务器评测 » 使用Zabbix + MPM全面监控MySQL
分享到: 更多 (0)

听说打赏我的人,都进福布斯排行榜啦!

支付宝扫一扫打赏

微信扫一扫打赏