0% found this document useful (0 votes)
18 views3 pages

NFS Server Setup and Configuration Guide

The document provides a detailed guide on configuring an NFS server on serverb, including installation, service management, firewall configuration, and directory sharing. It also outlines steps for mounting the shared directory on a client system (servera), creating logical volumes, and managing permissions for file access. Additionally, it covers auto-mounting NFS shares for convenience and includes commands for verifying configurations and managing storage sizes.

Uploaded by

lokeshreddy0213
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views3 pages

NFS Server Setup and Configuration Guide

The document provides a detailed guide on configuring an NFS server on serverb, including installation, service management, firewall configuration, and directory sharing. It also outlines steps for mounting the shared directory on a client system (servera), creating logical volumes, and managing permissions for file access. Additionally, it covers auto-mounting NFS shares for convenience and includes commands for verifying configurations and managing storage sizes.

Uploaded by

lokeshreddy0213
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#### 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 *.[Link](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 [Link]:/myshare /mnt/vol1
# df -hT => to check mount point
# umount /mnt/vol1
2. To mount permanent
# vi /etc/fstab
[Link]:/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
[Link]:/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 [Link] /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/[Link] file by adding the below line


# vi /etc/[Link]
/mnt/nfs_vol1 /etc/[Link] --timeout=1
:wq

3. Edit /etc/[Link] file by adding the below line


# vi /etc/[Link]
linux -rw,sync,fstype=nfs4 [Link]:/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.

Common questions

Powered by AI

To allow write access on an NFS client, change the permissions of the NFS share directory. If the error indicates read-only access due to 755 permissions, you can either set the shared folder permissions to 777 or change its ownership. Use `chown nobody.nobody /mnt/nfs_vol1/share1` to change the owner and group owner to 'nobody', which RHEL 9 uses as the default NFS anonymous user. After this change, clients will be able to write to the shared directory .

To mount an NFS share permanently on a client system, first ensure the share is visible using `showmount -e serverb`. Create a mount directory on the client system, e.g., `mkdir /mnt/vol1`. Add the NFS share to the `/etc/fstab` file with `serverb.lab.example.com:/myshare /mnt/vol1 nfs defaults 0 0`. Apply the configuration with `mount -a` and reload the system daemon using `systemctl daemon-reload`. Finally, check the mount point using `df -hT` to ensure it's correctly mounted .

To automate the mounting of an NFS share on an NFS client system, install the `autofs` package with `yum install autofs -y`. Edit the `/etc/auto.master` file to include the line `/mnt/nfs_vol1 /etc/auto.misc --timeout=1`. Modify the `/etc/auto.misc` file to add the NFS share with options `linux -rw,sync,fstype=nfs4 serverb.lab.example.com:/mnt/nfs_vol1/share1`. Enable and start the `autofs` service with `systemctl enable --now autofs`. The NFS share will mount automatically when accessed and unmount on inactivity .

Changing the ownership and group ownership of an NFS share folder to `nobody` aligns with the default anonymous user for NFS, facilitating write permissions for client systems that otherwise face restrictions due to directory permissions, such as 755. This adjustment ensures that files created by clients align with an ownership that doesn't conflict with server-side settings, effectively granting clients write capabilities without globally opening permissions through 777 settings .

To share a specific partition across different systems using NFS, connect to `serverb` and create a partition on `/dev/vdb`, changing its type to LVM. Create a volume group and physical volume with `vgcreate nfs_vg /dev/vdb3`. Make a logical volume with `lvcreate -n vol1 -L 1GB nfs_vg` and format it using `mkfs.ext4 /dev/nfs_vg/vol1`. Mount it to a directory, e.g., `mkdir /mnt/nfs_vol1`, then get the UUID using `blkid` and add it to `/etc/fstab`. Create a directory in the logical volume, specify it in the exports file for sharing, and export it with `exportfs -rv`. Ensure the changes are reflected on the client by updating `/etc/fstab` for permanent mounting .

Setting directory permissions to 777 on NFS shares allows all users read, write, and execute access. The immediate benefit is ease of access, avoiding permission-related errors for any user trying to write to or execute files in the directory. However, this also presents significant security risks, as any user with network access can modify or delete files, potentially leading to data loss or corruption and making the system susceptible to malicious activities. A more secure approach would be to adjust ownership and limit access to specific users or groups as needed .

To extend an existing logical volume used for NFS sharing, run `lvextend -r -L 1.5G /dev/nfs_vg/vol1` on `serverb`. This command extends the logical volume size to 1.5 GB, automatically resizing the filesystem as well. On the NFS client system, the new size will be apparent when checking the NFS share with `df -hT`. The client system does not require any additional steps to recognize the increased space as the extension is handled transparently .

To configure an NFS server on Linux, install the `nfs-utils` package with `yum install nfs-utils -y`. Start the NFS service using `systemctl enable --now nfs-server`. Then, add NFS services to the firewall using `firewall-cmd --add-service={nfs,rpc-bind,mountd}` and make it permanent with `firewall-cmd --add-service={nfs,rpc-bind,mountd} --permanent`. Create a directory (`mkdir /myshare`), edit the `/etc/exports` file to share it (`/myshare *.lab.example.com(ro,sync)`), and export the directory with `exportfs -rv`. Check the shared directory using `showmount -e serverb` .

To configure a shared folder on a new logical volume for NFS, begin by creating the volume group that includes the new partition, and make a logical volume with `lvcreate`. Format the logical volume, mount it to a directory like `/mnt/nfs_vol1`, and add it to `/etc/fstab` using its UUID for automatic mounting. Create a share folder in the logical volume, e.g., `mkdir /mnt/nfs_vol1/share1`, and define it in `/etc/exports` for NFS sharing. Export the directory with `exportfs -rv`. These steps ensure the folder is both available and advertised for client systems to access .

An NFS client may encounter a 'Read-Only filesystem' error when the `etc/exports` file on the NFS server is configured with 'ro' (read-only) permissions. If a client attempts to write to such a file system, it will be denied due to these export settings. To resolve this, you need to change the relevant line in the `/etc/exports` file on the NFS server to 'rw' (read-write), for example, `/mnt/nfs_vol1/share1 *.*(rw,sync)`. Re-export the directories with `exportfs -rv` to apply the changes and allow write access .

You might also like