#!/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 mysql_test]# crontab -l */1 * * * * /home/mysql_test/mgmd_check_online.sh 传到另外一个管理节点,然后加入CRONTAB [root@localhost mysql_test]# scp mgmd_check_online.sh root@192.168.0.232:~ The authenticity of host '192.168.0.232 (192.168.0.232)' can't be established. RSA key fingerprint is 47:39:89:a7:f7:1a:fc:0a:6f:7a:4b:b5:91:28:48:e8. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.0.232' (RSA) to the list of known hosts. root@192.168.0.232's password: mgmd_check_online.sh 100% 680 0.7KB/s 00:00
日志内容: !-------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