1、安裝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;
2、在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狀態
3、在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
4、修改監控腳本配置文件
# 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/b2b-tj-demo166.bw.mg.pid
#下面的主機名須要跟Zabbix Server裏面定義的主機名一致
[125.39.195.166]
Type = mysqld
Modules = mpm server process mysql myisam innodb
5、修改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路徑)
6、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