ubuntu 20.04配置nfs服务

1.安装NFS服务软件包
sudo apt update
sudo apt install nfs-kernel-server
##安装客户端,非必要##
sudo apt install nfs-common
2.创建nfs的文件夹,修改权限
mkdir -p /home/lin/nfs
chmod 777 /home/lin/nfs
3.配置nfs目录
sudo vi /etc/exports
##在文件后面添加内容##
# /etc/exports: the access control list for filesystems which may be exported
#               to NFS clients.  See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes       hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4        gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes  gss/krb5i(rw,sync,no_subtree_check)
#
/home/lin/nfs *(rw,sync,no_subtree_check)
调用命令使其生效

sudo exportfs -ra

4.修改固定端口

使用rpcinfo来查看nfs服务中所使用的端口

rpcinfo -p localhost

nfs使用到的端口中,2049,111是固定的端口号,但是status,mountd,nolockmgr使用的是动态的端口,对于配置ufw不方便,所在把这把端口号修改为固定的,方便配置ufw。

A.修改/etc/default/nfs-common文件,配置status服务端口为4000
# Options for rpc.statd.
#   Should rpc.statd listen on a specific port? This is especially useful
#   when you have a port-based firewall. To use a fixed port, set this
#   this variable to a statd argument like: "--port 4000 --outgoing-port 4001".
#   For more information, see rpc.statd(8) or http://wiki.debian.org/SecuringNFS
STATDOPTS="--port 4000"
B.修改/etc/default/nfs-kernel-server文件,配置mountd服务端口为4001

由于板子端用的协议nfs协议比较老旧,需要在nfs服务配置v2,v3版本生效

在末端加上 

# Number of servers to start up
RPCNFSDCOUNT=8

# Runtime priority of server (see nice(1))
RPCNFSDPRIORITY=0

# Options for rpc.mountd.
# If you have a port-based firewall, you might want to set up
# a fixed port here using the --port option. For more information, 
# see rpc.mountd(8) or http://wiki.debian.org/SecuringNFS
# To disable NFSv4 on the server, specify '--no-nfs-version 4' here
RPCMOUNTDOPTS="--manage-gids -p 4001"

# Do you want to start the svcgssd daemon? It is only required for Kerberos
# exports. Valid alternatives are "yes" and "no"; the default is "no".
NEED_SVCGSSD=""

# Options for rpc.svcgssd.
RPCSVCGSSDOPTS=""

RPCNFSDOPTS="--nfs-version 2,3,4 --debug --syslog"

 

C.创建/etc/modprobe.d/options.conf文件,添加如下内容,配置nlockmgr端口为4002
options lockd nlm_udpport=4002 nlm_tcpport=4002

然后在/etc/modules文件中添加lockd,

# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
lockd

参考博文:https://blog.csdn.net/bryanwang_3099/article/details/114702374

5.设置防火墙放行规则

sudo ufw allow 111/tcp
sudo ufw allow 111/udp
sudo ufw allow 2049/tcp
sudo ufw allow 2049/udp
sudo ufw allow 4000/tcp
sudo ufw allow 4000/udp
sudo ufw allow 4001/tcp
sudo ufw allow 4001/udp
sudo ufw allow 4002/tcp
sudo ufw allow 4002/udp

6.设置nfs服务生效

sudo systemctl start nfs-kernel-server
sudo systemctl enable nfs-kernel-server

由于修改了固定端口号,需要重启一下ubuntu 

 

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
安装命令是什么?NFS服务器的配置文件在哪里? 回答: 在Ubuntu 20.04中安装NFS客户端的命令是: ``` sudo apt install nfs-common ``` 在安装NFS服务器端之前,需要执行以下步骤进行配置: 1. 创建共享目录: ``` sudo mkdir /nfs sudo chmod -R 777 /nfs sudo chown -R vinson:vinson /nfs/ ``` 2. 修改NFS服务器端的配置文件`/etc/exports`,允许任何网段的IP系统访问该NFS目录,添加如下内容: ``` /nfs *(rw,sync,no_root_squash) ``` 3. 启动NFS服务: ``` sudo /etc/init.d/nfs-kernel-server restart ``` 关于Ubuntu 20.04NFS服务配置文件的路径是`/etc/exports`。 要检查NFS服务器是否已经启动,可以使用以下命令: ``` sudo systemctl status nfs-server ``` 如果NFS服务器已经启动,将会显示"Active: active"的状态。123 #### 引用[.reference_title] - *1* *3* [Ubuntu 20.04配置NFS服务](https://blog.csdn.net/linux_hua130/article/details/124658170)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}} ] [.reference_item] - *2* [Ubuntu20.04搭建 NFS 服务](https://blog.csdn.net/baidu_33032485/article/details/114496376)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值