ITPub博客

首页 > 数据库 > MySQL > Zabbix监控MySQL

Zabbix监控MySQL

原创 MySQL 作者:pathfinder_cui 时间:2015-08-20 20:04:38 1 删除 编辑
http://itindex.net/detail/52128-mysql-%E5%B7%A5%E5%85%B7-zabbix
一.更换yum源
rpm -ivh http://repo.zabbix.com/zabbix/2.0/rhel/6/x86_64/zabbix-release-2.0-1.el6.noarch.rpm
二.安装必要的软件程序包
yum install -y mysql-server mysql-devel mysql httpd php gcc*
yum install -y mysql-dev gcc net-snmp-devel curl-devel perl-DBI php-gd php-mysql php-bcmatch php-mbstring php-xml wget php-bcmath

三.安装Fping
wget -c http://fping.org/dist/fping-3.4.tar.gz
tar xf fping-3.4.tar.gz
cd fping-3.4
./configure
make && make install
echo $?
groupadd zabbix
useradd -g zabbix zabbix
chown root.zabbix /usr/local/sbin/fping
chmod 4710 /usr/local/sbin/fping

四.安装zabbix server
下载网址:http://bbs.51cto.com/thread-1070384-1.html
wget http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.0.6/zabbix-2.0.6.tar.gz
tar xf zabbix-2.0.6.tar.gz
cd zabbix-2.0.6
export MYSQL_HOME=/home/mysql/mysqlhome
export C_INCLUDE_PATH=$MYSQL_HOME/include
export LD_LIBRARY_PATH=$MYSQL_HOME/lib
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-proxy --with-mysql=/usr/bin/mysql_config --with-net-snmp --with-libcurl
make && make install

五.配置数据库
/etc/init.d/mysqld restart
cd /root/zabbix-2.0.6/database/mysql
mysql
show databases;
create schema zabbix character set utf8;
use zabbix
create user 'zabbix'@'%' identified by '123456';
grant all on zabbix.* to zabbix@'%';
flush privileges;
source schema.sql;
source images.sql;
source data.sql;

六.配置Zabbix配置文件
vim /usr/local/zabbix/etc/zabbix_server.conf

ListenPort=10051
LogFile=/usr/local/zabbix/logs/zabbix_server.log
PidFile=/usr/local/zabbix/logs/zabbix_server.pid
DBHost=192.168.10.250
DBName=zabbix
DBUser=zabbix
DBPassword=123456
DBSocket=/var/lib/mysql/mysql.sock
DBPort=3306
FpingLocation=/usr/local/sbin/fping

七.配置Zabbix服务器脚本
cd zabbix-2.0.6
cp misc/init.d/fedora/core5/zabbix_server /etc/init.d/
mkdir -p /usr/local/zabbix/logs
chown -R zabbix.zabbix /usr/local/zabbix
vim /etc/init.d/zabbix_server
   ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_server"
   CONF_FILE="/usr/local/zabbix/etc/zabbix_server.conf"
   将start()函数中
   #daemon $ZABBIX_BIN    替换为  daemon $ZABBIX_BIN -c $CONF_FILE

八.配置Zabbix Web服务器
cd zabbix-2.0.6
cp -ra frontends/php/* /var/www/html/
vim /etc/httpd/conf/httpd.conf
ServerName 192.168.10.250:80

vim /etc/php.ini
date.timezone = Asia/Shanghai
max_execution_time = 300
max_input_time = 300
memory_limit = 128M
session.auto_start = 0
mbstring.func_overload = 2
post_max_size = 16M
extension=bcmath.so

/etc/init.d/httpd restart
(可选)
iptables -A INPUT -p tcp -m tcp --dport 10050 -j ACCEPT

九.Zabbix Web安装
http://http://192.168.10.250/
username: admin  password:zabbix

#############################################################################################

MPM(Performance Monitor for MySQL)是一套比较完整的MySQL数据库的Zabbix插件,包括监控项和触发规则,通过与Zabbix客户端整合,可以实现MySQL的监控
首先zabbix_agentd会读取配置文件zabbix_agentd.conf和FROMDual_MySQL_monitoring.conf(包含FromDualMySQLagent.pl脚本)文件,将zabbix客户端与MPM插件实现挂接操作,
通过FromDualMySQLagent.pl实现解析调优perl模块(.pm)。最终通过调用zabbix_sender实现上传。
部署MPM
1.安装和部署Zabbix Server软件,zabbix web;
2.下载安装MPM软件包以及依赖的Perl模板;
3.通过Zabbix Web导入MPM中所需要的模板文件
4.在Zabbix web创建组、创建主机关联模板(MPM agent配置中的数据库,注意在web端配置的hostname必须与MPM agent配置中所使用的一致)
5.安装配置MPM Agent,将MPM整合到zabbix中
6.重启服务

Template_FromDual.MySQL.mpm.xml     监控MPM agent本身,这个必须导入,因为它会触发发送进程
Template_FromDual.MySQL.server.xml  监控Linux系统和附加的数据库信息
Template_FromDual.MySQL.process.xml 监控各种linux进制,比如:mysqld信息
Template_FromDual.MySQL.mysql.xml   监控mysql常用状态变量信息
Template_FromDual.MySQL.innodb.xml  监控innodb状态变量信息
Template_FromDual.MySQL.myisam.xml  
Template_FromDual.MySQL.master.xml  监控主从复制master状态信息
Template_FromDual.MySQL.slave.xml   监控主从复制slave状态信息

Template_FromDual.MySQL.ndb.xml     监控MySQL NDB 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设备状态信息


一.在Agent主机上
tar xf zabbix-2.0.6.tar.gz
cd zabbix-2.0.6
mkdir /usr/local/zabbix
./configure --prefix=/usr/local/zabbix --enable-agent
make && make install
cp misc/init.d/fedora/core5/zabbix_agentd /etc/init.d/
groupadd zabbix
useradd -g zabbix zabbix
mkdir -p /usr/local/zabbix/logs
chown zabbix.zabbix -R /usr/local/zabbix/
vim /usr/local/zabbix/etc/zabbix_agentd.conf

PidFile=/usr/local/zabbix/logs/zabbix_agentd.pid
LogFile=/usr/local/zabbix/logs/zabbix_agentd.log
Server=192.168.10.250
ListenPort=10050
ServerActive=192.168.10.250
Hostname=zabbix_agent39
Timeout=15
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/

vim /etc/init.d/zabbix_agentd
ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_agentd"
CONF_FILE="/usr/local/zabbix/etc/zabbix_agentd.conf"
将start()函数中
#daemon $ZABBIX_BIN    替换为  daemon $ZABBIX_BIN -c $CONF_FILE

(可选)
iptables -A INPUT -p tcp -m tcp --dport 10050 -j ACCEPT
 /etc/init.d/zabbix_agentd restart

测试
/usr/local/zabbix/sbin/zabbix_agentd -c /usr/local/zabbix/etc/zabbix_agent.conf -t system.uptime

部署MPM插件
yum install perl-File-Which perl-libwww-perl perl-Digest-SHA perl-DBD-MySQL perl-Time-HiRes perl-Crypt-SSLeay

下载文件,文件中有监控模板文件和MPN
wget -c http://www.shinguz.ch/download/mysql_performance_monitor-latest.tar.gz
tar xf mysql_performance_monitor-latest.tar.gz
tar xf mysql_performance_monitor_agent-0.9.1.tar.gz
mv mysql_performance_monitor_agent-0.9.1 /usr/local/mysql_performance_monitor_agent
cd /usr/local/mysql_performance_monitor_agent
sed -i "s|/usr/local/bin|/usr/local/zabbix/bin|g" FromDualMySQLagent.pl
vim  /usr/local/zabbix/etc/zabbix_agentd.conf
UserParameter=FromDual.MySQL.check,/usr/local/mysql_performance_monitor_agent/FromDualMySQLagent.pl  /usr/local/mysql_performance_monitor_agent/etc/FromDualMySQLagent.conf

mysql
create user 'mpm'@'127.0.0.1' identified by '123456';
grant process,replication client on *.* to 'mpm'@'127.0.0.1';
flush privileges;
exit

cd /usr/local/mysql_performance_monitor_agent/etc/
cp -a 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 /mysql/data/localhost.localdomain.pid    #被监控的mysql的pid

cd /usr/local/mysql_performance_monitor_agent/etc
vim FromDualMySQLagent.conf
[default]
Type         = mysqld
LogFile       = /var/log/zabbix/FromDualMySQLagent.log
Username     = mpm
Password     = 123456
MysqlHost    = 127.0.0.1
MysqlPort    = 3307
ZabbixServer = 192.168.10.250
Modules      = process mysql myisam innodb
[db_server]
Type         = mysqld
Modules      = mpm server
[mysql39]          # web页面中监控主机名。
Type         = mysqld
MysqlPort    = 3307
Modules      = process mysql myisam slave
PidFile      = /mysql/data/localhost.localdomain.pid  #被监控的mysql的pid




测试PMP(1表示正常)
/usr/local/mysql_performance_monitor_agent/FromDualMySQLagent.pl   /usr/local/mysql_performance_monitor_agent/etc/FromDualMySQLagent.conf

/etc/init.d/zabbix_agentd start

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29620572/viewspace-1777923/,如需转载,请注明出处,否则将追究法律责任。

下一篇: Jenkins+Tomcat
请登录后发表评论 登录
全部评论

注册时间:2014-04-21

  • 博文量
    55
  • 访问量
    58125