Linux Centos7 远程挂载网络磁盘/共享目录-NFS共享文件夹操作

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/bj_chengrong/article/details/90271418

服务端操作

【1】安装NFS程序

yum -y install nfs*

rpcbind,在centos6以前自带的yum源中为portmap。

使用yum安装nfs时会下载依赖,因此只要下载nfs即可,无需再下载rpcbind.


【2】查看是否安装了nfs与rpcbind

rpm -qa |grep nfs

rpm -qa |grep rpcbind


【3】创建共享的目录并共享

如要共享的目录已存在请跳过创建(也可以进行手动创建)

mkdir  /mnt/NFS/resource


然后编辑下面的文件:

vim /etc/exports

-- 把下面的加入到文件/etc/exports中

/mnt/NFS/resource  10.8.200.202/24(rw,no_root_squash,sync,no_wdelay)

/mnt/NFS/resource  10.8.200.205/24(rw,no_root_squash,sync,no_wdelay)

【4】启动nfs,rpcbind,并设为开机自启

(centos7)

systemctl start nfs

systemctl start rpcbind

systemctl enable nfs

systemctl enable rpcbind

(centos6)

service nfs start

service rpcbind start


【5】查看是否共享成功

showmount -e localhost

可看到共享的目录及客户端,即为成功

如果报下面错误,则需要把防火墙关闭

 ==========================================================================================

客户端操作

【1】安装NFS程序

yum -y install nfs*


【2】启动nfs

(centos7)

systemctl start nfs

systemctl start rpcbind

systemctl enable nfs

systemctl enable rpcbind

(centos6)

service nfs start

service rpcbind start

chkconfig nfs on

chkconfig rpcbind on


【3】创建挂载目录

mkdir /res_base/prd/


【4】查看是否共享成功

showmount -e nfs服务端IP(10.8.200.204 是NFS的服务器)

showmount -e 10.8.200.204    

10.8.200.202,10.8.200.205是远程访问共享服务器的客户端IP


【5】网络挂载

mount -t nfs -o nolock 服务端IP:共享目录绝对路径 本地挂载目录

mount -t nfs -o nolock 10.8.200.204:/mnt/NFS/resource/  /res_base/prd

开机自动挂载

vi /etc/fstab

# 新增一行

10.8.200.132:/mnt/NFS/resource/ /res_base/prd                    nfs4    defaults        0 0

centos7的nfs默认使用的是nfs4,所以mount -t 无需指定nfs4也可以


【6】查看是否成功

df -Th 

【7】卸载网络磁盘

与卸载本地挂载相同

umount /res_base/prd

umount 10.8.200.132:/mnt/NFS/resource   

猜你喜欢

转载自blog.csdn.net/bj_chengrong/article/details/90271418