1. NFS介绍
NFS:Network File System 网络文件系统,NFS 文件系统仅支持基于 IP 的用户访问控制,NFS 的客户端主要为Linux。
一般可以远程共享存储
2. 操作
实验环境准备两台机器
支持多节点同时挂载以及并发写入
服务端:nfs-server 192.168.246.160
客户端:web1 192.168.246.161
centos7(服务端和客户端都关闭防火墙和selinux内核防火墙)
#systemctl stop firewalld
#systemctl disable firewalld
#setenforce 0
服务端操作
NFS-server操作
[root@nfs-server ~]# yum -y install rpcbind #安装rpc协议的包
[root@nfs-server ~]# yum -y install nfs-utils #安装nfs服务。
启动服务
[root@nfs-server ~]# systemctl start nfs
[root@nfs-server ~]# systemctl start rpcbind
[root@nfs-server ~]# mkdir /nfs-dir #创建存储目录
[root@nfs-server ~]# echo "nfs-test" >> /nfs-dir/index.html #制作test文件
[root@nfs-server ~]# vim /etc/exports #编辑共享文件
/nfs-dir 192.168.246.0/24(rw,no_root_squash,sync)
[root@nfs-server ~]# systemctl restart nfs-server #重启服务。
[root@nfs-server ~]# systemctl enable nfs-server #制作开机启动
可选参数注释:
ro:只读
rw:读写
*:表示共享给所有网段。
sync:所有数据在请求时写入共享
root_squash: 对于使用分享目录的使用者如果是root用户,那么这个使用者的权限将被压缩成为匿名使用者,只读权限。
no_root_squash:使用分享目录的使用者,如果是 root 的话,那么对于这个分享的目录来说,他就具有 root 的权限。
客户端操作
[root@web1 ~]# yum -y install rpcbind
[root@web1 ~]# yum -y install nfs-utils
[root@web1 ~]# mkdir /qf #创建挂载点
[root@web1 ~]# mount -t nfs 192.168.246.160:/nfs-dir /qf #挂载
-t:指定文件系统类型
[root@web1 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 17G 1.1G 16G 7% /
tmpfs tmpfs 98M 0 98M 0% /run/user/0
192.168.246.160:/nfs-dir nfs4 17G 1.4G 16G 8% /qf
[root@web1 ~]# ls /qf
index.html
[root@web1 ~]# umount /qf #取消挂载
制作开机挂载
[root@client.qfedu.com ~]# vim /etc/fstab
192.168.246.160:/nfs-dir /qf defaults 0 0
# 192.168.241.149:/xa2401 /mnt nfs rw,nofail,bg 0 0
[root@client.qfedu.com ~]# mount -a
挂载后客户端/qf下面产生的数据会存储在服务端的nfs-dir中