部署nfs服务

nfs(Network File System),通过网络,让不同的机器、不同的操作系统可以共享彼此的文件。

Server端

安装

sudo yum -y install nfs-utils

如果要监听在固定端口

sudo vi /etc/sysconfig/nfs

加入内容

LOCKD_TCPPORT=30001 #TCP锁使用端口
LOCKD_UDPPORT=30002 #UDP锁使用端口
MOUNTD_PORT=30003 #挂载使用端口
STATD_PORT=30004 #状态使用端口

启动/重启服务

sudo systemctl restart rpcbind.service
sudo systemctl restart nfs-server.service

设置开机启动

sudo systemctl enable rpcbind.service
sudo systemctl enable nfs-server.service

编辑共享目录

sudo vi /etc/exports

共享/home/txl/test文件夹,允许172.23.73内网地址挂载

/home/txl/test    172.23.73.0/24(rw,async)

image

root_squash(默认):将来访的root用户映射为匿名用户或用户组;
no_root_squash:来访的root用户保持root帐号权限 ;
no_all_squash(默认):访问用户先与本机用户匹配,匹配失败后再映射为匿名用户或用户组;
all_squash:将来访的所有用户映射为匿名用户或用户组;
secure(默认):限制客户端只能从小于1024的tcp/ip端口连接服务器;insecure:允许客户端从大于1024的tcp/ip端口连接服务器;
anonuid:匿名用户的UID值,通常是nobody或nfsnobody,可以在此处自行设定;
anongid:匿名用户的GID值;
no_subtree_check:如果NFS输出的是一个子目录,则无需检查其父目录的权限(可以提高效率)

然后重新加载配置或者重启服务

sudo exportfs -a
sudo systemctl restart nfs-server.service

查看挂载

showmount -e localhost

image

Client端

安装

sudo yum -y install nfs-utils

查看Server端共享的目标文件夹

showmount -e 172.23.73.187

挂载

mount -t nfs 172.23.73.187:/home/txl/test   /home/txl/test

查看挂载

df -h

image

卸载

umount /home/txl/test
posted @ 2021-11-22 15:12  Azure沫  阅读(54)  评论(0编辑  收藏  举报