NFS网络文件系统
一:定义
NFS是一种在网络上共享文件系统资源的协议
二:安装服务
[root@servera ~]# yum install rpcbind nfs-utils -y
nfs-utils,包含rpc.nfsd rpc.mount等程序,以及nfs协议支持
rpcbind,主要是portmapper(端口映射服务)
[root@servera ~]# systemctl enable --now rpcbind nfs-server.service 启动服务
三:服务端配置共享文件导出
[root@servera ~]# mkdir -p /nfs_test/pub 创建共享目录
[root@servera ~]# useradd -u 1006 -g 1006 nfstest 创建用户
[root@servera ~]# groupadd -g 1006 nfstest 添加组
[root@servera ~]# chown 1006.1006 /nfs_test/pub 修改属组和属主
[root@servera ~]# vi /etc/exports 添加导出记录
[root@servera ~]# exportfs -r 导出
[root@servera ~]# showmount -e localhost 查看导出
Export list for localhost:
/nfs_test/pub *
[root@servera ~]# firewall-cmd --add-service=mountd firewall中添加服务
success
[root@servera ~]# firewall-cmd --add-service=nfs
success
[root@servera ~]# firewall-cmd --add-service=rpc-bind
Success
Serberb:客户端
[root@serverb ~]# showmount -e 192.168.204.7 查看servera的导出记录
Export list for 192.168.204.7:
/nfs_test/pub *
[root@serverb ~]# mkdir nfsdata
[root@serverb ~]# mount -t nfs 192.168.204.7:/nfs_test/pub ./nfsdata/ 挂载到本地目录
四:测试
服务端:
[root@servera ~]# touch /nfs_test/pub/{a,b,c}
客户端:
[root@serverb nfsdata]# ls
a b c
五:自动挂载
[root@serverb nfsmount]# yum install autofs -y 安装挂载服务
[root@serverb nfsmount]# vi /etc/auto.master 配置自动挂载
[root@serverb nfsmount]# vi /etc/auto.nfs 配置自动挂载
[root@serverb nfsmount]# systemctl enable --now autofs
[root@serverb nfsmount]# cd /auto-mount/nfsmount/ 挂载
[root@serverb nfsmount]# df 查看挂载