NFS 实现文件共享

💡 NFS 即网络文件系统,是一种使用于分布式文件系统的协议,NFS 功能是通过网络让不同的机器,不同的操作系统能够彼此分享各自的数据,让应用程序在客户端通过网络访问位于服务器磁盘中的数据,是在类Unix系统间实现磁盘文件共享的一种方法

应用场景

服务器A(server端)192.168.127.138
服务器B(clinet端) 192.168.127.139

两台服务器(服务器A、服务器B) 安装nfs

apt install -y nfs-kernel-server

两台服务器(服务器A、服务器B):创建共享目录 nfs

mkdir -p /usr/local/share/nfs

服务器A(server端) :修改配置文件

vim /etc/exports

服务器A(server端): 在exports文件中添加

/usr/local/share/nfs *(rw,sync,no_root_squash,no_subtree_check)

配置参数说明

NFS权限选项功能描述信息
ro以只读方式共享
rw以读写方式共享
sync同步写入磁盘
async异步写入磁盘
wdelay延迟写入操作
root_squash屏蔽远程root权限
no_root_squash不屏蔽远程root权限
all_squash屏蔽所有远程用户权限

服务器A、服务器B: 重启服务并设置开机自启

systemctl restart nfs-kernel-server.service && systemctl enable nfs-kernel-server.service 

服务器A、服务器B : 查看服务状态

systemctl status nfs-kernel-server.service

image.png

服务器B(client端): 查看服务器A(server端)的共享目录

showmount -e 192.168.127.138

image.png

服务器B(client端): 进行目录挂载

mount -t nfs 192.168.127.138:/usr/local/share/nfs /usr/local/share/nfs

服务器B(client): 查看磁盘挂载,看到一下挂载信息则成功

df -h

image.png

服务器A(server): 创建目录

cd /usr/local/share/nfs && mkdir tt

image.png

服务器B(client): 查看是否目录已经同步

cd /usr/local/share/nfs && ls

image.png

卸载挂载目录

umonut -f /usr/local/share/nfs

服务器B(client) : 设置开机自动挂载

vim /etc/rc.d/rc.local

# 在文件最下面添加
mount -t nfs 192.168.127.138:/usr/local/share/nfs /usr/local/share/nfs
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值