All technological notes.
NFS (Network File System)NFS (Network File System)
Features
sudo dnf install nfs-utils
rpm -qa | grep nfs-utils
sudo systemctl enable --now nfs-server rpcbind
sudo systemctl status nfs-server
# Test Exported Directories:
showmount -e server_ip
Configuration Files: /etc/exports
Format
# share_dir client_ip (permissions)
/shared_directory 192.168.1.0/24(rw,sync,no_root_squash)
# share with everyone
/shared_directory *(rw,sync,no_root_squash)
| Permission | Desc |
|---|---|
rw |
Read-write access. |
sync |
Write changes to disk immediately. |
no_root_squash |
Allows root access from the client. |
/var/log/messages or /var/log/syslog| CMD | DESC |
|---|---|
exportfs -v |
List all exported directories |
sudo exportfs -r |
Apply the changes |
/etc/fstab
server_ip:/shared_dir /mount_point nfs defaults 0 0
/var/log/messages or /var/log/syslog| CMD | DESC |
|---|---|
sudo mount -t nfs server_ip:/shared_dir /mount_point |
Mount the NFS share |
sudo umount /mount_point |
Unmount a share |
yum install nfs-utils -y
rpm -qa | grep nfs
# nfs-utils-2.3.3-59.el8.x86_64
# libnfsidmap-2.3.3-59.el8.x86_64
# sssd-nfs-idmap-2.9.4-5.el8_10.1.x86_64
systemctl enable rpcbind
systemctl enable nfs-server
systemctl start rpcbind nfs-server rpc-statd nfs-idmapd
# create dedicated dir for sharing
mkdir /shared_data
chmod 755 /shared_data
# create resource
touch /shared_data/resource
echo "this is resource on server" > /shared_data/resource
# backup exports
cp /etc/exports /etc/exports.bak
vi /etc/exports
# /shared_data 192.168.1.0/24(rw,sync,no_root_squash)
exportfs -rv
# exporting 192.168.1.0/24:/shared_data
firewall-cmd --permanent --add-service nfs
firewall-cmd --reload
firewall-cmd --list-all
dnf install nfs-utils rpcbind -y
rpm -qa | grep nfs
# sssd-nfs-idmap-2.9.4-5.el8_10.1.x86_64
# nfs-utils-2.3.3-59.el8.x86_64
# libnfsidmap-2.3.3-59.el8.x86_64
systemctl enable rpcbind
systemctl start rpcbind
systemctl status rpcbind
ps -ef | egrep "firewall|iptable"
# stop firewall
systemctl stop firewalld
systemctl status firewalld
showmount -e 192.168.1.130
# Export list for 192.168.1.130:
# /shared_data 192.168.1.0/24
# create mount point
mkdir /mnt/app
mount 192.168.1.130:/shared_data /mnt/app
# verify
df -h
# Filesystem Size Used Avail Use% Mounted on
# devtmpfs 1.8G 0 1.8G 0% /dev
# tmpfs 1.8G 0 1.8G 0% /dev/shm
# tmpfs 1.8G 9.7M 1.8G 1% /run
# tmpfs 1.8G 0 1.8G 0% /sys/fs/cgroup
# /dev/mapper/rhel_rhelhost-root 26G 7.9G 19G 31% /
# /dev/nvme0n1p1 1014M 424M 591M 42% /boot
# tmpfs 364M 24K 364M 1% /run/user/1001
# 192.168.1.130:/shared_data 26G 7.5G 19G 29% /mnt/app
# access to resource
ll /mnt/app
# total 4
# -rw-r--r--. 1 root root 27 Dec 21 00:57 resource
cat /mnt/app/resource
# this is resource on server
# create dir and file
mkdir /mnt/app/client
echo "this is data from client" > /mnt/app/client/test
# verify on server
cat /shared_data/client/test
# this is data from client
umount /mnt/app
echo "192.168.1.130:/shared_data /mnt/app nfs _netdev 0 0"
AutoFSAuto File System (AutoFS)
AutoFS service automatically mounts a share upon detecting an activity in its mount point with a command such as ls or cd.To avoid inconsistencies, mounts managed with AutoFS should not be mounted or unmounted manually or via the /etc/fstab file.
maps
/etc/auto.master.dWith AutoFS, a share is unmounted automatically if it is not accessed for five minutes by default.
automount
/etc/autofs.conf
Sample:
[ autofs ]
timeout = 300
browse_mode = no
mount_nfs_default_protocol = 4
[amd]
dismount_interval = 300
master
/etc/auto.masterdirect
indirect
dnf install -y autofs
showmount -e 192.168.128.50
# Export list for 192.168.128.50:
# /home/guests/netuserX 192.168.128.0/24
# create mount point
mkdir /autodir
# add entry in master file
vi /etc/auto.master
/- /etc/auto.master.d/auto.dir
# create file and map mount point
vi etc/auto.master.d/auto.dir
/autodir 192.168.128.50:/home/guests/netuserX
# confirm autofs running
systemctl status autofs.service -l --no-pager
# confirm
ll /autodir
# total 4
# -rw-r--r--. 1 xanadu xanadu 22 Jan 31 14:21 testfile
# create mount point
mkdir /indirect
# edit misc file
vi /etc/auto.misc
autoindir 192.168.128.50:/home/guests/netuserX
# confirm
ll /misc/autoindir/
# total 4
# -rw-r--r--. 1 xanadu xanadu 22 Jan 31 14:21 testfile
netuserX with UID 3000/home/netuserX to the list of NFS shares.useradd -u 3000 netuserX
echo password | passwd --stdin netuserX
# add entry
echo "/home 192.168.128.0/24(rw)" >> /etc/exports
# export all share
exportfs -avr
# exporting 192.168.128.50:/home
# exporting 192.168.128.0/24:/home/guests/netuserX
netuserX with UID 3000 and no home dir./nfshome# create user
# -M: no home dir
# -b: specify base dir
useradd netuserX -u 3000 -Mb /nfshome
echo password | passwd --stdin netuserX
# create mount point
mkdir /nfshome
# add entry to master
echo "/nfshome /etc/auto.master.d/auto.home" >> /etc/auto.master
# create cf
echo "* -rw 192.168.128.50:/home/netuserX" > /etc/auto.master.d/auto.home
# confirm
su - netuserX
pwd
# /nfshome/netuserX