NFS 是Network File System的缩写,即网络文件系统。一种使用于分散式文件系统的协定,由Sun公司开发,于1984年向外公布。功能是通过网络让不同的机器、不同的操作系统能够彼此分享个别的数据,让应用程序在客户端通过网络访问位于服务器磁盘中的数据,是在类Unix系统间实现磁盘文件共享的一种方法。现介绍如何在CentOS 7中安装NFS
一、准备Linux机器两台,我的机器如下:
服务器端 192.168.199.180
客户端 192.168.199.110
二、服务器端安装NFS服务
安装NFS
yum -y install nfs-utils rpcbind
A、服务器端配置1、创建共享目录
# mkdir /usr/local/test
2、NFS文件配置
# vi /etc/exports
增加配置
/usr/local/test/ 192.168.199.110(rw,no_root_squash,no_all_squash,sync)
保存配置,使配置生效
# exportfs -r
3、启动NFS服务
service rpcbind start
service nfs start
B、客户端挂载
1、创建需要挂载的目录:
mkdir /usr/local/test
2、测试挂载:
[root@xjhlinuxpc opt]# showmount -e 192.168.199.180
Export list for 192.168.199.180:
/usr/local/test 192.168.199.110
如果不能访问关闭防火墙
systemctl stop firewalld.service#停止firewall
systemctl disable firewalld.service#禁止firewall开机启动
3、挂载
mount -t nfs 192.168.199.180:/usr/local/test /usr/local/test
三、其他
解除挂载
umount /usr/local/test
如果遇到:umount.nfs: /usr/local/test: device is busy
可以执行下面的命令
# umount -l /usr/local/test
设置服务开机自动启动NFS
chkconfig rpcbind on
chkconfig nfs-server on
客户端自启动挂载NFS文件系统
[root@homeserver test]# vi /etc/fstab
加入
192.168.199.180:/usr/local/test /usr/local/test nfs defaults 0 0