获取主从复制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 '密码';