techne/nfs.org

132 lines
2.9 KiB
Org Mode
Raw Normal View History

2024-09-21 04:17:26 +02:00
#+title: NFS
#+setupfile: ../org-templates/page.org
** Setup NFS server on Debian
#+begin_src shell
sudo apt install -y nfs-kernel-server nfs-common
#+end_src
Configure NFSv4 in ~/etc/default/nfs-common~:
#+begin_src shell
NEED_STATD="no"
NEED_IDMAPD="yes"
#+end_src
Configure NFSv4 in ~/etc/default/nfs-kernel-server~. Disable NFSv2 and NFSv3.
#+begin_src shell
RPCNFSDOPTS="-N 2 -N 3"
RPCMOUNTDOPTS="--manage-gids -N 2 -N 3"
#+end_src
#+begin_src shell
sudo systemctl restart nfs-server
#+end_src
Configure FirewallD:
#+begin_src shell
sudo firewall-cmd --zone=public --permanent --add-service=nfs
sudo firewall-cmd --reload
#+end_src
Setup pseudo filesystem and exports:
#+begin_src shell
sudo mkdir /shared
sudo chown -R nobody:nogroup /shared
#+end_src
Add exported directory to ~/etc/exports~:
#+begin_src shell
/shared <ip address of client>(rw,no_root_squash,no_subtree_check,crossmnt,fsid=0)
#+end_src
Create the NFS table:
#+begin_src shell
sudo exportfs -a
#+end_src
** Setup NFS client on Debian
#+begin_src shell
sudo apt install -y nfs-common
#+end_src
Create shared directory:
#+begin_src shell
sudo mkdir -p /mnt/shared
#+end_src
Mount NFS exports:
#+begin_src shell
sudo mount.nfs4 <ip address of server>:/ /mnt/shared
#+end_src
#+begin_quote
Note that ~<server ip>:/~ is relative to the exported directory. So ~/mnt/shared~ on the client is ~/shared~ on the server. If you try to mount with ~mount -t nfs <server ip>:/shared /mnt/shared~ you will get a /no such file or directory/ error.
#+end_quote
~/etc/fstab~ entry:
#+begin_src shell
<ip address of server>:/ /mnt/shared nfs4 soft,intr,rsize=8192,wsize=8192
#+end_src
#+begin_src shell
sudo systemctl daemon-reload
sudo mount -av
#+end_src
** Setup NFS server on FreeBSD
Edit ~/etc/rc.conf~.
#+BEGIN_SRC shell
nfs_server_enable="YES"
nfs_server_flags="-u -t -n 4"
rpcbind_enable="YES"
mountd_flags="-r"
mountd_enable="YES"
#+END_SRC
Edit ~/etc/exports~.
#+BEGIN_SRC
/data1 -alldirs -mapall=user1 host1 host2 host3
/data2 -alldirs -maproot=user2 host2
#+END_SRC
Start the services.
#+BEGIN_SRC shell
sudo service rpcbind start
sudo service nfsd start
sudo service mountd start
#+END_SRC
After making changes to the exports file, you need to restart NFS for the changes to take effect:
#+BEGIN_SRC shell
kill -HUP `cat /var/run/mountd.pid`
#+END_SRC
** Setup NFS client on FreeBSD
Edit ~/etc/rc.conf~.
#+BEGIN_SRC shell
nfs_client_enable="YES"
nfs_client_flags="-n 4"
rpc_lockd_enable="YES"
rpc_statd_enable="YES"
#+END_SRC
** Mount NFS share on client with systemd
Create a file at ~/etc/systemd/system/mnt-backup.mount~.
#+BEGIN_SRC systemd
[Unit]
Description=borgbackup NFS share from FreeBSD
DefaultDependencies=no
Conflicts=umount.target
After=network-online.target remote-fs.target
Before=umount.target
[Mount]
What=10.0.0.119:/coffeeNAS/borgbackup/repositories
Where=/mnt/backup
Type=nfs
Options=defaults,vers=3
[Install]
WantedBy=multi-user.target
#+END_SRC