這兩個簡單的腳本是用來檢測管理節點和數據節點掛掉的時候能被MySQL集群拉進去。
由於MySQL集群只能把壞掉的節點踢出去,如果網絡端掉或者其他情況。他不能自給拉回來。
1、管理節點的腳本
#!/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@localhost TM]# crontab -l
*/1 * * * * /usr/local/scripts/mgmd_check_online.sh
日志內容:
!-------MGMD is ok-------------!
Check date:2007-12-20 16:52:51
!-------MGMD is dead ----------!
!-------MGMD NODE OK-----------!
2、數據節點的腳本
#!/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