一、nfs文件系统简介
Network File System,网络文件系统,它允许网络中的计算机之间通过TCP/IP网络共享资源。
nfs-utils是支持nfs的软件
二、nfs的启用
yum install nfs-utils -y安装nfs软件 systemctl start nfs-server开启服务 systemctl enable nfs-server设置为开机启动 systemctl stop firewalld关闭火墙
测试
在客户端
showmount -e 172.25.254.109
Export list for 172.25.254.109:
三、配置共享
mkdir /nfsdir创建共享目录 vim /etc/exports 创建配置文件
本机目录 共享客户端(共享方式) /nfsdir *(sync) /nfsdir 172.25.254.109(rw,anonuid=1001,anongid=1001,no_root_squash) /nfsdir 172.25.254.109(rw,no_root_squash)
*:任意用户 172.25.254.0/24指定网段用户
rw:读写
ro:只读
anonuid:指定创建文件的uid
anongid:指定创建文件的gid
all_squash:所有用户都继承uid gid
no_root_squash:以当前用户作为创建文件的对象 exportfs -rv r:刷新 v:显示
挂载测试
mount 172.25.254.109:/nfsdir /mnt
cd /mnt
touch file
客户端显示
服务端显示
四、自动挂载
在客户端
默认挂载点
yum install autofs -y systemctl start autofs systemctl enable autofs cd /net cd 172.25.254.109 cd nfsdir/ df 自动挂载完成
vim /etc/sysconfig/autofs 编辑配置文件(默认300秒改成3秒)
systemctl restart autofs
cd 等待3秒
df 查看挂载发现自动解除
指定挂载点
vim /etc/auto.master /mnt(挂载点上级目录) /etc/auto.nfs vim /etc/auto.nfs westos(挂载位置自动创建) -ro,vers3.0(挂载参数) 172.25.254.109:/nfsdir(挂载设备) systemctl restart autofs cd /mnt/westos df 自动挂载完成 cd df 自动解除完成