这两个简单的脚本是用来检测管理节点和数据节点挂掉的时候能被MYSQL集群拉进去。
由于MYSQL集群只能把坏掉的节点踢出去,如果网络端掉或者其他情况。他不能自给拉回来。
1、管理节点的脚本
vi /var/lib/mysql-cluster/mgmd_check_online.sh
#!/bin/bash
#
# Short managment keep alive file.
#
# Created by david yeung 2007-12-20
#
# Filename: mgmd_check_online.sh.
#
# To determinate whether mgmd process is running or not.
#
ps afx | grep -w ndb_mgmd | grep -v grep 1>&/dev/null
if [ $? == 0 ]
then
echo "!-------MGMD is ok-------------!">>/var/log/mgmd-check-online.log
else
# NDBD is dead.
echo "Check date:`date '+%Y-%m-%d %H:%M:%S'`" | tee -a /var/log/mgmd-check-online.log
echo "!-------MGMD is dead ----------!" | tee -a /var/log/mgmd-check-online.log
# Run the managment node.
/usr/local/mysql/ndb_mgmd -f /etc/config.ini
echo "!-------MGMD NODE OK-----------!" | tee -a /var/log/mgmd-check-online.log
fi
exit 0
然后加入到crontab
[root@test5 mysql-cluster]#chmod +x mgmd_check_online.sh
[root@test5 mysql-cluster]#crontab -e
*/1 * * * * /var/lib/mysql-cluster/mgmd_check_online.sh
2、数据节点的脚本
/usr/local/mysql/data/mgmd_check_online.sh
#!/bin/bash
#
# Created by david yeung 2007-12-20.
#
# Short ndbd node keep alive file.
#
# Filename:ndbd_check_online.sh.
#
# To determinate whether ndbd process is running or not.
#
ps afx | grep -w ndbd | grep -v grep 1>& /dev/null
if [ $? == 0 ]
then
echo "!-------NDBD is ok-------------!" >> /var/log/ndbd-check-online.log
else
# NDBD is dead
echo "!-------NDBD is dead ----------!" | tee -a /var/log/ndbd-check-online.log
echo "Check date:`date '+%Y-%m-%d %H:%M:%S'`" | tee -a /var/log/ndbd-check-online.log
echo "!-------RESTART NDBD ----------!" | tee -a /var/log/ndbd-check-online.log
# The real command.
/usr/local/mysql/bin/ndbd
echo "!-------NDBD NODE OK-----------!" | tee -a /var/log/ndbd-check-online.log
fi
exit 0
然后加入到crontab
[root@Redhat51 data]# chmod +x /usr/local/mysql/data/mgmd_check_online.sh
[root@Redhat51 data]# crontab -e
*/1 * * * * /usr/local/mysql/data/mgmd_check_online.sh
日志内容:
[root@Redhat51 data]# cat /var/log/ndbd-check-online.log
root@Redhat51 data]#
!-------NDBD is ok-------------!
!-------NDBD is dead ----------!
Check date:2009-08-21 14:46:58
!-------RESTART NDBD ----------!
!-------NDBD NODE OK-----------!
传到另外一个数据节点,然后加入CRONTAB
[root@Redhat51 data]# scp ndbd_check_online.sh
Address 192.168.31.73 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
password:
ndbd_check_online.sh 100% 754 0.7KB/s 00:00
阅读(1127) | 评论(0) | 转发(0) |