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

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