挂载文件至网络,可以通过本地挂载实现修改与同步
服务端 安装nfs-utils
yum install nfs-utils -y编辑文件/etc/exports
/mnt 172.25.254.0/24(ro,async)参数
sync 实时同步(内存) async 不实时同步(内存)查看配置结果
exportfs -rv开启服务,关闭防火墙
systemctl stop firewalld systemctl start nfs-server客户端 查看可挂载文件系统
showmount -e 172.25.254.141(Server IP)挂载
mount 172.25.254.141:/mnt /mnt测试 Server端创建文件file Client端发现file文件 Server端写入Hello World内容 Client端查看到内容
编辑/etc/exports文件,赋予rw权限,在客户端进行测试,由于受本地文件系统限制,创建文件失败
/mnt 172.25.254.0/24(rw,async)服务器端开放文件夹权限,再次尝试创建文件,创建成功,默认为nfsnobody用户 修改配置文件,使得默认uid和gid为1002,进行测试
/mnt 172.25.254.0/24(rw,async,anonuid=1002,anongid=1002)创建文件file1 修改配置文件/etc/exports,添加no_root_squash权限,使得用户和组跟随创建用户
/mnt 172.25.254.0/24(rw,async,anonuid=1002,anongid=1002,no_root_squash)修改配置文件/etc/exports,添加all_squash权限,使得用户和组跟随指定用户
/mnt 172.25.254.0/24(rw,async,anonuid=1002,anongid=1002,no_root_squash,all_squash)
客户端安装autofs服务
yum install autofs配置文件位置
7.0版本 /etc/sysconfig/autofs 7.1版本及以后 /etc/autofs.conf启动服务
systemctl start autofs查看,发现生成新的文件夹/net 进入文件夹,同时指定服务器端IP,发现服务端共享目录
cd /net/ServerIP进入该目录,查看共享文件 此时,发现目录被挂载 五分钟(默认挂载时间,可修改)后,发现被卸载
修改配置文件/etc/auto.master,添加
/mnt /etc/auto.nfs编辑配置文件/etc/auto.nfs,指定目录以及被挂载参数
octopus -ro,vers=3 172.25.254.100:/mnt重启服务,查看结果
systemctl restart autofs编辑配置文件/etc/auto.nfs,指定目录名挂载跟随被挂载目录名
* -ro,vers=3 172.25.254.141:/mnt/&服务端创建octopus{1…2}目录 客户端重启服务,进入octopus1目录成功,进入octopus3目录失败