在Debian系统上安装NFS服务

Linux · 2024-04-06

在Debian系统上安装NFS服务,你需要执行以下步骤:

安装NFS内核服务器

sudo apt update
sudo apt install nfs-kernel-server

创建共享目录

sudo mkdir -p /srv/nfs/share
sudo chown nobody:nogroup /srv/nfs/share

配置共享权限。编辑 /etc/exports 文件,并添加共享目录的配置。

sudo nano /etc/exports

添加以下行:(*代表不限制IP)

/data *(rw,sync,no_subtree_check)

替换 <*> 为客户端的IP地址,或使用通配符来允许多个客户端。

更新修改的配置
sudo exportfs -rav

启动NFS服务
sudo systemctl start nfs-kernel-server
--作为自启动项目
sudo systemctl enable nfs-kernel-server

使用showmount -e可查看当前NFS服务器的加载情况。

showmount -e

配置防火墙(如果需要)允许NFS通信

sudo ufw allow from <client_IP> to any port nfs
sudo ufw enable
sudo ufw status

替换 <client_IP> 为客户端的IP地址。

在客户端上,你需要安装NFS通用客户端:

sudo apt update
sudo apt install nfs-common

然后,你可以挂载服务器上的共享目录:

sudo mount <server_IP>:/srv/nfs/share /mnt

替换 <server_IP> 为NFS服务器的IP地址。

debian linux NFS服务