NFS export
Mount it to freshly created directory. Add to fstab for automatic mount during boot process.
Preparations:
sudo su
dnf install \
nfs-utils
Configure
vi /etc/idmapd.conf
[General]
Verbosity = 0
Domain = (domain)
systemctl restart rpcbind
Allow network connectivity:
For Redhat family:
firewall-cmd --list-all
firewall-cmd --permanent --add-service=nfs
success
firewall-cmd --permanent --add-service=rpc-bind
success
firewall-cmd --permanent --add-service=mountd
success
firewall-cmd --permanent --reload
firewall-cmd --list-all
For Debian family:
ufw status
ufw allow nfs
ufw allow rpcbind
ufw allow mountd
ufw enable
hostname -s
export host="$(hostname -s)"
Decide which declaration will be used: FQDN or IP address (depending on purpose).
export src_host="(source host)"
ping ${src_host}
showmount -e ${src_host}
Verify that needed export is listed in the output and set a variable:
export src_export="(name of exported directory)"
Create local directory where a NFS export will be mounted. Naming used here comes from the name of attached disk to the VM (usually). To clarify, that it is a data disk, -data
suffix is added.
export dir="/mnt/${host}-data/"
mkdir -p ${dir}
Before mounting the export, check where target directory is mounted, it should be mounted on the root /
and it should be empty.
df -h ${dir}
ls -la ${dir}
Finally, check variables and mount the export.
echo ${src_host}
echo ${src_export}
echo ${dir}
mount ${src_host}:${src_export} ${dir}
mount | grep ${src_host}
Check again
df -h ${dir}
ls -la ${dir}
Mounting source should be presented as IP address and exported path and it should be mounted in the correct destination. For example:
[root@host mnt]# df -h ${dir}
Filesystem Size Used Avail Use% Mounted on
10.xxx.x.xx:/aaa/data/bbb/ccc 1.0T 0 1.0T 0% /mnt/host-data
#TODO: add into /fstab with oneliner
```bash
cat /etc/fstab
cat <<EOF >> /etc/fstab
${src_host}:${src_export} ${dir} nfs defaults 0 0
EOF
cat /etc/fstab
systemctl daemon-reload
Umount and check automatic mounts, simulating restart.
mount | grep ${src_host}
umount ${dir}
mount | grep ${src_host}
mount -aF
mount | grep ${src_host}
df -h ${dir}
Try to write to the destination
touch ${dir}/test.md
Let's create an application directory. In my case, I use /data/ncp/
as structure for an application "NextCloud Production". Be consistent in directory structure: /data/
- for data, /home/
for users' home directories and similar across the infrastructure.
mkdir -p ${dir}/data/ncp/
df -h ${dir}/data/ncp/
when possible, test VM restart to ensure disk will be properly mounted
shutdown -r now
No Comments