#### NFS Server Configuration #####
Note: connect to serverb and configure NFS server#####
1. Install the package
# yum install nfs-utils -y
2. Start the service
# systemctl enable --now nfs-server
3. Add the services into the firewalld
# firewall-cmd --add-service={nfs,rpc-bind,mountd}
# firewall-cmd --add-service={nfs,rpc-bind,mountd} --permanent
4. Create a folder
# mkdir /myshare
# vi /etc/exports
/myshare *.lab.example.com(ro,sync)
5. Export the shared directory
# exportfs -rv
6. Check the shared directory
# showmount -e serverb
##### Connect to Servera and try to mount to serverb NFS server shared folder
###########
# showmount -e serverb
# mkdir /mnt/vol1 => to create new dir to mount nfs share folder
# mount serverb.lab.example.com:/myshare /mnt/vol1
# df -hT => to check mount point
# umount /mnt/vol1
2. To mount permanent
# vi /etc/fstab
serverb.lab.example.com:/myshare /mnt/vol1 nfs defaults 0 0
:wq
3 Update the fstab file configuration
# mount -a
# systemctl daemon-reload
4. df -hT => to check mount point again
##### Part2: To share specific partition with nfs an across different systems
######
1. Connect to serverb and create partition in /dev/vdb 2GB, change partition type
to LVM Id ie.. 30
2. Create vg and pv on the partition
# vgcreate nfs_vg /dev/vdb3 => with one command you can create volume group and
physical volume at same time
# vgs => to check all vg
# lvcreate -n vol1 -L 1GB nfs_vg
# lvs => to check lv
# mkfs.ext4 /dev/nfs_vg/vol1
# mkdir /mnt/nfs_vol1
# mount /
# blkid => to check UUID, copy UUID and paste into /etc/fstab file
# vi /etc/fstab
UUID=paste UUID here /mnt/nfs_vol1 ext4 defaults 0 0
:wq
3. Create a new directory in logical volume with the name called share1
# mkdir /mnt/nfs_vol1/share1
4. Provide the above directory in the export file
# vi /etc/export
/mnt/nfs_vol1/share1 *.*(rw,sync)
:wq
5. Now export new added share directory
# exportfs -rv
###### To mount new share directory in servera (Client system) ####
1) connect to servera client system using ssh
2) Check serverb nfs share folder
# showmount -e serverb
3) Create a new dir in to mount serverb nfs server
# mkdir /mnt/nfs_vol1
4) Open fstab file & provide serverb nfs share folder details for permanent
mounting
# vi /etc/fstab
serverb.lab.example.com:/mnt/nfs_vol1/share1 /mnt/nfs_vol1 nfs defaults 0 0
:wq
# mount -a => to update the new configuration
# df -hT => to check the nfs server shared folder
###### To extend LV size, Go to serverb and extend lv size ####
# lvextend -r -L 1.5G /dev/nfs_vg/vol1
# lvs => to check new lv size
##### Now check in servera(client system) the NFS share new size ####
# df -hT => here will get in new size.
## Try to create some files in mount point of nfs client system ##
# cd /mnt/nfs_vol1
# touch test1 test2 test3
=> It will show permission denied error because at server on share folder it is
having 755 permissions.
=> In order to give write permission to client at server system we can either give
777 on share folder or we change
the ownership and groupownership of the share folder from defaul to nobody.
##### Now in serverb (NFS Server) try to change ownership and groupownership of nfs
share folder in order to give write permissons to client system#######
# id nobody => check username exist or not because in older version of linux it was
nfsnobody now in rhel 9 it is nobody
It should show id's of nobody user.
# chown nobody.nobody /mnt/nfs_vol1/share1
# ls -ld /mnt/nfs_vol1 => to check the owner and group owner
#### In servera (NFS CLient) again try to write the new data #####
# cd /mnt/nfs_vol1 => enter into mount point
# touch test{1..10} => Now you be able to write data.
## Like that way try to write data in another share folder mount point ###
# cd /mnt/vol1
# touch data{1..10}
Read only filesystem error => you cannot write because in NFS export file it is
having ro permissions
##### AUTO MOUNTING IN NFS CLIENT SYSTEM (servera machine) ######
1. Install the package
# yum install autofs -y
2. Edit /etc/auto.master file by adding the below line
# vi /etc/auto.master
/mnt/nfs_vol1 /etc/auto.misc --timeout=1
:wq
3. Edit /etc/auto.misc file by adding the below line
# vi /etc/auto.misc
linux -rw,sync,fstype=nfs4 serverb.lab.example.com:/mnt/nfs_vol1/share1
:wq
4. Restart the service
# systemctl enable --now autofs
5. To check result try to enter into the local mount point
# umount /mnt/nfs_vol1 => firstly unmount previosly mounted directory
# cd /mnt/nfs_vol1/linux
# ls => to list data
# df -hT => mount point will show
# cd => to come out from the mount point
# df -hT => It will unmount
# cd /mnt/nfs_vol1/linux => enter into mount point, it will mount it automatically
# df -hT => again mount point will show.