How to install and configure NFS server and client in Centos.

 

What is Linux NFS Server?

Network File Sharing (NFS) is a protocol that allows you to share directories and files with other Linux clients over a network. Shared directories are typically created on a file server, running the NFS server component. Users add files to them, which are then shared with other users who have access to the folder.


Define Access for NFS Clients in Export File

To enable access to a single client

/testNFS {clientIP}(rw,sync,no_subtree_check)

To enable access to several clients

/testNFS {clientIP-1}(rw,sync,no_subtree_check)

{clientIP-2}(...)

{clientIP-3}(...)

To enable access to an entire subnet

/testNFS {subnetIP}/{subnetMask}(rw,sync,no_subtree_check)



Setup NFS Server

1.Installing nfs-utils
[root@rajeev ~]# yum install nfs-utils

2.Choose the directory to share. If not present create one.
[root@rajeev ~]# mkdir /testNFS

3.Add permissions and ownership privileges to the shared directory.
[root@rajeev ~]# chmod -R 755 /testNFS
[root@rajeev ~]# chown nfsnobody:nfsnobody /testNFS
[root@rajeev ~]# ll -d /testNFS
drwxr-xr-x 2 nfsnobody nfsnobody 6 Sep 19 11:38 /testNFS

4.Start the nfs services.

[root@rajeev ~]# systemctl status nfs.service 
● nfs-server.service - NFS server and services
   Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

[root@rajeev ~]# systemctl start  nfs.service 

[root@rajeev ~]# systemctl status nfs.service 
● nfs-server.service - NFS server and services
   Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; disabled; vendor preset: disabled)
   Active: active (exited) since Mon 2022-09-19 11:50:46 IST; 2s ago
  Process: 2793 ExecStartPost=/bin/sh -c if systemctl -q is-active gssproxy; then systemctl reload gssproxy ; fi (code=exited, status=3)
  Process: 2776 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)
  Process: 2775 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
 Main PID: 2776 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/nfs-server.service

Sep 19 11:50:46 rajeev.example.com systemd[1]: Starting NFS server and services...
Sep 19 11:50:46 rajeev.example.com sh[2793]: Failed to reload gssproxy.service: Job type reload is not applicable for unit gssproxy.service.
Sep 19 11:50:46 rajeev.example.com sh[2793]: See system logs and 'systemctl status gssproxy.service' for details.
Sep 19 11:50:46 rajeev.example.com systemd[1]: Started NFS server and services.

[root@rajeev ~]# systemctl enable nfs.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.


5.Configuring the exports file for sharing.
Open the exports file and add these lines.

[root@rajeev ~]# vim /etc/exports
/testNFS  192.168.122.228(rw,sync,no_root_squash)
For Example:-
[root@rajeev ~]# cat /etc/exports
# To enable access to an entire subnet 
#/testNFS    192.168.122.0/24(rw,sync,no_root_squash)

# To enable access to several clients
#/testNFS    192.168.122.10,192.168.122.11,192.168.122.12(rw,sync,no_root_squash)

# To enable access to a single client
#/testNFS    192.168.122.228(rw,sync,no_root_squash)

# To enable access to All Network
#/testNFS    *(rw,sync,no_root_squash)


6.Restart the service
[root@rajeev ~]# systemctl  restart nfs.service

7. To check nfs Share
[root@rajeev ~]# showmount -e 192.168.122.71
Export list for 192.168.122.71:
/testNFS 192.168.122.228


Setup NFS Client
1.Installing nfs-utils
[root@client ~]# yum install nfs-utils

2.Create a mount point
[root@client ~]# mkdir /testNFS_Client

3.Mounting the filesystem
[root@client ~]# showmount -e 192.168.122.71
Export list for 192.168.122.71: /testNFS 192.168.122.228
[root@client ~]# mount -t nfs 192.168.122.71:/testNFS /testNFS_Client

4.Verify if mounted
[root@client ~]# df -h
Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 17G 3.1G 14G 19% / devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 8.5M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/vda1 1014M 125M 890M 13% /boot tmpfs 386M 0 386M 0% /run/user/0 192.168.122.71:/testNFS 26G 8.1G 18G 31% /testNFS_Client

5.Mounting permanently. 
Now if the client is rebooted, we need to remount again. So, to mount permanently,we need to configure /etc/fstab file.
Append this to /etc/fstab

[root@client ~]# vim /etc/fstab
192.168.122.71:/testNFS /testNFS_Client  nfs defaults 0 0

To verify, create a file in the Client-side, and open in server-side.
[root@client ~]# echo "HI" > /testNFS_Client/TestNFSCLIENT
[root@rajeev ~]# cat /testNFS/TestNFSCLIENT 

Comments

Popular posts from this blog

PCS Corosync Pacemaker Cluster Mariadb using NFS

How to install and configure node js and PM2 in rhel7

How to Create or Configure iSCSI Server and Clinet