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

相关文章

Redis 热 key 和大 key 问题小结

《Redis热key和大key问题小结》:本文主要介绍Redis热key和大key问题小结,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录一、什么是 Redis 热 key?热 key(Hot Key)定义: 热 key 常见表现:热 key 的风险:二、

SpringBoot整合OpenFeign的完整指南

《SpringBoot整合OpenFeign的完整指南》OpenFeign是由Netflix开发的一个声明式Web服务客户端,它使得编写HTTP客户端变得更加简单,本文为大家介绍了SpringBoot... 目录什么是OpenFeign环境准备创建 Spring Boot 项目添加依赖启用 OpenFeig

IntelliJ IDEA 中配置 Spring MVC 环境的详细步骤及问题解决

《IntelliJIDEA中配置SpringMVC环境的详细步骤及问题解决》:本文主要介绍IntelliJIDEA中配置SpringMVC环境的详细步骤及问题解决,本文分步骤结合实例给大... 目录步骤 1:创建 Maven Web 项目步骤 2:添加 Spring MVC 依赖1、保存后执行2、将新的依赖

Spring 中的循环引用问题解决方法

《Spring中的循环引用问题解决方法》:本文主要介绍Spring中的循环引用问题解决方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录什么是循环引用?循环依赖三级缓存解决循环依赖二级缓存三级缓存本章来聊聊Spring 中的循环引用问题该如何解决。这里聊

Spring Boot中JSON数值溢出问题从报错到优雅解决办法

《SpringBoot中JSON数值溢出问题从报错到优雅解决办法》:本文主要介绍SpringBoot中JSON数值溢出问题从报错到优雅的解决办法,通过修改字段类型为Long、添加全局异常处理和... 目录一、问题背景:为什么我的接口突然报错了?二、为什么会发生这个错误?1. Java 数据类型的“容量”限制

Python的time模块一些常用功能(各种与时间相关的函数)

《Python的time模块一些常用功能(各种与时间相关的函数)》Python的time模块提供了各种与时间相关的函数,包括获取当前时间、处理时间间隔、执行时间测量等,:本文主要介绍Python的... 目录1. 获取当前时间2. 时间格式化3. 延时执行4. 时间戳运算5. 计算代码执行时间6. 转换为指

SpringBoot基于配置实现短信服务策略的动态切换

《SpringBoot基于配置实现短信服务策略的动态切换》这篇文章主要为大家详细介绍了SpringBoot在接入多个短信服务商(如阿里云、腾讯云、华为云)后,如何根据配置或环境切换使用不同的服务商,需... 目录目标功能示例配置(application.yml)配置类绑定短信发送策略接口示例:阿里云 & 腾

关于MongoDB图片URL存储异常问题以及解决

《关于MongoDB图片URL存储异常问题以及解决》:本文主要介绍关于MongoDB图片URL存储异常问题以及解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录MongoDB图片URL存储异常问题项目场景问题描述原因分析解决方案预防措施js总结MongoDB图

SpringBoot项目中报错The field screenShot exceeds its maximum permitted size of 1048576 bytes.的问题及解决

《SpringBoot项目中报错ThefieldscreenShotexceedsitsmaximumpermittedsizeof1048576bytes.的问题及解决》这篇文章... 目录项目场景问题描述原因分析解决方案总结项目场景javascript提示:项目相关背景:项目场景:基于Spring

解决Maven项目idea找不到本地仓库jar包问题以及使用mvn install:install-file

《解决Maven项目idea找不到本地仓库jar包问题以及使用mvninstall:install-file》:本文主要介绍解决Maven项目idea找不到本地仓库jar包问题以及使用mvnin... 目录Maven项目idea找不到本地仓库jar包以及使用mvn install:install-file基