重启fastdfs脚本,前端lvs

 

功能:
 
当前端tracker出现宕机、僵尸进程,以及网络丢包严重时,自动注销掉storage.conf里的tracker服务器IP列表,并重启storage进程。
 
写入crontab里,每5分钟执行一次脚本。
 
===============================================================================================
 
#!/bin/bash
 
. /root/.bash_profile
 
 
ip_tracker1=192.168.8.90
ip_tracker2=192.168.8.91
 
 
count1=`ping $ip_tracker1 -c 10 | grep 'received' |awk -F ',' '{print $2}' |awk '{print $1}'`
count2=`ping $ip_tracker2 -c 10 | grep 'received' |awk -F ',' '{print $2}' |awk '{print $1}'`
 
 
telnet $ip_tracker1 22122 | grep -w 'Connected' > /dev/null
 
#如果端口存活并且ping 10个包,保证有7个以上接收,代表正常。否则代表失败。
 
 
if [ $? = "0" ] && [ "$count1" -gt 7 ];then
echo "#########################################" > /root/running.log
date >> /root/running.log
echo "Tracker server $ip_tracker1 is OK." >> /root/running.log
else
sed -i "s/tracker_server=$ip_tracker1/##&/" /etc/fdfs/storage.conf
echo "#########################################" >> /root/running.log
date >> /root/running.log
echo "Tracker server $ip_tracker1 is Critical!" >> /root/running.log
fi
 
 
telnet $ip_tracker2 22122 | grep -w 'Connected' > /dev/null
 
 
if [ $? = "0" ] && [ "$count2" -gt 7 ];then
echo "#########################################" >> /root/running.log
date >> /root/running.log
echo "Tracker server $ip_tracker2 is OK!" >> /root/running.log
else
sed -i "s/tracker_server=$ip_tracker2/##&/" /etc/fdfs/storage.conf
echo "#########################################" >> /root/running.log
date >> /root/running.log
echo "Tracker server $ip_tracker2 is Critical!" >> /root/running.log
fi
 
#记录下运行日志,如果出现有故障tracker,自动重启storage进程。
#并注销掉crontab计划任务,避免重复执行重启storage进程。
 
 
grep "Critical" /root/running.log
 
 
if [ $? = "0" ];then
/etc/init.d/fdfs_storaged stop
sleep 3
/etc/init.d/fdfs_storaged start
sed -i '/restart/s/*\/5/##&/' /etc/crontab
fi
 

你可能感兴趣的:(fastDFS,重启)