Linux nfs服务搭建
系统镜像:CentOS-7-x86_64-Everything-2207-02.iso
虚拟机软件:VirtualBox 图形用户界面 版本 7.1.6 r167084 (Qt6.5.3)
主机名称:compute(192.168.43.20);controller(192.168.43.10)
流程:服务器和客户端挂载镜像文件 → 服务器和客户端安装功能软件 → 服务器和客户端关闭安全防护 → 客户端挂载
rw:允许读写。
no_root_squash ->来访的root用户保持root帐号权限;
no_all_squash(默认) ->访问用户先与本机用户匹配,匹配失败后再映射为匿名用户或用户组: nfsnobody;
sync:同步写入到内存与硬盘中。
anonuid ->匿名用户UID设置值,可自行设置,但必须在/etc/passwd中存在;在多台客户端共享一个nfs目录时,可通过此参数使得不同的客户端写入的数据保持相同的用户权限
anongid ->匿名用户组
rpcbind是一个RPC服务,用于将不同服务与对应的端口进行绑定,支持机器间的互操作
一、准备
操作机:compute controller
1.挂载镜像文件
开机后添加磁盘

mkdir /opt/packages
mount /dev/cdrom/ /opt/packages
2.配置repo文件
2.1备份
mv /etc/yum.repos.d/ /etc/yum.repos.d.bak
2.2配置
mkdir /etc/yum.repos.d/
echo [Local] >> /etc/yum.repos.d/Package-Local.repo
echo name=local >> /etc/yum.repos.d/Package-Local.repo
echo baseurl=file:///opt/packages >> /etc/yum.repos.d/Package-Local.repo
echo gpgcheck=0 >> /etc/yum.repos.d/Package-Local.repo
echo enable=1 >> /etc/yum.repos.d/Package-Local.repo
yum clean all
二、安装与配置
3.安装nfs和rpcbind
操作机:compute controller
yum -y install nfs-utils rpcbind4.配置共享文件夹
操作机:compute
mkdir -p /mnt/testecho '/mnt/test 192.168.43.0/24(rw,no_root_squash,no_all_squash,sync,anonuid=501,anongid=501)' >> /etc/exports
export -r
5.启动
操作机:compute controller
systemctl start rpcbind操作机:compute
systemctl start nfs三、挂载
4.关闭防火墙
操作机:compute controller
systemctl stop firewalld5.关闭selinux防火墙
操作机:compute
setenforce 06.查看可挂载项
操作机:compute controller
showmount -e 192.168.43.20[root@controller ~]# showmount -e 192.168.43.20
Export list for 192.168.43.20:
/mnt/test 192.168.43.0/24
[root@compute ~]# showmount -e 192.168.43.20
Export list for 192.168.43.20:
/mnt/test 192.168.43.0/24
7.挂载
操作机:controller
mount -t nfs 192.168.43.20:/mnt/test /mnt8.查看挂载信息
[root@controller ~]# df -h /mnt
文件系统 容量 已用 可用 已用% 挂载点
192.168.43.20:/mnt/test 46G 1.3G 45G 3% /mnt

浙公网安备 33010602011771号