搭建NFS

阅读量: searchstar 2024-12-13 15:12:49
Categories: Tags:

宿主机

sudo apt install nfs-kernel-server

假设要把$server_dir暴露给NFS的client,那么要把它的owner变成nobody,group变成nogroup

sudo mkdir -p $server_dir
sudo chown nobody:nogroup $server_dir

/etc/exports:

$server_dir    client_ip(rw,sync,no_subtree_check,all_squash)

文档:man exports

client_ip可以是单个IP,也可以是CIDR:https://askubuntu.com/a/998736

all_squash
       Map all uids and gids to the anonymous user. Useful for NFS-exported public FTP  directories,  news
       spool directories, etc. The opposite option is no_all_squash, which is the default setting.
sudo systemctl reload nfs-kernel-server

如果有防火墙的话需要对client_ip放开2049端口。

客户端

sudo apt install nfs-common

假设要把宿主机上的$server_dir mount到$mount_dir上:

sudo mkdir -p $mount_dir
sudo mount host_ip:$server_dir $mount_dir

如果需要开机自动mount,在/etc/fstab里加入:

host_ip:$server_dir	$mount_dir	nfs4	defaults,nofail	0	0

存在的问题:

参考文献

https://www.digitalocean.com/community/tutorials/how-to-set-up-an-nfs-mount-on-ubuntu-20-04