nfsSetup.sh 2.98 KB
# 作者: 石晓旭
# 描述:安装nfs
# 步骤:1、安装 2、实现自动挂在, 3、直接命令挂在。
#!/bin/bash

echo "[`date`] [DEBUG] ############################# nfsSetup.sh begin ##########################" >> ${ucswitchSetupLogFile}
#创建挂在点目录
if [ ! -d ${nfsServerDirectory} ];then
	mkdir -p ${nfsServerDirectory}
	if [ $? -eq 0 ];then
		echo "[`date`] [DEBUG] nfsSetup.sh create ${nfsServerDirectory}" >> ${ucswitchSetupLogFile}
	else
		echo "[`date`] [ERROR] nfsSetup.sh Failed to create ${nfsServerDirectory}" >> ${ucswitchSetupLogFile}
		exit 1
	fi
else
	echo "[`date`] [DEBUG] nfsSetup.sh ${nfsServerDirectory} already exists" >> ${ucswitchSetupLogFile}
fi
#安装nfs软件
bNfsUtilsNotInstall=`rpm -qa nfs-utils | grep nfs-utils | wc -l`
if [ ${bNfsUtilsNotInstall} -eq 0 ];then
	yum install -y nfs-utils
	if [ $? -ne 0 ];then
		echo "[`date`] [ERROR] nfsSetup.sh Failed to install nfs-utils" >> ${ucswitchSetupLogFile}
		exit 1
	else
		echo "[`date`] [DEBUG] nfsSetup.sh install nfs-utils success" >> ${ucswitchSetupLogFile}
	fi
else
	echo "[`date`] [DEBUG] nfsSetup.sh install nfs-utils already exists" >> ${ucswitchSetupLogFile}
fi
bRpcBindNotInstall=`rpm -qa rpcbind | grep rpcbind | wc -l`
if [ ${bRpcBindNotInstall} -eq 0 ];then
	yum install -y rpcbind
	if [ $? -ne 0 ];then
		echo "[`date`] [ERROR] nfsSetup.sh Failed to install rpcbind" >> ${ucswitchSetupLogFile}
		exit 1
	else
		echo "[`date`] [DEBUG] nfsSetup.sh install rpcbind success" >> ${ucswitchSetupLogFile}
	fi
else
	echo "[`date`] [DEBUG] nfsSetup.sh install rpcbind already exists" >> ${ucswitchSetupLogFile}
fi
#启动rpcbind
/etc/init.d/rpcbind start
if [ $? -ne 0 ];then
	echo "[`date`] [ERROR] nfsSetup.sh Failed to start rpcbind" >> ${ucswitchSetupLogFile}
	exit 1
else
	echo "[`date`] [DEBUG] nfsSetup.sh start rpcbind success" >> ${ucswitchSetupLogFile}
fi
#开始挂载
bNotMount=`df -h | grep $nfsServerDirectory | wc -l`
if [ ${bNotMount} -eq 0 ];then
	/bin/mount -t "${nfsType}" -o "${nfsOptions},rsize=${nfsReadSize},wsize=${nfsWriteSize}" "${nfsDevice}" "${nfsServerDirectory}"
	if [ $? -eq 0 ];then
		echo "[`date`] [DEBUG] nfsSetup.sh mount ${nfsServerDirectory} success" >> ${ucswitchSetupLogFile}
	else
		echo "[`date`] [ERROR] nfsSetup.sh Failed to mount ${nfsServerDirectory}" >> ${ucswitchSetupLogFile}
		exit 1
	fi
else
	echo "[`date`] [DEBUG] nfsSetup.sh ${nfsServerDirectory} already mount" >> ${ucswitchSetupLogFile}
fi
#自动挂载
bNotAutoMount=`cat /etc/rc.local | grep $nfsServerDirectory | wc -l`
if [ ${bNotMount} -eq 0 ];then
	echo "/bin/mount -t ${nfsType} -o ${nfsOptions},rsize=${nfsReadSize},wsize=${nfsWriteSize} ${nfsDevice} ${nfsServerDirectory}" >> /etc/rc.local
	echo "[`date`] [DEBUG] nfsSetup.sh ${nfsServerDirectory} autoMount success" >> ${ucswitchSetupLogFile}
else
	echo "[`date`] [DEBUG] nfsSetup.sh ${nfsServerDirectory} already autoMount" >> ${ucswitchSetupLogFile}
fi
echo "[`date`] [DEBUG] #############################  nfsSetup.sh end  ##########################" >> ${ucswitchSetupLogFile}