zabbixl监控mysql

1.修改zabbix_agent.conf


[root@mysql-master-b etc]# cat zabbix_agentd.conf


LogFile=/tmp/zabbix_agentd.log

#被动模式填服务器的IP
Server=192.168.1.111

#主动模式,填服务器的IP
ServerActive=192.168.1.111

#这里设置的name必须和web界面的一样
Hostname=192.168.1.24


#打开以下两项
 Include=/usr/local/zabbix-agent/etc/zabbix_agentd.conf.d/

 UnsafeUserParameters=1

2.在/usr/local/zabbix-agent/etc/zabbix_agentd.conf.d目录创建监控文件mysql_status.conf


[root@mysql-master-b zabbix_agentd.conf.d]# cat mysql_status.conf
#UserParameter=mysql.version,mysql -V
#UserParameter=mysql.ping,mysql -urepl -phipiao ping | grep -c alive

UserParameter=mysql.status[*],/usr/local/zabbix-agent/scripts/checkmysqlperformance.sh $1 $2



3.写一个脚本,取监控项的值

cat  /usr/local/zabbix-agent/scripts/checkmysqlperformance.sh

#!/bin/sh
MYSQL_SOCK="/var/lib/mysql/mysql.sock"
MYSQL_PWD=`cat /usr/local/zabbix-agent/scripts/mysqlpass.txt`
ARGS=1
HOST="192.168.1.24"


if [ $# -ne "$ARGS" ];then
     echo "Please input onearguement:"
fi
case $1 in


    mysql_replication)
         result=`mysql -urepl -h${HOST} -p${MYSQL_PWD} -e 'show slave status\G' | grep -E "Slave_IO_Running|Slave_SQL_Running"|awk '{print $2}' | grep -c Yes`
        echo $result
        ;;
    
    mysql_delay)
         result=`mysql -urepl -h${HOST} -p${MYSQL_PWD} -e 'show slave status\G' | grep -E "Seconds_Behind_Master" |awk '{print $2}'`
        echo $result
                        
esac

4.重启服务

/usr/local/zabbix-agent/sbin/zabbix_agentd /usr/local/zabbix-agent/etc/zabbix_agentd.conf


5.防火墙配置

iptables -I INPUT -p tcp --dport 10050 -j DROP


iptables -I INPUT  -p tcp -m tcp -s 192.168.1.111  --dport 10050 -m comment --comment "zabbix_agentd listen " -j ACCEPT


/etc/init.d/iptables save

iptables -L -n --line-number


6.在Web界面设置监控项mysql_replication









你可能感兴趣的:(mysql,监控,zabbix)