nfs 服务端和客户端的配置
10.14.40.151为例
nfs服务配置
服务端安装nfs
yum -y install nfs-utils
有需要的安装
yum -y install nfs-utils rpcbind
配置在服务端创建一个共享目录
mkdir -p /data1/nfsshare
chmod 666 /data1/nfsshare
修改 NFS 配置文件 /etc/exports
cat /etc/exports
/data1/nfsshare *(rw,sync,insecure,no_subtree_check,no_root_squash)
重载nfs
[root@test151 ~]
exporting *:/data1/nfsshare
启动rpc
systemctl start rpcbind
systemctl enable rpcbind
- 检查启动是否成功:rpcinfo -p localhost ,如果显示rpc 服务器注册的端口列表(端口:111),则启动成功
[root@test151 ~]
program vers proto port service
100000 4 tcp 111 portmapper
100000 3 tcp 111 portmapper
100000 2 tcp 111 portmapper
100000 4 udp 111 portmapper
100000 3 udp 111 portmapper
100000 2 udp 111 portmapper
systemctl start nfs
systemctl enable nfs
客户端的安装 10.14.40.124 为例
yum -y install nfs-utils
rpcinfo -p
[root@test124 node]
program vers proto port service
100000 4 tcp 111 portmapper
100000 3 tcp 111 portmapper
100000 2 tcp 111 portmapper
100000 4 udp 111 portmapper
100000 3 udp 111 portmapper
100000 2 udp 111 portmapper
showmount -e 10.14.40.151
[root@test124 node]
Export list for 10.14.40.151:
/data1/nfsshare *
rm -fr /data1/nfsshare;mkdir /data1/nfsshare
mount -t nfs 10.14.40.151:/data1/nfsshare /data1/nfsshare
整理完成的脚本
#!/bin/sh
function nfs_cli(){
nfsshare=$1
nfsip=$2
if [[ -z ${nfsshare} ]];then
echo "input nfsshare dir"
exit 1
fi
if [[ -z ${nfsip} ]];then
echo "input nfs server ip"
exit 2
fi
yum -y install nfs-utils
if [[ $? -ne 0 ]];then
echo "install nfs—utils failed"
exit 3
fi
rpcinfo -p
if [[ $? -ne 0 ]];then
echo "check rpc info failed"
exit 1
fi
showmount -e ${nfsip}
if [[ $? -ne 0 ]];then
echo "check remote nfs server failed"
exit 1
fi
rm -fr ${nfsshare}
mkdir ${nfsshare}
mount -t nfs ${nfsip}:${nfsshare} ${nfsshare}
if [[ $? -ne 0 ]];then
echo "mount remote nfs share dir failed"
exit 1;
fi
}
function nfs_server(){
nfsshare=$1
nfsip=$2
if [[ -z ${nfsshare} ]];then
echo "input nfsshare dir"
exit 1
fi
if [[ -z ${nfsip} ]];then
echo "input nfs server ip"
exit 2
fi
yum -y install nfs-utils
if [[ $? -ne 0 ]];then
echo "install nfs—utils failed"
exit 3
fi
rpcinfo -p
if [[ $? -ne 0 ]];then
echo "check rpc info failed"
exit 1
fi
mkdir ${nfsshare}
echo "${nfsshare} *(rw,sync,insecure,no_subtree_check,no_root_squash)" >/etc/exports
exportfs -rv
if [[ $? -ne 0 ]];then
echo "mount remote nfs share dir failed"
exit 1;
fi
systemctl start rpcbind
systemctl enable rpcbind
systemctl start nfs
systemctl enable nfs
}
function usage(){
echo "input param num 3"
echo "param1 nfs share dir"
echo "param2 nfs server ip info"
echo "param3 only support {cli|server}"
}
if [[ $# -ne 3 ]];then
usage;
exit
fi
nfsshare=$1
nfsip=$2
optional=$3
case "$3" in
cli)
echo "config nfs client info start ......"
nfs_cli ${nfsshare} ${nfsip}
;;
server)
echo "config nfs server info start ......"
nfs_server ${nfsshare} ${nfsip}
;;
*)
usage;
echo "Usage:$3 {cli|server}"
exit 1
esac