zabbix监控mysql主从同步

获取主从复制sql线程和I/O线程状态是否为yes
#!/bin/bash
HOSTNAME="数据库IP"
PORT="端口"
USERNAME="用户"
PASSWORD="密码"
SOCK="/mkt/mysql/5.6.40/3308/mysql.sock"
#select="show slave STATUS\G"
#STATUS=`mysql  -h${HOSTNAME} -p${PASSWORD} -u${USERNAME} -P ${PORT} -S ${SOCK}` -e 'SHOW SLAVE STATUS\G'

# | egrep '(Slave_IO_Running|Slave_SQL_Running):' | awk -F: '{print $2}' | tr '\n' ','`

#sql=`mysql -h${HOSTNAME} -p${PASSWORD} -u${USERNAME} -P${PORT} -e${select} -S /mkt/mysql/5.6.40/3308/mysql.sock | grep -v password | egrep '(Slave_IO_Running|Slave_SQL_Running):' | awk -F: '{print $2}' | tr '\n' ','`
#echo $sql
#STATUS=`echo ${sql} | grep -v 'Warning'`
#echo $STATUS

#STATUS= `echo $sql |  egrep '(Slave_IO_Running|Slave_SQL_Running):' | awk -F: '{print $2}' | tr '\n' ','`
#if [ "$sql" =  " Yes, Yes," ]; then
#    echo 1
#else
#    echo 0
#fi


array=($(mysql -h${HOSTNAME} -p${PASSWORD} -u${USERNAME} -P${PORT} -S /mkt/mysql/5.6.40/3308/mysql.sock  -e "show slave status\G" 2>/dev/null | grep "Running" |awk '{print $2}'))
 if [ "${array[0]}" == "Yes" ] || [ "${array[1]}" == "Yes" ]
          then
            echo "1"
       else
            echo "0"
    fi
自定义key
UserParameter=slave.status,sh /etc/zabbix/slave.sh
修改密码:update user set password=password('123') where user='root' and host='localhost'; 
创建用户并授权:create user readonly@'IP' identified by '密码';
grant select on *.* to readonly@'IP' identified by '密码';  

  

  

转载于:https://www.cnblogs.com/The-day-of-the-wind/p/10094575.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值