Blog

NFS 基于客户端-服务器架构,服务器端将指定的目录通过网络导出(export),客户端通过挂载(mount)这些共享目录,实现文件的读写操作。

使用NFS的优势包括:

  • 资源共享:多台机器可以访问同一个文件目录,方便数据集中管理和协作。
  • 透明访问:用户和应用程序无需关心文件的物理位置,访问体验与本地文件无异。
  • 简化管理:减少数据冗余,便于备份与维护。
  • 灵活性与可扩展性:支持多种访问权限和安全机制,适合不同规模的网络环境。

快速部署

1. 设置时区

sudo apt upgrade -y
sudo apt autoremove -y
sudo apt clean
sudo apt-get install ntpdate -y 
sudo ntpdate time.windows.com
sudo timedatectl set-timezone Asia/Shanghai

2. 安装nfs server服务器

sudo apt install nfs-kernel-server

《快速搭建NFS网络文件系统》文章正文配图 — STARBUCKET BLOG

3. 创建共享目录

sudo mkdir -p /data/nfs/shared
sudo chown nobody:nogroup /data/nfs/shared
sudo chmod 755 /data/nfs/shared
  • 为什么用 nobody:nogroup:是为了让目录权限更安全,防止权限问题,您可以根据需要调整权限。

4. 配置 NFS 导出目录

编辑 /etc/exports 文件,服务器网段根据实际情况修改

/data/nfs/shared  192.168.1.0/24(rw,sync,no_subtree_check)

说明:

  • /srv/nfs/shared 是共享目录
  • 192.168.1.0/24 表示允许这个网段的所有机器访问
  • 选项解释: rw:读写权限 sync:同步写入,保证数据安全 no_subtree_check:关闭子目录检查,提高性能

5. 应用配置 & 启动服务

sudo exportfs -ra
sudo systemctl restart nfs-kernel-server
sudo systemctl enable nfs-kernel-server
sudo systemctl status nfs-kernel-server

《快速搭建NFS网络文件系统》文章正文配图(配图 2)— STARBUCKET BLOG

Comments & discussion

The first comment in each thread opens a topic. Signed-in readers can keep the conversation going under that topic.

No comments yet. Sign in to start a topic.

Start a new topic

Sign in to start a topic or join the discussion.