Here we have two servers. we are going to attach  an additional disk in one server and share the disk to the other server using NFS

server 1 - 172.31.23.64 (NFS server)

server 2 - 172.31.27.183 ( NFS client)

these are private IPs

we are attaching disk in NFS server .

STAGE 1 : ATTACH  DISK IN  VM  AND MOUNT  (NFS server)

Login into azure portal ,

  1. Go to the Azure portal to find the VM. Search for and select Virtual machines.
  2. Choose the VM from the list.
  3. In the Virtual machines page, under Settings, choose Disks.

Then attach a new disk,

  1. On the Disks pane, under Data disks, select Create and attach a new disk.
  2. Enter a name for your managed disk. Review the default settings, and update the Storage type.
  3. When you are done, select Save at the top of the page to create the managed disk and update the VM configuration.

Connect to the server via putty,

Once connected to your VM, you need to find the disk,

lsblk

The output is similar to the following example

Here xvdf  is the attached disk.

If you are using an existing disk that contains data, skip to mounting the disk. If you are attaching a new disk, you need to partition the disk.

parted /dev/xvdf --script mklabel gpt mkpart xfspart xfs 0% 100%

mkfs.xfs /dev/xvdf1

partprobe /dev/xvdf1

Then create a directory and mount the file system,

mkdir /datadrive

Use mount to  mount the filesystem

mount  /dev/xvdf1  /datadrive

df -h

Disk is mounted.

To ensure that the drive is remounted automatically after a reboot, it must be added to the /etc/fstab file.

blkid

Copy the UUID and save it in /etc/fstab

nano /etc/fstab

UUID=18d5b64a-0dfc-4b8d-8b15-a05950570399   /datadrive   xfs   defaults,nofail   1   2

And save.

Thats all..

STAGE 2 : MOUNT NFS FILE SYSTEM

NFS, stands for Network File System, is a server-client protocol used for sharing files between linux/unix to unix/linux systems. NFS enables you to mount a remote share locally. You can then directly access any of the files on that remote share.

I have two server

NFS server - 172.31.23.64  (in this server we already attached a disk)

NFS client -  172.31.27.183

Install and start needed services on both NFS server and client

yum install nfs-utils

systemctl enable rpcbind

systemctl enable nfs-server

systemctl enable nfs-lock

systemctl enable nfs-idmap

systemctl start rpcbind

systemctl start nfs-server

systemctl start nfs-lock

systemctl start nfs-idmap

We need to run above commands in both servers.

Login into NFS server,

We want to mount the /datadrive as NFS

chmod 777 /datadrive

Export shared directory on NFS Server:

nano /etc/exports

And put

/datadrive/ 172.31.0.0/16(rw,sync,no_root_squash,no_all_squash)

systemctl restart nfs-server

Then Login into client server, we already enabled and installed all the needed things

Create a directory

mkdir /backup

Mount the share from server to client as shown below

mount -t nfs 172.31.23.64:/datadrive /backup

To verify ,

mount

You need to add in /etc/fstab files

nano  /etc/fstab

172.31.23.64:/datadrive /backup/ nfs rw,sync,hard,intr 0 0

And save

Thats all