1. what is nfs used for?
nfs is network file system, it is used when multiple computers need to access one directory.
2. Computer Environment
OS: Ubuntu 20.04
3. Install and config nfs server
3.1. Install nfs server
#执行以下命令安装NFS服务器,
#apt会自动安装nfs-common、rpcbind等13个软件包
sudo apt install nfs-kernel-server
3.2 create directory to share
# create directory /home/maye/nfs to share on nfs server host
# Attention: It's better to create directory to share under directory home, not under root directory,
# because It may have error: permission not allowed to read or write the directory,
# if under root directory.
sudo mkdir -p /home/maye/nfs
3.3 write config file to set exported directories.
sudo gedit /etc/exports
-->
#设置共享目录
/home/maye/nfs *(rw,sync,no_subtree_check,no_root_squash)```
Note:
* means any ip can mount this exported directory.
3.4 start nfs service
# before starting nds serivce, rpcbind service needs to be active.
# check status of rpcbind service
$ systemctl status rpcbind
# if rpcbind service not active, start it.
$ systemctl start rpcbind
$ systemctl start nfs-kernel-server
# see the export list for localhost
$ showmount -e
-->
Export list for maye-Inspiron-5547:
/home/maye/nfs *
4. Install and config nfs client
4.1 install nfs client
#在需要连接到NFS服务器的客户端机器上,
#需要执行以下命令,安装nfs-common软件包。
#apt会自动安装nfs-common、rpcbind等12个软件包
sudo apt install nfs-common
#显示指定的NFS服务器上export出来的目录
sudo showmount -e nfs-server-ip
4.2 create directory which the nfs server exported directory will mount to.
sudo mkdir -p /home/maye/mnt/nfs
4.3 mount shared directory
# on nfs client
# /home/maye/nfs is the directory exported on nfs server in this example,
# /home/maye/mnt/nfs is the directory on nfs server to which
# to mount the shared directory in this example,
# change them to the actual pathes in your case.
sudo mount -t nfs nfs-server-ip:/home/maye/nfs /home/maye/mnt/nfs
# check the mounted directory
$ sudo df -h
-->
nfs-server-ip:/home/maye/nfs 457G 182G 253G 42% /home/maye/mnt/nfs
5. stop nfs service
# on nfs server
$ sudo systemctl stop nfs-kernel-server
References:
https://zhuanlan.zhihu.com/p/606174368?utm_id=0