因squid對多核伺服器支援不夠理想,所以在每台freebsd伺服器上(4核)開啟了3個squid
平穩的執行了一段時間,有一天客服反映網頁無法開啟,然後就對每台squid伺服器進行檢查,發現有台伺服器其中的乙個squid程序死掉了,重新啟動該squid,一切正常,為了及時發現squid程序故障並重啟squid,特寫了以下指令碼
定時器,每過10分鐘檢查一次,無限迴圈
vi /root/restart_squid.sh
#!/bin/sh
while true
dosquid1_ip=`awk '/ifconfig_lo0_alias0/' /etc/rc.conf`
squid1num=`netstat -an | grep -c $squid1_ip`
if [ $squid1num -lt 10 ] ; then
/usr/local/etc/rc.d/squid1 start
/usr/local/etc/rc.d/squid1 restart
adddate=`date +%y-%m-%d`" "`date +%h:%m:%s`
echo "$adddate squid_1 started" >> /var/restart_squid.log
fisquid2_ip=`awk '/ifconfig_lo0_alias1/' /etc/rc.conf`
squid2num=`netstat -an | grep -c $squid2_ip`
if [ $squid2num -lt 10 ] ; then
/usr/local/etc/rc.d/squid2 start
/usr/local/etc/rc.d/squid2 restart
adddate=`date +%y-%m-%d`" "`date +%h:%m:%s`
echo "$adddate squid_2 started" >> /var/restart_squid.log
fisquid3_ip=`awk '/ifconfig_lo0_alias2/' /etc/rc.conf`
squid3num=`netstat -an | grep -c $squid3_ip`
if [ $squid3num -lt 10 ] ; then
/usr/local/etc/rc.d/squid3 start
/usr/local/etc/rc.d/squid3 restart
adddate=`date +%y-%m-%d`" "`date +%h:%m:%s`
echo "$adddate squid_3 started" >> /var/restart_squid.log
fisleep 10m
done
chmod +x /root/restart_squid.sh
/root/restart_squid.sh
也可以用計畫任務來實現
vi /root/restart_squid.sh
#!/bin/sh
squid1_ip=`awk '/ifconfig_lo0_alias0/' /etc/rc.conf`
squid1num=`netstat -an | grep -c $squid1_ip`
if [ $squid1num -lt 10 ] ; then
/usr/local/etc/rc.d/squid1 start
/usr/local/etc/rc.d/squid1 restart
adddate=`date +%y-%m-%d`" "`date +%h:%m:%s`
echo "$adddate squid_1 started" >> /var/restart_squid.log
fisquid2_ip=`awk '/ifconfig_lo0_alias1/' /etc/rc.conf`
squid2num=`netstat -an | grep -c $squid2_ip`
if [ $squid2num -lt 10 ] ; then
/usr/local/etc/rc.d/squid2 start
/usr/local/etc/rc.d/squid2 restart
adddate=`date +%y-%m-%d`" "`date +%h:%m:%s`
echo "$adddate squid_2 started" >> /var/restart_squid.log
fisquid3_ip=`awk '/ifconfig_lo0_alias2/' /etc/rc.conf`
squid3num=`netstat -an | grep -c $squid3_ip`
if [ $squid3num -lt 10 ] ; then
/usr/local/etc/rc.d/squid3 start
/usr/local/etc/rc.d/squid3 restart
adddate=`date +%y-%m-%d`" "`date +%h:%m:%s`
echo "$adddate squid_3 started" >> /var/restart_squid.log fi
chmod +x /root/restart_squid.sh
crontab -e
*/10 * * * * root /root/restart_squid.sh
監控服務執行指令碼
個人興趣愛好 bin bash data 2019 04 20 owner wei process nginx 此處為要監控的程序 start process nginx 此處為啟動程序方式 log file var log error.log 此處為重啟記錄 該指令碼實現一分鐘監控一次,如果服務掛...
Squid執行控制指令碼
指令碼如下 bin bash chkconfig 2345 90 25 config etc squid.conf pidfile usr local squid var run squid.pid description squid internet object cache.pid usr lo...
自動執行指令碼
乙個偶然的機會,發現了自動執行指令碼的東東,真是神奇啊,可以執行sql 控制台命令等。由於研究的時間有限,所以知之甚少 先和大家分享下,哈 dim consoleprocess as new system.diagnostics.process consoleprocess.startinfo.fi...