a616652325 发表于 2018-8-22 06:41:12

使用Shell脚本实现NFS挂载自动切换

#!/bin/sh  
. /etc/init.d/functions
  
. /etc/profile
  
#This script's function is to check master NFS status.And if master NFS server is down,it will switch to backup
  
#NFS server
  
#Author:yongzhen
  
#Date:2015-11-18
  
#Email:1041282946@qq.com
  
while true
  
do
  
      /usr/sbin/showmount -e 172.16.1.17 >/dev/null 2>&1
  
      if [ $? -ne 0 ]
  
      then
  
                /usr/bin/ssh 172.16.1.18 /bin/umount -lf /data >/dev/null 2>&1
  
                /usr/bin/ssh 172.16.1.20 /bin/chown -R nfsnobody.nfsnobody /data >/dev/null 2>&1
  
                /usr/bin/ssh 172.16.1.18 /bin/mount -t nfs 172.16.1.20:/data /data >/dev/null 2>&1
  
                /usr/bin/ssh 172.16.1.18 /application/nginx/sbin/nginx -s reload >/dev/null 2>&1
  
                echo "NFS Server is down!!! At $(date +%F_%H:%M:%S)">/home/yongzhen/warning/nfs_warning_$(date +%F).log
  
                curl_id=$(/usr/bin/curl -I -s -w %{http_code} -o /dev/null www.etiantian.org)
  
                if [ $curl_id -ne 200 ]
  
                then
  
                        echo "Switch to backup NFS server is Failed">>/home/yongzhen/warning/nfs_warning_$(date +%F).log
  
                else
  
                        echo "Switch to backup NFS server is Successful">>/home/yongzhen/warning/nfs_warning_$(date +%F).log
  
                fi
  
                mail -s "NFS Server Warning" 1041282946@qq.com
页: [1]
查看完整版本: 使用Shell脚本实现NFS挂载自动切换