Friday, January 13, 2023

Procedure to export a filesystem in linux and mounting it in client machines (NFS)

How to export a filesystem in linux using nfs protocal and access the same using clients on the same subnet

1) Ensure you have nfs-utils.x86_64 packages installed to install nfs server bin and service. This util needs to be installed on the nfs server and clients (all machines)

without nfs-utils packages

[root@localhost ~]# systemctl status fs
Unit fs.service could not be found.
[root@localhost ~]#

After nfs-utils package installation:

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

2) Note down the machine IP to note down the subnet it is in, so we can grant the access to all the machines in the same subnet.

For example:
ip: 10.0.2.8/24
So we will grant access to the subnet:
10.0.2.0/24

3) Make an entry in the /etc/exports file the filesystem we wanted to allow for nfs export with necessary acl for other hosts.

Filesystem picked for remote mount:
/dev/mapper/appvg-appvg--pgbackup00   5.9G  458M  5.5G   8% /pgBACKUP

[root@localhost ~]# cat /etc/exports
/pgBACKUP 10.0.2.0/24(rw,sync)
[root@localhost ~]#

4) Now start the nfs service as root

[root@localhost ~]# systemctl start nfs
[root@localhost ~]#

5) Check the status of nfs service

[root@localhost ~]# systemctl status nfs
● nfs-server.service - NFS server and services
   Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; disabled; vendor preset: disabled)
   Active: active (exited) since Sat 2023-01-07 10:23:17 EST; 6s ago
  Process: 7751 ExecStartPost=/bin/sh -c if systemctl -q is-active gssproxy; then systemctl reload gssproxy ; fi (code=exited, status=0/SUCCESS)
  Process: 7734 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)
  Process: 7733 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
 Main PID: 7734 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/nfs-server.service
Jan 07 10:23:16 localhost.localdomain systemd[1]: Starting NFS server and services...
Jan 07 10:23:17 localhost.localdomain systemd[1]: Started NFS server and services.
[root@localhost ~]#

[root@localhost ~]# systemctl status nfs --all
● nfs-server.service - NFS server and services
   Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; disabled; vendor preset: disabled)
   Active: active (exited) since Sat 2023-01-07 10:25:51 EST; 1min 5s ago
  Process: 8794 ExecStopPost=/usr/sbin/exportfs -f (code=exited, status=0/SUCCESS)
  Process: 8792 ExecStopPost=/usr/sbin/exportfs -au (code=exited, status=0/SUCCESS)
  Process: 8791 ExecStop=/usr/sbin/rpc.nfsd 0 (code=exited, status=0/SUCCESS)
  Process: 8835 ExecStartPost=/bin/sh -c if systemctl -q is-active gssproxy; then systemctl reload gssproxy ; fi (code=exited, status=0/SUCCESS)
  Process: 8818 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)
  Process: 8817 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
 Main PID: 8818 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/nfs-server.service
Jan 07 10:25:51 localhost.localdomain systemd[1]: Starting NFS server and services...
Jan 07 10:25:51 localhost.localdomain systemd[1]: Started NFS server and services.
[root@localhost ~]#

6) Now before trying to mount the FS, please be sure to exempt the nfs port 2049. I stopped firewall in my setup.

7) Mount the nfs using the below command
[root@localhost ~]# mount 10.0.2.8:/pgBACKUP /mnt/nmonclient
[root@localhost ~]# df -h
Filesystem                           Size  Used Avail Use% Mounted on
10.0.2.8:/pgBACKUP                   5.9G  458M  5.5G   8% /mnt/nmonclient
[root@localhost ~]#

8) The mountpoint is available in the client machine.

Thank you!

No comments:

Post a Comment

Troubleshooting the “Cannot Generate SSPI Context” Error After SQL Server Migration

  Introduction After a recent  SQL Server migration from 2012 to 2022 , our team encountered a classic authentication issue: The target prin...