平台:Ubuntu 18.04.6

# tftp 服务端搭建

# 安装

sudo apt update
sudo apt install tftpd-hpa

# 配置

sudo mkdir /home/user/tftp_share
sudo chmod -R 777 /home/user/tftp_share
sudo vim /etc/default/tftpd-hpa

更改 TFTP_DIRECTORY 字段,填写配置 tftp 服务共享的路径,eg:

TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/home/user/tftp_share"
TFTP_ADDRESS=":69"
TFTP_OPTIONS="-l -c -s"

# 启动服务

在加载完后,重启服务器:

sudo systemctl restart tftpd-hpa

查看服务启动状态:

sudo systemctl status tftpd-hpa

# 测试传输

如果本机没有安装 tftp 客户端,可以使用以下命令安装:

sudo apt update
sudo apt install tftp-hpa

然后连接 tftp 服务器,通过 get 和 put 读写文件:

tftp 127.0.0.1 #连接服务器
> get a.txt # 获取 a.txt
> put b.txt # 上传 b.txt
> q # 断开连接

# NFS 服务端搭建

# 安装

sudo apt update
sudo apt install nfs-kernel-server

# 配置

sudo mkdir /home/user/nfs_share
sudo chmod -R 777 /home/user/nfs_share
sudo vim /etc/exports

在最后一行添加自己的共享路径,如:

/home/user/nfs_share *(rw,sync,no_root_squash,no_subtree_check)

note:

/home/nfs_share 是 NFS 服务端的共享路径。

* 表示所有网段都可以访问(可以指定具体的 ip )。

参数说明
ro只读访问
rw读写访问
sync所有数据在请求时写入共享
asyncnfs 在写入数据前可以响应请求
securenfs 通过 1024 以下的安全 TCP/IP 端口发送
insecurenfs 通过 1024 以上的端口发送
wdelay如果多个用户要写入 nfs 目录,则归组写入(默认)
no_wdelay如果多个用户要写入 nfs 目录,则立即写入,当使用 async 时,无需此设置
hide在 nfs 共享目录中不共享其子目录
no_hide共享 nfs 目录的子目录
subtree_check如果共享 /usr/bin 之类的子目录时,强制 nfs 检查父目录的权限(默认)
no_subtree_check不检查父目录权限
all_squash共享文件的 UID 和 GID 映射匿名用户 anonymous,适合公用目录
no_all_squash保留共享文件的 UID 和 GID(默认)
root_squashroot 用户的所有请求映射成如 anonymous 用户一样的权限(默认)
no_root_squashroot 用户具有根目录的完全管理访问权限
anonuid=xxx指定 nfs 服务器 /etc/passwd 文件中匿名用户的 UID
anongid=xxx指定 nfs 服务器 /etc/passwd 文件中匿名用户的 GID

# 启动服务

在加载完后,重启服务器:

sudo systemctl restart nfs-kernel-server

查看服务启动状态:

sudo systemctl status nfs-kernel-server

# 测试挂载

如果本机没有安装 NFS 客户端,可以使用以下命令安装:

sudo apt update
sudo apt install nfs-common

然后执行本地挂载测试:

sudo mount -t nfs -o nolock localhost:/home/user/nfs_share /mnt

# 添加对 version 2 的支持

使用如下命令查看对 NFS 版本的支持:

sudo cat /proc/fs/nfsd/versions
-2 +3 +4 +4.1 +4.2

可以看出来 -2 说明目前是对 NFS 的 version 2 并不支持的,因此需要稍作修改才可完成兼容工作:

sudo vim /etc/default/nfs-kernel-server

通过修改 RPCNFSDCOUNTRPCMOUNTDOPTSRPCSVCGSSDOPTS 的字段得到:

# Number of servers to start up
RPCNFSDCOUNT="-V 2 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="-V 2 --manage-gids"
# 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="--nfs-version 2,3,4 --debug --syslog"

然后重启一下服务,再次查看版本支持:

sudo systemctl restart nfs-kernel-server
sudo cat /proc/fs/nfsd/versions
+2 +3 +4 +4.1 +4.2
更新于 阅读次数

请我喝[茶]~( ̄▽ ̄)~*

夏沫の浅雨 微信支付

微信支付

夏沫の浅雨 支付宝

支付宝