Linux 创建网络共享盘 NFS

参考 https://www.cnblogs.com/lixiuran/p/7117000.html 一步步部署就可以成功

一、安装 NFS 服务器所需的软件包:

yum install -y nfs-utils
二、编辑exports文件,添加从机

  
vim /etc/exports
/home/nfs/ 192.168.248.0/24(rw,sync,fsid=0)
同192.168.248.0/24一个网络号的主机可以挂载NFS服务器上的/home/nfs/目录到自己的文件系统中

rw表示可读写;sync表示同步写,fsid=0表示将/data找个目录包装成根目录

三、启动nfs服务

先为rpcbind和nfs做开机启动:(必须先启动rpcbind服务)

 
systemctl enable rpcbind.service
systemctl enable nfs-server.service
然后分别启动rpcbind和nfs服务:

 
systemctl start rpcbind.service
systemctl start nfs-server.service
确认NFS服务器启动成功:

 
rpcinfo -p  这个命令没看到效果
检查 NFS 服务器是否挂载我们想共享的目录 /home/nfs/:

exportfs -r
#使配置生效

exportfs
#可以查看到已经ok
/home/nfs 192.168.248.0/24

四、在从机上安装NFS 客户端

首先是安裝nfs,同上,然后启动rpcbind服务

先为rpcbind做开机启动:

systemctl enable rpcbind.service

然后启动rpcbind服务:

systemctl start rpcbind.service

注意:客户端不需要启动nfs服务

检查 NFS 服务器端是否有目录共享:showmount -e nfs服务器的IP

showmount -e 192.168.248.208
Export list for 192.168.248.208:
/home/nfs 192.168.248.0/24
在从机上使用 mount 挂载服务器端的目录/home/nfs到客户端某个目录下:


cd /home && mkdir nfs  原文写成 /nfs是不成功的
mount -t nfs 192.168.220.128:/home/nfs /home/nfs

df -h 查看是否挂载成功。

主机上 添加一个新目录  /var/lib/mysql

vi /etc/exports

/home/nfs/ *(rw,no_root_squash)
/var/lib/mysql *(rw,no_root_squash)
exportfs -r 使配置生效

从机上执行

cd /var/lib && mkdir mysql

mount -t nfs 192.168.220.128:/var/lib/mysql /var/lib/mysql

df -h 查看是否生效

在使用的过程中,换权限后, 遇到从机无法访问,报错 cannot access nfs: Stale file handle

这时先解绑,再绑定

umount -f nfs 

mount -t nfs 192.168.220.128:/home/nfs /home/nfs

http://blog.csdn.net/taiyang1987912/article/details/41696319

http://www.linuxidc.com/Linux/2015-05/117378.htm

猜你喜欢

转载自blog.csdn.net/gs80140/article/details/93199622