zabbix监控mysql主从关系

环境

操作系统:Centos 6.* ( 双核4G、硬盘至少20G)
zabbix server :192.168.1.127
zabbix agentd :192.168.1.180
mysql slave : 192.168.1.180
mysql主从参考:http://www.jianshu.com/p/fd6ab5fd22e0

一:zabbix agentd 配置
1.mysql创建用户并赋予权限

grant select,REPLICATION CLIENT on *.* to zabbix@"localhost" identified by "zabbix";

2.刷新用户权限

flush privileges;

3.监控mysql主从同步状态脚本
vim chk_mysql-slave.sh

#!/bin/bash
/usr/local/mysql/bin/mysql   -e 'show slave status\G' |grep -E "Slave_IO_Running|Slave_SQL_Running"|awk '{print $2}'|grep -c Yes

4.获取mysql从同步post值实时变化脚本
vim chk_post.sh

#!/bin/bash
/usr/local/mysql/bin/mysql   -e 'show slave status\G' |grep -E "Read_Master_Log_Pos"|cut -d":" -f2 |sed 's/ //g'

5.给脚本添加执行权限

chmod +x chk_post.sh
chmod +x chk_mysql-slave.sh
post-status.png

6.在agentd配置文件末尾添加zabbix获取key值
vim /etc/zabbix/zabbix_agentd.conf

UserParameter=mysql.replication,/etc/zabbix/chk_mysql-slave.sh $1
UserParameter=mysql.post,/etc/zabbix/chk_post.sh $1

7.重启服务

/etc/init.d/zabbix-agent restart

二:zabbix server端
1.zabbix server服务器端分别获取post及状态值

/usr/local/zabbix/bin/zabbix_get -s192.168.1.180 -p10050 -k mysql.replication
/usr/local/zabbix/bin/zabbix_get -s192.168.1.180 -p10050 -k mysql.post
post-server.png

2.zabbix server web端
在本地新建一个txt文档,将以下模板内容粘贴并将名字及后缀更改为master-slave.xml, 导入此模板添加到zabbix agentd主机里即可



    3.2
    2017-07-19T06:29:36Z
    
        
            Templates
        
    
    
        
    
    
        
            {master-slave:mysql.replication.last()}=0
            0
            
            mysql_IO and RUN
            0
            
            
            0
            5
            
            0
            0
            
            
        
        
            {master-slave:mysql.replication.last()}=1
            0
            
            mysql_IO or RUN
            0
            
            
            0
            4
            
            0
            0
            
            
        
    
    
        
            mysql.post
            900
            200
            0.0000
            100.0000
            0
            0
            0
            1
            0
            0.0000
            0.0000
            0
            0
            0
            0
            
                
                    0
                    5
                    99FFFF
                    0
                    2
                    0
                    
                        master-slave
                        mysql.post
                    
                
            
        
        
            mysql IO RUN
            900
            200
            0.0000
            100.0000
            1
            1
            1
            1
            0
            0.0000
            0.0000
            0
            0
            0
            0
            
                
                    0
                    5
                    00EEEE
                    0
                    2
                    0
                    
                        master-slave
                        mysql.replication
                    
                
            
        
    


zabbix server端监控mysql post值


zabbix监控mysql主从关系_第1张图片
f1.png

zabbix server端监控mysql主从状态


zabbix监控mysql主从关系_第2张图片
f2.png

你可能感兴趣的:(zabbix监控mysql主从关系)