---
description: NFS Storage
---

# Chapter 9

## Deploying NFS server:

```
dnf install nfs-utils -y
mkdir -p /nfsdata /home/ldap/ldapuser{1..9}
```

Editing exports file to state which folders we are sharing as NFS:

```
vim /etc/exports

/nfsdata        *(rw,no_root_squash)
/home/ldap      *(rw,no_root_squash)
```

starting nfs server:

```
systemctl enable --now nfs-server
systemctl enable --now firewalld
```

enabling firewall:

```
for i in nfs mountd rpc-bind; do firewall-cmd --add-service $i --permanent; done
firewall-cmd --reload
firewall-cmd --list-all
```

verifying mounts:

```
showmount -e
```

## Mounting NFS share:

```
dnf install nfs-utils -y^C
mount nfsserver:/nfsdata /mnt

mount | tail -n 1 # OUTPUT BELOW:
nfsserver:/nfsdata on /mnt type nfs4 (rw,relatime,vers=4.2,rsize=1048576,wsize=1048576,
    namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.32.131,
    local_lock=none,addr=192.168.32.133)
```

## Mounting NFS with automount:

```
dnf install -y autofs
```

Creating auto file:

```
vim /etc/auto.master

# add this line:
/nfsdata    /etc/auto.nfsdata
```

Bundan sonra `/nfsdata` mountu ilə bağlı configlər hamısı `/etc/auto.nfsdata` üzərindən ediləcək.

```
# to view examples:
cat /etc/auto.misc

vim /etc/auto.nfsdata

# add these lines:

files    -rw    nfsserver:/nfsdata
# <directory>    <permissions>    <nfsserver-hostname>:<mountpoint>
```

enabling autofs service:

```
systemctl enable --now autofs
```

## Automounting home folders:

```
vim /etc/auto.master
# add this:
/homes    /etc/auto.homes
```

edit homes file:

```
vim /etc/auto.homes
# add this:
*    -rw    nfsserver:/home/ldap/&
```

restart the service:

```
systemctl restart autofs
```
