最新消息:

使用Zabbix监控Mysql

mysql admin 4394浏览 0评论

使用Zabbix监控Mysql
使用Zabbix监控Mongodb
使用Zabbix监控Postfix

系统:CentoOS 5.5 x86_64

Zabbix版本:1.8.11

Mysql版本:5.5.11

一、安装Perl模块
# perl -MCPAN -e shell
cpan> install File::Which
cpan> install Bundle::LWP
cpan> install Digest::SHA1
cpan> install DBI
cpan> install DBD::mysql
cpan> install Time::HiRes
cpan> install Crypt::SSLeay

在安装DBD::mysql时,提示安装成功,但运行下面的perl脚本时,提示找不到DBD::mysql,这样的话使用源码安装DBD::mysql;

二、在zabbix server端导入监控模板
导入相应需要的模板:
Template_FromDual.MySQL.mpm.xml  –>(必须)
Template_FromDual.MySQL.server.xml  –>监控与数据库相关的Linux服务器性能模板
Template_FromDual.MySQL.process.xml –>监控各种Linux进程
Template_FromDual.MySQL.mysql.xml   –>监控Mysql的常用状态变量
Template_FromDual.MySQL.myisam.xml  –>监控Myisam存储引擎状态变量
Template_FromDual.MySQL.innodb.xml  –>监控Innodb存储引擎状态变量
Template_FromDual.MySQL.master.xml  –>监控Mysql Master状态
Template_FromDual.MySQL.slave.xml   –>监控Mysql Slave状态

三、在Mysql数据库服务器上上传监控脚本
cd /usr/local
tar xvf mysql_performance_monitor_agent-0.9.tar.gz
mv mysql_performance_monitor_agent-0.9/ mysql_performance_monitor
cd mysql_performance_monitor/etc
cp FromDualMySQLagent.conf.template 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
#执行日志文件路径,需要zabbix用户可写权限
LogFile       = /data/log/zabbix/FromDualMySQLagent.log
# Directory where the Cache files should be written to:
CacheFileBase = /tmp/FromDualAgentCache

# Information for MySQL connections:
#需要在Mysql中进行授权
Username     = mpm
Password     = password
MysqlHost    = 127.0.0.1
MysqlPort    = 3306

# Zabbix Server IP address
ZabbixServer = 192.168.100.241

# 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   = /data/log/zabbix/ndb_1_cluster.log
#Mysql的PID文件,需要zabbix用户可读权限
PidFile      = /data/mysql/data/mysqld.pid

#下面的主机名需要跟Zabbix Server里面定义的主机名一致
[192.168.100.166]
Type         = mysqld
Modules      = mpm server process mysql myisam innodb

五、修改Zabbix Agent配置文件
#/etc/zabbix/zabbix_agentd.conf
UserParameter=FromDual.MySQL.check,/usr/local/mysql_performance_monitor/

FromDualMySQLagent.pl /usr/local/mysql_performance_monitor/etc/FromDualMySQLagent.conf

修改FromDualMySQLagent.pl脚本里面的zabbix_sender路径:
# This is needed to find zabbix_sender!
$ENV{PATH} .= $ENV{PATH} . ‘:/usr/local/zabbix/bin’;  #将/usr/local/bin修改为/usr/local/zabbix/bin(为zabbix_sender路径)

六、Mysql数据库授权、重启Zabbix客户端
CREATE USER ‘mpm’@’127.0.0.1′ IDENTIFIED BY ‘mpmsecret’;
GRANT PROCESS ON *.* TO ‘mpm’@’127.0.0.1′;
GRANT REPLICATION CLIENT ON *.* TO ‘mpm’@’127.0.0.1′;

/etc/init.d/zabbix_agentd restart

查看日志或Zabbix Server上的LastData数据检查是否可以正常接收到数据:
tail -f /data/log/zabbix/FromDualMySQLagent.log

参考:http://www.fromdual.com/mpm-installation-guide

转载请注明:爱开源 » 使用Zabbix监控Mysql

您必须 登录 才能发表评论!