Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

Hoofdstuk 15Naam in de cursus: Accessing Network-attached Storage

Mount network storage with NFS and autofs

NFS (Network File System) lets many Linux machines use folders of one file server as if they were local. You can mount a share by hand, at boot in /etc/fstab, or on demand with the automounter autofs — it mounts when somebody opens the folder and unmounts when nobody uses it.

  • 8 Lessen
  • 14 Commando's
  • 1 Labs

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

Vaardigheden in dit hoofdstuk

  • NFS-shares koppelen met de hand, in fstab en met autofs

15.1

Know NFS

The server exports folders. The client mounts them. RHEL uses NFSv4 (version 4.2) by default: one TCP port (2049), good security and locking.

server2 (NFS server)                     server1 (client)
/srv/nfs/shared  ── export ──►  network  ──► mount on /mnt/shared

On the client you need the package nfs-utils:

dnf install nfs-utils

Commando's in deze les

15.2

Find the exports of a server

List what a server shares. With NFSv4 you can also mount the root of the server and look around.

showmount -e server2
Export list for server2:
/srv/nfs/shared  192.168.122.0/24
/srv/nfs/home    192.168.122.0/24
mkdir -p /mnt/browse
mount server2:/ /mnt/browse
ls /mnt/browse/srv/nfs
home  shared
umount /mnt/browse

Notitie

showmount needs the old NFSv3 services on the server. If the server allows only NFSv4, showmount fails — mount server2:/ and look instead.

15.3

Mount a share by hand

mount SERVER:/PATH FOLDER mounts until the next reboot. Check the NFS version and options with nfsstat -m or findmnt.

mkdir -p /mnt/shared
mount -t nfs server2:/srv/nfs/shared /mnt/shared
mount -t nfs -o vers=4.2,rw,sync server2:/srv/nfs/shared /mnt/shared
findmnt /mnt/shared
TARGET      SOURCE                  FSTYPE OPTIONS
/mnt/shared server2:/srv/nfs/shared nfs4   rw,relatime,vers=4.2,rsize=262144,wsize=262144,hard,proto=tcp,...
nfsstat -m
umount /mnt/shared
OptionMeaning
rw / roRead-write / read-only
vers=4.2Force an NFS version
syncWrite at once (safer, slower)
hard (default)Retry forever when the server is gone — programs wait
softGive up after a time with an error (data risk on writes)
sec=krb5pKerberos login and encryption (needs a Kerberos setup)

15.4

Mount at boot with fstab

An fstab line with the type nfs mounts the share at every boot. _netdev tells systemd to wait for the network.

/etc/fstab
server2:/srv/nfs/shared  /mnt/shared  nfs  rw,sync,_netdev  0 0
systemctl daemon-reload
mount -a
df -h /mnt/shared

Let op

If the NFS server is down at boot, an fstab mount can make the boot slow. For shares that are not always needed, use autofs (next lesson) or add nofail.

15.5

Mount on demand with autofs

autofs watches a folder. When somebody opens a name in it, autofs mounts the share; after some minutes without use, it unmounts it.

dnf install autofs
vim /etc/auto.master.d/shares.autofs
vim /etc/auto.shares
systemctl enable --now autofs
ls /shares
ls /shares/work
findmnt /shares/work
/etc/auto.master.d/shares.autofs
/shares   /etc/auto.shares   --timeout=300
/etc/auto.shares
work     -rw,sync   server2:/srv/nfs/shared
public   -ro        server2:/srv/nfs/public
  • The master map (/etc/auto.master.d/*.autofs) says: the folder /shares is managed by the map /etc/auto.shares.
  • The map has one line per key: name, options, server:/path.
  • ls /shares is empty at first. ls /shares/work mounts it.

Onthoud

Do not create /shares/work yourself — autofs makes and removes it. /shares itself is created by autofs too.

15.6

Mount every home folder with a wildcard

With * and &, one line mounts the home folder of every user: * = any key, & = the same key in the path.

/etc/auto.master.d/home.autofs
/home/remote   /etc/auto.home
/etc/auto.home
*   -rw,sync   server2:/srv/nfs/home/&
systemctl reload autofs
ls /home/remote/anna
findmnt /home/remote/anna
TARGET            SOURCE                       FSTYPE OPTIONS
/home/remote/anna server2:/srv/nfs/home/anna   nfs4   rw,relatime,...

Examentip

"The home folders of the NFS users must be mounted on /home/remote/USER when used" = an autofs wildcard map. Test with one user name.

15.7

Use a direct map

A direct map mounts a share on an exact, full path (not inside a managed folder). The master map uses the key /-.

/etc/auto.master.d/direct.autofs
/-   /etc/auto.direct
/etc/auto.direct
/srv/reports   -ro   server2:/srv/nfs/reports
systemctl reload autofs
ls /srv/reports
Map typeMaster lineKey in the mapMounts on
Indirect/shares /etc/auto.shareswork/shares/work
Wildcard/home/remote /etc/auto.home* with &/home/remote/NAME
Direct/- /etc/auto.direct/srv/reports (full path)/srv/reports

15.8

Find NFS problems

Check the network, the server's export, and the client config — in this order.

ping -c1 server2
nc -zv server2 2049
showmount -e server2
journalctl -u autofs -n 20
automount -m | head -20
systemctl status autofs
ErrorLikely cause
access denied by serverThe client's address is not in the server's export list
No route to host / timeoutFirewall on the server: open the nfs service
Folder in /shares does not appearTypo in the map, or autofs not reloaded
Permission denied on filesUID of the user differs between client and server

More: the RHCSA NFS chapter.

Oefenen

Alle commando's in dit hoofdstuk