menu Chancel's blog
rss_feed
Chancel's blog
有善始者实繁,能克终者盖寡。

本地Ubuntu1804使用NFS挂载远程Linux服务器目录

作者:Chancel Yang, 创建:2022-06-10, 字数:1302, 已阅:97, 最后更新:2022-06-10

这篇文章更新于 684 天前,文中部分信息可能失效,请自行甄别无效内容。

NFS即Network File Server,网络文件系统

Network File System (NFS) is a distributed file system protocol originally developed by Sun Microsystems (Sun) in 1984,[1] allowing a user on a client computer to access files over a computer network much like local storage is accessed

现有服务器信息如下

  • IP:10.0.0.1
  • 目录:/mnt/sdb
  • 防火墙: ufw
  • 系统:Ubuntu1804

我们希望在挂载10.0.0.1上的/mnt/sdb目录到本地(Linux)下的/mnt/share

首先在10.0.0.1上安装NFS服务

Bash
sudo apt install nfs-kernel-server

使用vim /etc/exports配置允许使用NFS服务的来源IP信息,防止被第三方非法滥用(这里也可以允许全部来源,在防火墙中指定来源IP)

TEXT
# 允许单个IP访问
/mnt/sdb 192.168.1.1(rw,sync,no_root_squash)

# 允许单个网段访问
/mnt/sdb 192.168.1.*(rw,sync,no_root_squash)

# 允许任意IP访问
/mnt/sdb *(rw,sync,no_root_squash)

启动服务并允许开机自启

Bash
sudo systemctl restart nfs-kernel-server
sudo systemctl enable nfs-kernel-server

NFS使用默认端口2049,在防火墙中开放2049端口

Bash
# 允许所有来源IP访问2049(不安全)
sudo ufw allow 2049

# 仅允许指定来源IP访问2049
sudo ufw allow from 192.168.1.1 to any port 2049

到这里10.0.0.1的所有设置都完成了,接下来开始配置本地的NFS客户端

本地首先安装NFS客户端

Bash
sudo apt install nfs-common

挂载远程10.0.0.1的/mnt/sdb目录到本地/mnt/share中

Bash
sudo mount -t nfs 10.0.0.1:/mnt/sdb /mnt/share

查看/mnt/share目录,确认挂载成功,将挂载添加到开机自启中

sudo crontab -e

添加如下命令将挂载添加到开机自启中

Bash
@reboot /usr/bin/mount -t nfs 10.0.0.1:/mnt/sdb /mnt/share

[[replyMessage== null?"发表评论":"发表评论 @ " + replyMessage.m_author]]

account_circle
email
web_asset
textsms

评论列表([[messageResponse.total]])

还没有可以显示的留言...
[[messageItem.m_author]] [[messageItem.m_author]]
[[messageItem.create_time]]
[[getEnviron(messageItem.m_environ)]]
[[subMessage.m_author]] [[subMessage.m_author]] @ [[subMessage.parent_message.m_author]] [[subMessage.parent_message.m_author]]
[[subMessage.create_time]]
[[getEnviron(messageItem.m_environ)]]