安装

1
sudo apt install nfs-common nfs-kernel-server

配置nfs服务

修改/etc/exports

1
vim /etc/exports

文件中增加以下内容

1
2
3
4
5
6
7
8
9
10
11
# /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)
#
/var/tci/netboot/root 192.168.8.0/24(rw,sync,no_root_squash,no_subtree_check)

重启服务

1
systemctl restart nfs-kernel-server

查看状态

1
systemctl status nfs-kernel-server
1
2
3
4
5
6
7
8
9
● nfs-server.service - NFS server and services
Loaded: loaded (/lib/systemd/system/nfs-server.service; enabled; vendor preset: enabled)
Active: active (exited) since Mon 2023-06-05 11:32:09 CST; 7s ago
Process: 93553 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
Process: 93554 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)
Main PID: 93554 (code=exited, status=0/SUCCESS)

6月 05 11:32:08 flame systemd[1]: Starting NFS server and services...
6月 05 11:32:09 flame systemd[1]: Finished NFS server and services.

本机或客户端测试

1
exportfs -r

查看

1
showmount -e 192.168.8.88
1
2
Export list for 192.168.8.88:
/var/tci/netboot/root 192.168.8.0/24

挂载测试

1
2
3
4
mkdir /mnt/tmp1
mkdir /mnt/tmp2
mount 192.168.8.88:/var/tci/netboot/ /mnt/tmp1
mount 192.168.8.88:/var/tci/netboot/root /mnt/tmp2

查看挂载目录

1
ls /mnt/tmp1
1
root
1
ls /mnt/tmp2
1
bin  boot  dev  etc  home  initrd.img  initrd.img.old  lib  lib32  lib64  libx32  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var  vmlinuz  vmlinuz.old