nfsSetup.sh
2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# 作者: 石晓旭
# 描述:安装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}:/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 ########################## "