Ubuntu22.04 下 NFS 相关问题与完整配置(客户机 MacOS)

2023-12-18 11:40

本文主要是介绍Ubuntu22.04 下 NFS 相关问题与完整配置(客户机 MacOS),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!


categories: [Linux-Shell]
tags: Linux NFS

写在前面

最近折腾一下 NFS, 先白嫖一顿华子云的 1 个月服务器, 2C4G 感觉不错了, 但NFS 配置起来还是有点难度, 主要还是随机分配的端口配置方面比较恶心.

server环境:

  • 华为云 2C4G Ubuntu22.04

client环境:

  • MacOS M1 with brew

  • Archlinux qemu-x86_64

背景

NFS 可以理解为网络主机上的一种服务, 支持多端的存储, 并且没有架构的限制, 底层通过 RPC 完成通信, 具体就是通过 RPC 寻找Server, 然后将找到的 Server 传到 Client,

server 端配置

安装基本包

首先需要安装一下nfs-Server:

sudo apt install rpcbind
sudo apt install nfs-server
sudo apt install nfs-kernel-server #这个好像在安装 nfs-server 之后就已经作为依赖安装过了

开启指定服务: (开机启动)

sudo systemctl enable rpcbind nfs-server
sudo systemctl start rpcbind nfs-server #这步可选, 因为安装之后默认是开启的

新建文件夹: (需要共享的文件夹)

mkdir /home/user/nfs_data
# 这里用 /nfs 也可以, 不过权限要注意. 

配置文件

sudo vi /etc/exports
# 下面的内容写入: (注意*之后左括号之前不要加任何空格!!!)
/home/user/nfs_data  *(rw,async,insecure,no_subtree_check,all_squash,anonuid=0,anongid=0)

端口配置

接下来遇到一个坑点了, 网上找到的关于 Ubuntu18 或者 20 的更改端口的方法都不起作用, 后来发现原来是 Ubuntu22.04 的一个更新点:

Bug #1971096 “Cannot Specify Fixed Ports for mountd and statd” : Bugs : nfs-utils package : Ubuntu;

Network File System (NFS) | Ubuntu;

参考的第二行给出了最新的配置文档, 也就是具体需要更改的配置文件: /etc/nfs.conf

这里主要是设置三个静态端口:

[lockd]
port=40002[mountd]
# debug=0
manage-gids=y
# descriptors=0
port=40001[statd]
# debug=0
port=40000

其实主要就是搜索 port 对应的条目, 改之.

重启服务

然后划重点的来了!!! (当然事实就是重启解决一切问题, 不过作为服务器来说总重启对用户体验不太好)

这里又是一个坑.

需要明确的是重启的服务不只是 nfs 的, 还有 rpc 相关的, 这里文档也提到了, 只是我没注意…

For example, systemctl restart nfs-server.service will restart nfs-mountd, nfs-idmapd and rpc-svcgssd (if running). On the other hand, restarting nfs-utils.service will restart nfs-blkmap, rpc-gssd, rpc-statd and rpc-svcgssd.

Of course, each service can still be individually restarted with the usual systemctl restart <service>.

The nfs.systemd(7) manpage has more details on the several systemd units available with the NFS packages.

也就是说, status 改了之后需要重启的服务是rpc-utils!

sudo systemctl restart nfs-server
sudo systemctl restart rpc-utils

这样才算是完成了端口的指定了.

最后看一下设置的情况:

==> rpcinfo -pprogram vers proto   port  service100000    4   tcp    111  portmapper100000    3   tcp    111  portmapper100000    2   tcp    111  portmapper100000    4   udp    111  portmapper100000    3   udp    111  portmapper100000    2   udp    111  portmapper100005    1   udp  40001  mountd100005    1   tcp  40001  mountd100005    2   udp  40001  mountd100005    2   tcp  40001  mountd100005    3   udp  40001  mountd100005    3   tcp  40001  mountd100003    3   tcp   2049  nfs100003    4   tcp   2049  nfs100227    3   tcp   2049100021    1   udp  40002  nlockmgr100021    3   udp  40002  nlockmgr100021    4   udp  40002  nlockmgr100021    1   tcp  40002  nlockmgr100021    3   tcp  40002  nlockmgr100021    4   tcp  40002  nlockmgr100024    1   udp  40000  status100024    1   tcp  40000  status

华为云服务器开放的端口:

控制台界面-> 安全组->配置规则->入方向规则->添加规则

优先级 1 即可, 端口都开放的是 TCP, 这里就不开放 UDP了, 如果网速比较慢需要开一下.

  • 2049(这里 UDP 可以开一下, 因为是实际走连接的端口)
  • 111
  • 40000
  • 40001
  • 40002

查看状态

除了上面提到的rpcinfo, 还可以通过下面的一些命令查看连接状态

端口

1024 以下的端口号需要 sudo

 ==> sudo lsof -i:111
COMMAND PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
systemd   1 root   91u  IPv4   1847      0t0  TCP *:sunrpc (LISTEN)
systemd   1 root   93u  IPv4   1848      0t0  UDP *:sunrpc
systemd   1 root   96u  IPv6   1849      0t0  TCP *:sunrpc (LISTEN)
systemd   1 root   97u  IPv6   1850      0t0  UDP *:sunrpc
rpcbind 485 _rpc    4u  IPv4   1847      0t0  TCP *:sunrpc (LISTEN)
rpcbind 485 _rpc    5u  IPv4   1848      0t0  UDP *:sunrpc
rpcbind 485 _rpc    6u  IPv6   1849      0t0  TCP *:sunrpc (LISTEN)
rpcbind 485 _rpc    7u  IPv6   1850      0t0  UDP *:sunrpc

查看连接情况

 ==> showmount -a
All mount points on hecs:
ip:/home/user/nfs_data[Ubuntu] √  ~==> showmount -e
Export list for hecs:
/home/user/nfs_data *[Ubuntu] √  ~==> showmount -d
Directories on hecs:
/home/user/nfs_data[Ubuntu] √  ~==> showmount -d
--all          -a  -- list both hostname and mounted dir in host:dir format
--directories  -d  -- list only the directories mounted by some client
--exports      -e  -- show server export list
--help         -h  -- help
--no-headers       -- suppress descriptive headers from output
--version      -v  -- version

查看 rpc 连接情况

 ==> rpcinfo -m
PORTMAP (version 2) statistics
NULL    SET     UNSET   GETPORT DUMP    CALLIT
19      0/0     0/0     18/22   21      0/0PMAP_GETPORT call statistics
prog		vers	netid	  success	failure
status          1	tcp	  3           	0
mountd          3	tcp	  7           	0
nfs             3	tcp	  8           	0
status          1	udp	  0           	4RPCBIND (version 3) statistics
NULL    SET     UNSET   GETADDR DUMP    CALLIT  TIME    U2T     T2U
0       148/148 73/73   0/0     0       0/0     0       0       0RPCBIND (version 4) statistics
NULL    SET     UNSET   GETADDR DUMP    CALLIT  TIME    U2T     T2U
11      198/198 168/168 10/10   0       0/0     0       0       0
VERADDR INDRECT GETLIST GETSTAT
0       0       0       1RPCB_GETADDR (version 4) call statistics
prog		vers	netid	  success	failure
mountd          3	tcp	  10          	0

nfsstat

 ==> nfsstat -m #在 Client 端执行
/Volumes/nfs_data from ip:/home/user/nfs_data-- Original mount options:General mount flags: 0x0NFS parameters: deadtimeout=45File system locations:/home/user/nfs_data @ ip (ip)-- Current mount parameters:General mount flags: 0x4000018 nodev,nosuid,multilabelNFS parameters: vers=3,tcp,port=2049,nomntudp,hard,nointr,noresvport,negnamecache,callumnt,locks,quota,rsize=32768,wsize=32768,readahead=16,dsize=32768,rdirplus,nodumbtimer,timeo=10,maxgroups=16,acregmin=5,acregmax=60,acdirmin=5,acdirmax=60,deadtimeout=45,nomutejukebox,nonfc,sec=sysFile system locations:/home/user/nfs_data @ ip (ip)Status flags: 0x0

Server 端的一些选项:

==> nfsstat -l
nfs v3 server        total:      180
------------- ------------- --------
nfs v3 server         null:        8
nfs v3 server      getattr:       81
nfs v3 server       lookup:       22
nfs v3 server       access:       33
nfs v3 server         read:        1
nfs v3 server  readdirplus:        3
nfs v3 server       fsstat:       24
nfs v3 server       fsinfo:        4
nfs v3 server     pathconf:        4nfs v4 server        total:      130
------------- ------------- --------
nfs v4 server         null:        2
nfs v4 server     compound:      128nfs v4 servop        total:      401
------------- ------------- --------
nfs v4 servop       access:        9
nfs v4 servop        close:        1
nfs v4 servop      getattr:      104
nfs v4 servop        getfh:       15
nfs v4 servop       lookup:       14
nfs v4 servop         open:        1
nfs v4 servop        putfh:      113
nfs v4 servop    putrootfh:        4
nfs v4 servop      readdir:        4
nfs v4 servop       rename:        1
nfs v4 servop       savefh:        1
nfs v4 servop      setattr:        1
nfs v4 servop        write:        1
nfs v4 servop  exchange_id:        4
nfs v4 servop   create_ses:        2
nfs v4 servop  destroy_ses:        2
nfs v4 servop secinfononam:        2
nfs v4 servop     sequence:      118
nfs v4 servop destroy_clid:        2
nfs v4 servop reclaim_comp:        2

查看配置文件信息

 ==> sudo exportfs -v
/home/user/nfs_data<world>(async,wdelay,hide,no_subtree_check,anonuid=0,anongid=0,sec=sys,rw,insecure,root_squash,all_squash)

client 端配置

这里比较有讲究, MacOS需要开放全部的端口, 否则连接会失败, 但是 archLinux 不需要, 仅通过 2049 完成连接, 这也是 Linux 的魅力所在吧.

MacOS

不需要安装额外的软件, 甚至通过访达也能连接, 只需要通过⌘+K, 键入:

nfs://<公网IP>/home/user/nfs_data

在这里插入图片描述

或者终端:

sudo mount_nfs -o rw <公网IP>:/home/user/nfs_data ~/code/nfs
sudo umount ~/code/nfs #取消挂载, 取消挂载之前记得先返回上级目录

都是比较方便的, 通过:

rpcinfo -p <公网IP>

查看连接情况, 一般来说应该与 Server 端的端口开放情况保持一致的, 例如:

   program vers proto   port100000    4   tcp    111  rpcbind100000    3   tcp    111  rpcbind100000    2   tcp    111  rpcbind100000    4   udp    111  rpcbind100000    3   udp    111  rpcbind100000    2   udp    111  rpcbind100005    1   udp  40001  mountd100005    1   tcp  40001  mountd100005    2   udp  40001  mountd100005    2   tcp  40001  mountd100005    3   udp  40001  mountd100005    3   tcp  40001  mountd100003    3   tcp   2049  nfs100003    4   tcp   2049  nfs100227    3   tcp   2049  nfs_acl100021    1   udp  40002  nlockmgr100021    3   udp  40002  nlockmgr100021    4   udp  40002  nlockmgr100021    1   tcp  40002  nlockmgr100021    3   tcp  40002  nlockmgr100021    4   tcp  40002  nlockmgr100024    1   udp  40000  status100024    1   tcp  40000  status

archlinux

直接一行:

sudo mount -t nfs -o rw <公网IP>:/home/user/nfs_data ~/nfs
# 因为没读取系统级端口, 所以 sudo 不是必须的. 

这篇关于Ubuntu22.04 下 NFS 相关问题与完整配置(客户机 MacOS)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/508250

相关文章

gitlab安装及邮箱配置和常用使用方式

《gitlab安装及邮箱配置和常用使用方式》:本文主要介绍gitlab安装及邮箱配置和常用使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1.安装GitLab2.配置GitLab邮件服务3.GitLab的账号注册邮箱验证及其分组4.gitlab分支和标签的

MySQL MCP 服务器安装配置最佳实践

《MySQLMCP服务器安装配置最佳实践》本文介绍MySQLMCP服务器的安装配置方法,本文结合实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下... 目录mysql MCP 服务器安装配置指南简介功能特点安装方法数据库配置使用MCP Inspector进行调试开发指

苹果macOS 26 Tahoe主题功能大升级:可定制图标/高亮文本/文件夹颜色

《苹果macOS26Tahoe主题功能大升级:可定制图标/高亮文本/文件夹颜色》在整体系统设计方面,macOS26采用了全新的玻璃质感视觉风格,应用于Dock栏、应用图标以及桌面小部件等多个界面... 科技媒体 MACRumors 昨日(6 月 13 日)发布博文,报道称在 macOS 26 Tahoe 中

Redis Cluster模式配置

《RedisCluster模式配置》:本文主要介绍RedisCluster模式配置,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录分片 一、分片的本质与核心价值二、分片实现方案对比 ‌三、分片算法详解1. ‌范围分片(顺序分片)‌2. ‌哈希分片3. ‌虚

SpringBoot项目配置logback-spring.xml屏蔽特定路径的日志

《SpringBoot项目配置logback-spring.xml屏蔽特定路径的日志》在SpringBoot项目中,使用logback-spring.xml配置屏蔽特定路径的日志有两种常用方式,文中的... 目录方案一:基础配置(直接关闭目标路径日志)方案二:结合 Spring Profile 按环境屏蔽关

Maven 配置中的 <mirror>绕过 HTTP 阻断机制的方法

《Maven配置中的<mirror>绕过HTTP阻断机制的方法》:本文主要介绍Maven配置中的<mirror>绕过HTTP阻断机制的方法,本文给大家分享问题原因及解决方案,感兴趣的朋友一... 目录一、问题场景:升级 Maven 后构建失败二、解决方案:通过 <mirror> 配置覆盖默认行为1. 配置示

CSS3中的字体及相关属性详解

《CSS3中的字体及相关属性详解》:本文主要介绍了CSS3中的字体及相关属性,详细内容请阅读本文,希望能对你有所帮助... 字体网页字体的三个来源:用户机器上安装的字体,放心使用。保存在第三方网站上的字体,例如Typekit和Google,可以link标签链接到你的页面上。保存在你自己Web服务器上的字

Springboot3+将ID转为JSON字符串的详细配置方案

《Springboot3+将ID转为JSON字符串的详细配置方案》:本文主要介绍纯后端实现Long/BigIntegerID转为JSON字符串的详细配置方案,s基于SpringBoot3+和Spr... 目录1. 添加依赖2. 全局 Jackson 配置3. 精准控制(可选)4. OpenAPI (Spri

MySQL 设置AUTO_INCREMENT 无效的问题解决

《MySQL设置AUTO_INCREMENT无效的问题解决》本文主要介绍了MySQL设置AUTO_INCREMENT无效的问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参... 目录快速设置mysql的auto_increment参数一、修改 AUTO_INCREMENT 的值。

关于跨域无效的问题及解决(java后端方案)

《关于跨域无效的问题及解决(java后端方案)》:本文主要介绍关于跨域无效的问题及解决(java后端方案),具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录通用后端跨域方法1、@CrossOrigin 注解2、springboot2.0 实现WebMvcConfig