全部博文(389)
分类: LINUX
2015-01-17 22:38:31
IPVS的MySQL从库检测脚本
IPVS上对于不可用的MySQL的从库需要有主动检测的机制,当发现
从库不可用时,从IPVS的转发列表中删除对应的MySQL只读从库.
#!/bin/sh
#writen by Frank Zou
export PATH=/usr/bin:/usr/sbin:/sbin:/bin
USER=root
PWD=123456
MYSQL_PORT=3307
if [ -f /tmp/mysql_live ] ; then
echo "A instance has running,script exit now,Please checking"
exit;
else
touch /tmp/mysql_live
fi
iparry=("192.168.10.145" "192.168.10.150")
for (( i = 0; i < ${#iparry[@]}; ++i ));
do
ping_result=`mysqladmin -u ${USER} -p${PWD} --host=${iparry[i]} --port=${MYSQL_PORT} ping`
if [ "${ping_result}" != "mysqld is alive" ] ; then
ipvsadm -d -t 192.168.10.225:${MYSQL_PORT} -r ${iparry[i]}:${MYSQL_PORT}
fi
done
rm -fr /tmp/mysql_live