Showing posts with label CentOS. Show all posts
Showing posts with label CentOS. Show all posts

Thursday, March 22, 2018

Linux: Tape Drive Configuration in Linux

In this blog, we are going to test writing data to a tape library. The tape library is HPE MSL 2024 with 24 tape slots and two tape drives. The tapes are LTO Ultrium 7 with 15 TB capacity. The tape library must be connected to a physical server, in this case we have connected the tape library to the physical server via Fibre Channel. We have setup Cent OS 7 in the physical server.

The tape library can be managed via Web GUI shown below.



We can check if the tape devices are present in the server as SCSI devices by running the following commands in the Cent OS server:

 [root@backup ~]# lsscsi  
 [0:0:0:0]  tape  HP    Ultrium 7-SCSI  HB81 /dev/st1   
 [1:0:0:0]  storage HP    P420i      8.00 -      
 [1:1:0:0]  disk  HP    LOGICAL VOLUME  8.00 /dev/sda   
 [4:0:0:0]  tape  HP    Ultrium 7-SCSI  HB81 /dev/st0   
 [4:0:0:1]  mediumx HP    MSL G3 Series  7.00 /dev/sch0  

 [root@backup ~]# cat /proc/scsi/scsi  
 Attached devices:  
 Host: scsi1 Channel: 00 Id: 00 Lun: 00  
  Vendor: HP    Model: P420i      Rev: 8.00  
  Type:  RAID               ANSI SCSI revision: 05  
 Host: scsi1 Channel: 01 Id: 00 Lun: 00  
  Vendor: HP    Model: LOGICAL VOLUME  Rev: 8.00  
  Type:  Direct-Access          ANSI SCSI revision: 05  
 Host: scsi4 Channel: 00 Id: 00 Lun: 00  
  Vendor: HP    Model: Ultrium 7-SCSI  Rev: HB81  
  Type:  Sequential-Access        ANSI SCSI revision: 06  
 Host: scsi4 Channel: 00 Id: 00 Lun: 01  
  Vendor: HP    Model: MSL G3 Series  Rev: 7.00  
  Type:  Medium Changer          ANSI SCSI revision: 05  
 Host: scsi0 Channel: 00 Id: 00 Lun: 00  
  Vendor: HP    Model: Ultrium 7-SCSI  Rev: HB81  
  Type:  Sequential-Access        ANSI SCSI revision: 06  

We can see in the above output that three tape devices are present in the server:

  1. The first device is a  "Sequential-Access" tape drive, present as /dev/st0.
Host: scsi4 Channel: 00 Id: 00 Lun: 00
Vendor: HP Model: Ultrium 7-SCSI Rev: HB81
Type: Sequential-Access ANSI SCSI revision: 06

      2. The second device is a "Sequential-Access" tape drive, present as /dev/st1.

Host: scsi0 Channel: 00 Id: 00 Lun: 00
Vendor: HP Model: Ultrium 7-SCSI Rev: HB81
Type: Sequential-Access ANSI SCSI revision: 06

     3. The third device is the "Medium Changer" or the tape library hosting the tapes and the tape drives.

Host: scsi4 Channel: 00 Id: 00 Lun: 01
Vendor: HP Model: MSL G3 Series Rev: 7.00
Type: Medium Changer ANSI SCSI revision: 05

  
It is important to note that Linux presents the tape drives with two types of device files:

  1. /dev/st0 and /dev/st1.
  2. /dev/nst0 and /dev/nst1.
The "n" in the second file type stands for non-rewinding tape. If we use /dev/st0 and write data to the tape, the tape will auto rewind to the beginning of the tape and the data will be overwritten with new data while writing data the second time.

However, if we use /dev/nst0 and write data to the tape, the tape will not auto rewind to the beginning of the tape and new data can be written sequentially after the previous data. 

For management of tape drive, we will run the "mt" commands and "tar" commands to write data to the tapes.

For checking the status of the two tape drives the following commands are run:

 [root@backup ~]# mt -f /dev/nst0 status  
 SCSI 2 tape drive:  
 File number=0, block number=0, partition=0.  
 Tape block size 0 bytes. Density code 0x5c (no translation).  
 Soft error count since last status=0  
 General status bits on (41010000):  
  BOT ONLINE IM_REP_EN  

 [root@backup ~]# mt -f /dev/nst1 status  
 SCSI 2 tape drive:  
 File number=-1, block number=-1, partition=0.  
 Tape block size 0 bytes. Density code 0x0 (default).  
 Soft error count since last status=0  
 General status bits on (50000):  
  DR_OPEN IM_REP_EN  

The first tape drive /dev/nst0 status, indicates that the tape is loaded from it's slot to the first tape drive. The tape is ready for data to be written and the general status indicates BOT ONLINE IM_REP_EN. BOT means Beginning Of Tape.

The second tape drive /dev/nst1 status, indicates the tape drive is empty with the general status DR_OPEN IM_REP_EN.

For this test we have run the commands as root user, however, we should create a different user with privileges for production systems.

I have created empty files by running "touch test{1..5}" shown below.

 [root@backup ~]# ls  
 anaconda-ks.cfg devices scsi tape test1 test2 test3 test4 test5  

Now, we write these test files to the first tape drive using tar.

 [root@backup ~]# tar -cvzf /dev/nst0 test1 test2 test3 test4 test5  
 test1  
 test2  
 test3  
 test4  
 test5  

After writing data, the tape needs to be rewind to check and verify that data has been written.

 [root@backup ~]# mt -f /dev/nst0 rewind  

Then, we check the status of the tape drive to verify that the tape is at the beginning.

 [root@backup ~]# mt -f /dev/nst0 status  
 SCSI 2 tape drive:  
 File number=0, block number=0, partition=0.  
 Tape block size 0 bytes. Density code 0x5c (no translation).  
 Soft error count since last status=0  
 General status bits on (41010000):  
  BOT ONLINE IM_REP_EN  

Now, we verify the test data by running tar.

 [root@backup ~]# tar -tzf /dev/st0  
 test1  
 test2  
 test3  
 test4  
 test5  

After checking the data by running above command, the tape will wind to the end of the data. We again rewind the tape:

 [root@backup ~]# mt -f /dev/nst0 rewind  

 [root@backup ~]# mt -f /dev/nst0 status  
 SCSI 2 tape drive:  
 File number=0, block number=0, partition=0.  
 Tape block size 0 bytes. Density code 0x5c (no translation).  
 Soft error count since last status=0  
 General status bits on (41010000):  
  BOT ONLINE IM_REP_EN  

Then, we go to the end of the data:

 [root@backup ~]# mt -f /dev/nst0 eod  

And check the status of the tape drive to verify the tape is at the end of data denoted by general status EOD ONLINE IM_REP_EN.

 [root@backup ~]# mt -f /dev/nst0 status  
 SCSI 2 tape drive:  
 File number=1, block number=-1, partition=0.  
 Tape block size 0 bytes. Density code 0x5c (no translation).  
 Soft error count since last status=0  
 General status bits on (9010000):  
  EOD ONLINE IM_REP_EN  

For a final test we erase the contents of the tape. Since we are at the end of data, we need to rewind again.

 [root@backup ~]# mt -f /dev/nst0 rewind  

Now, we erase the contents of the tape in the first tape drive.

 [root@backup ~]# mt -f /dev/nst0 erase  

So, we have tested by writing data to tape drives from Linux server successfully. These are basic operations required to manually write data to a single tape drive or a tape library. However, in practice, it is preferred to use a backup software solution where a backup configuration is done according to the company's backup policy for automatic backup and to prevent potential human error.







Friday, March 2, 2018

Linux: LVM Configuration in Linux

In this blog, we are going to perform some basic LVM operations. The OS is a Centos 6.5 Virtual Machine. A new HDD of size 20 GB has been added.

[root@lvm ~]# lsblk
NAME                           MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0                             11:0    1 1024M  0 rom
sda                              8:0    0  100G  0 disk
├─sda1                           8:1    0  500M  0 part /boot
└─sda2                           8:2    0 99.5G  0 part
  ├─vg_cellmgr1-lv_root (dm-0) 253:0    0   50G  0 lvm  /
  ├─vg_cellmgr1-lv_swap (dm-1) 253:1    0  7.9G  0 lvm  [SWAP]
  └─vg_cellmgr1-lv_home (dm-2) 253:2    0 41.7G  0 lvm  /home

[root@lvm ~]# ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2

However, as seen above the new HDD is not present in the OS and the device file is also not there. So we need to re-scan the SCSI bus to which the HDD is connected.

[root@lvm ~]# for BUS in /sys/class/scsi_host/host*/scan
> do
> echo "- - -" > ${BUS}
> done

We have re-scanned the SCSI bus using the above script in the shell. This process is followed when adding new Hard Disks. If we need to expand existing HDD, either of the following commands should be run:

echo "1" > /sys/class/scsi_device/device/rescan
echo "1" > /sys/class/block/sdb/device/rescan

We can see below that the HDD has been added.

[root@lvm ~]# lsblk
NAME                           MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0                             11:0    1 1024M  0 rom
sda                              8:0    0  100G  0 disk
├─sda1                           8:1    0  500M  0 part /boot
└─sda2                           8:2    0 99.5G  0 part
  ├─vg_cellmgr1-lv_root (dm-0) 253:0    0   50G  0 lvm  /
  ├─vg_cellmgr1-lv_swap (dm-1) 253:1    0  7.9G  0 lvm  [SWAP]
  └─vg_cellmgr1-lv_home (dm-2) 253:2    0 41.7G  0 lvm  /home
sdb                              8:16   0   20G  0 disk

[root@lvm ~]# ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2  /dev/sdb

Now, the new HDD is present in the OS as:
/dev/sdb

For creating partitions we will be using fdisk.

[root@lvm ~]# fdisk /dev/sdb

The following steps need to be followed carefully:

  1. Type 'n' for new partition.
  2. Press 'p' for primary partition.
  3. '1' for the partition number. 
  4. Then press 'Enter' for First and Last cylinder to use default values which will result in the partition using up all the space from the disk. 
  5. Type 'p' to list the partitions.

The above steps are executed as shown below.

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610):
Using default value 2610

Command (m for help): p
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        2610    20964793+  83  Linux

Type 't' to change the type of the partition created. We will use the code '8e' for LVM.

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x114f0a8d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        2610    20964793+  8e  Linux LVM

Write the changes using 'w' command.

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

[root@lvm ~]# partprobe /dev/sdb

[root@lvm ~]# lsblk
NAME                           MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0                             11:0    1 1024M  0 rom
sda                              8:0    0  100G  0 disk
├─sda1                           8:1    0  500M  0 part /boot
└─sda2                           8:2    0 99.5G  0 part
  ├─vg_cellmgr1-lv_root (dm-0) 253:0    0   50G  0 lvm  /
  ├─vg_cellmgr1-lv_swap (dm-1) 253:1    0  7.9G  0 lvm  [SWAP]
  └─vg_cellmgr1-lv_home (dm-2) 253:2    0 41.7G  0 lvm  /home
sdb                              8:16   0   20G  0 disk
└─sdb1                           8:17   0   20G  0 part

The partition has been created. Now, we create the LVM. The first step is to create Physical Volume.

[root@lvm ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created

The second step is to create Volume Group.

[root@lvm ~]# vgcreate vg_test /dev/sdb1
  Volume group "vg_test" successfully created

[root@lvm ~]# vgdisplay vg_test
  --- Volume group ---
  VG Name               vg_test
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               19.99 GiB
  PE Size               4.00 MiB
  Total PE              5118
  Alloc PE / Size       0 / 0
  Free  PE / Size       5118 / 19.99 GiB
  VG UUID               ViaF4b-G49v-AG5W-PlkE-ydsu-hThU-ClZeGv

[root@lvm ~]# vgs
  VG          #PV #LV #SN Attr   VSize  VFree
  vg_cellmgr1   1   3   0 wz--n- 99.51g     0
  vg_test       1   0   0 wz--n- 19.99g 19.99g

The Volume Group has been created and is verified above. The third step is to create Logical Volume. We will be creating two Logical Volumes, the first will be of 15 GB and the second 5 GB.

[root@lvm ~]# lvcreate -L 15G -n lv_live1 vg_test
  Logical volume "lv_live1" created

[root@lvm ~]# vgdisplay vg_test
  --- Volume group ---
  VG Name               vg_test
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               19.99 GiB
  PE Size               4.00 MiB
  Total PE              5118
  Alloc PE / Size       3840 / 15.00 GiB
  Free  PE / Size       1278 / 4.99 GiB
  VG UUID               ViaF4b-G49v-AG5W-PlkE-ydsu-hThU-ClZeGv

Now, we will create the second Logical Volume named 'lv_live2' with the remaining free space on the Volume Group 'vg_test'.

[root@lvm ~]# lvcreate -l 100%FREE -n lv_live2 vg_test
  Logical volume "lv_live2" created
[root@lvm ~]# lvs |grep lv_live
  lv_live1 vg_test     -wi-a----- 15.00g
  lv_live2 vg_test     -wi-a-----  4.99g

The Logical Volumes have been successfully created.

[root@lvm ~]# lsblk
NAME                           MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0                             11:0    1 1024M  0 rom
sda                              8:0    0  100G  0 disk
├─sda1                           8:1    0  500M  0 part /boot
└─sda2                           8:2    0 99.5G  0 part
  ├─vg_cellmgr1-lv_root (dm-0) 253:0    0   50G  0 lvm  /
  ├─vg_cellmgr1-lv_swap (dm-1) 253:1    0  7.9G  0 lvm  [SWAP]
  └─vg_cellmgr1-lv_home (dm-2) 253:2    0 41.7G  0 lvm  /home
sdb                              8:16   0   20G  0 disk
└─sdb1                           8:17   0   20G  0 part
  ├─vg_test-lv_live1 (dm-3)    253:3    0   15G  0 lvm
  └─vg_test-lv_live2 (dm-4)    253:4    0    5G  0 lvm

We need to format the Logical Volumes. We are going to format it to type 'EXT4'.

[root@lvm ~]# mkfs.ext4 /dev/vg_test/lv_live1

[root@lvm ~]# mkfs.ext4 /dev/vg_test/lv_live2

[root@lvm ~]# blkid |grep lv_live
/dev/mapper/vg_test-lv_live1: UUID="3d7cba8b-bd4a-48d3-a43b-013b964c95a0" TYPE="ext4"
/dev/mapper/vg_test-lv_live2: UUID="ec5bafd1-d2aa-4dea-b80b-6c5e3bf3273a" TYPE="ext4"

We will create two folders 'Live1 and Live2' which will be the mount points for the Logical Volumes.

[root@lvm ~]# mkdir /Live{1..2}
[root@lvm ~]# ls /
bin  boot  dev  etc  home  lib  lib64  Live1  Live2  lost+found  media  misc  mnt  net  opt  proc  repo  root  sbin  selinux  srv  sys  tmp  usr  var

The following entries are added to fstab file for permanent mount.

[root@lvm ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Wed May  9 10:48:07 2018
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vg_cellmgr1-lv_root /                       ext4    defaults        1 1
UUID=501e7ee7-ce91-41cd-9036-14ab4f2eaecd /boot                   ext4    defaults        1 2
/dev/mapper/vg_cellmgr1-lv_home /home                   ext4    defaults        1 2
/dev/mapper/vg_cellmgr1-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0

/dev/mapper/vg_test-lv_live1    /Live1  ext4    defaults        1       1
/dev/mapper/vg_test-lv_live2    /Live2 ext4     defaults        1       1
[root@lvm ~]# mount -a

Now, the mount points are ready.

[root@lvm ~]# df -h
Filesystem                       Size  Used Avail Use% Mounted on
/dev/mapper/vg_cellmgr1-lv_root   50G  6.3G   41G  14% /
tmpfs                            940M   72K  940M   1% /dev/shm
/dev/sda1                        485M   39M  421M   9% /boot
/dev/mapper/vg_cellmgr1-lv_home   41G  176M   39G   1% /home
/dev/mapper/vg_test-lv_live1      15G  166M   14G   2% /Live1
/dev/mapper/vg_test-lv_live2     5.0G  138M  4.6G   3% /Live2

Extend Logical Volume


I have added another 5 GB of HDD on the VM. So we will repeat the previous steps of rescanning the BUS.

[root@lvm ~]# for BUS in /sys/class/scsi_host/host*/scan
> do
> echo "- - -" > ${BUS}
> done
[root@lvm ~]# ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2  /dev/sdb  /dev/sdb1  /dev/sdc
[root@lvm ~]# lsblk
NAME                           MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0                             11:0    1 1024M  0 rom
sda                              8:0    0  100G  0 disk
├─sda1                           8:1    0  500M  0 part /boot
└─sda2                           8:2    0 99.5G  0 part
  ├─vg_cellmgr1-lv_root (dm-0) 253:0    0   50G  0 lvm  /
  ├─vg_cellmgr1-lv_swap (dm-1) 253:1    0  7.9G  0 lvm  [SWAP]
  └─vg_cellmgr1-lv_home (dm-2) 253:2    0 41.7G  0 lvm  /home
sdb                              8:16   0   20G  0 disk
└─sdb1                           8:17   0   20G  0 part
  ├─vg_test-lv_live1 (dm-3)    253:3    0   15G  0 lvm  /Live1
  └─vg_test-lv_live2 (dm-4)    253:4    0    5G  0 lvm  /Live2
sdc                              8:32   0    5G  0 disk

Creating Physical Volume from the new HDD and extending the Volume Group 'vg_test'.

[root@lvm ~]# pvcreate /dev/sdc
  Physical volume "/dev/sdc" successfully created

[root@lvm ~]# vgs
  VG          #PV #LV #SN Attr   VSize  VFree
  vg_cellmgr1   1   3   0 wz--n- 99.51g    0
  vg_test       1   2   0 wz--n- 19.99g    0
[root@lvm ~]# vgextend vg_test /dev/sdc
  Volume group "vg_test" successfully extended
[root@lvm ~]# vgs
  VG          #PV #LV #SN Attr   VSize  VFree
  vg_cellmgr1   1   3   0 wz--n- 99.51g    0
  vg_test       2   2   0 wz--n- 24.99g 5.00g

Extending the Logical Volume with free space of the Volume Group 'vg_test'.

[root@lvm ~]# lvextend -l +100%FREE /dev/vg_test/lv_live1
  Extending logical volume lv_live1 to 20.00 GiB
  Logical volume lv_live1 successfully resized
[root@lvm ~]# lvs |grep live
  lv_live1 vg_test     -wi-ao---- 20.00g
  lv_live2 vg_test     -wi-ao----  4.99g

[root@lvm ~]# df -h
Filesystem                       Size  Used Avail Use% Mounted on
/dev/mapper/vg_cellmgr1-lv_root   50G  6.3G   41G  14% /
tmpfs                            940M   72K  940M   1% /dev/shm
/dev/sda1                        485M   39M  421M   9% /boot
/dev/mapper/vg_cellmgr1-lv_home   41G  176M   39G   1% /home
/dev/mapper/vg_test-lv_live1      15G  166M   14G   2% /Live1
/dev/mapper/vg_test-lv_live2     5.0G  138M  4.6G   3% /Live2

However, the partition size has not been updated. So we will resize the Filesystem.

[root@lvm ~]# resize2fs /dev/vg_test/lv_live1
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_test/lv_live1 is mounted on /Live1; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/vg_test/lv_live1 to 5241856 (4k) blocks.
The filesystem on /dev/vg_test/lv_live1 is now 5241856 blocks long.

[root@lvm ~]# df -h
Filesystem                       Size  Used Avail Use% Mounted on
/dev/mapper/vg_cellmgr1-lv_root   50G  6.3G   41G  14% /
tmpfs                            940M   72K  940M   1% /dev/shm
/dev/sda1                        485M   39M  421M   9% /boot
/dev/mapper/vg_cellmgr1-lv_home   41G  176M   39G   1% /home
/dev/mapper/vg_test-lv_live1      20G  170M   19G   1% /Live1
/dev/mapper/vg_test-lv_live2     5.0G  138M  4.6G   3% /Live2

Reduce LVM Size


First we need to unmount the partition mount point and then resize the filesystem to a size less than the size we are going to reduce the LVM to. Here, we are resizing the filessystem to 10 GB which is less than the size we will reduce the LVM to which is 12 GB.



[root@lvm ~]# e2fsck -f /dev/vg_test/lv_live1
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vg_test/lv_live1: 11/1310720 files (0.0% non-contiguous), 125585/5241856 blocks

[root@lvm ~]# resize2fs /dev/vg_test/lv_live1 10G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/vg_test/lv_live1 to 2621440 (4k) blocks.
The filesystem on /dev/vg_test/lv_live1 is now 2621440 blocks long.

[root@lvm ~]# lvreduce -L 12G /dev/vg_test/lv_live1
  WARNING: Reducing active logical volume to 12.00 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_live1? [y/n]: y
  Reducing logical volume lv_live1 to 12.00 GiB
  Logical volume lv_live1 successfully resized
[root@lvm ~]# resize2fs /dev/vg_test/lv_live1
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/vg_test/lv_live1 to 3145728 (4k) blocks.
The filesystem on /dev/vg_test/lv_live1 is now 3145728 blocks long.

Now we can see below that the LVM size has reduced to 12 GB.

[root@lvm ~]# mount -a
[root@lvm ~]# df -h
Filesystem                       Size  Used Avail Use% Mounted on
/dev/mapper/vg_cellmgr1-lv_root   50G  6.3G   41G  14% /
tmpfs                            940M   72K  940M   1% /dev/shm
/dev/sda1                        485M   39M  421M   9% /boot
/dev/mapper/vg_cellmgr1-lv_home   41G  176M   39G   1% /home
/dev/mapper/vg_test-lv_live2     5.0G  138M  4.6G   3% /Live2
/dev/mapper/vg_test-lv_live1      12G  166M   12G   2% /Live1

Thursday, February 22, 2018

Red Hat Cluster Part 8: Convert HA Cluster from Active/Passive to Active/Active

Recently, we had to convert an HA Cluster from Active/Passive  to Active/Active mode. So I thought of making a blog post for future reference. The scenario is as follows:

  • Operating System: CentOS 7.7
  • Cluster Mode: 2 Node Active/Passive
  • Cluster Manager: Pacemaker/Corosync
  • Shared Storage LVM: HA-LVM

Since the shared storage was configured as LVM resource using HA-LVM configuration, we had to reconfigure LVM to be managed by DLM, CLVMD and formatted as GFS2.

Remove HA-LVM Configuration

The first step in this process was to remove the HA-LVM configuration done previously. The steps used to configure HA-LVM are as follows.

While configuring HA-LVM on both nodes we ensure that the locking_type is set to 1 and use_lvmetad is set to 0 in the file /etc/lvm/lvm.conf  by issuing the following command disabling lvmetad processes.

 # lvmconf --enable-halvm --services --startstopservices  

Then in the same file in the volume_list we list all the Volume Group names that are not controlled by the Cluster but by the OS as given below on both nodes.

 volume_list = [ "centos_root", "centos_home" ]  

We rebuilt the initramfs boot image and rebooted both the nodes.

Now, we undo the above settings on both nodes.

1. Set use_lvmetad to 0 and locking_type to 3 in the file /etc/lvm/lvm.conf and stop lvm2-lvmetad service.

[root@node01 ~]# cat /etc/lvm/lvm.conf | grep use_lvmetad  
      use_lvmetad = 0  
[root@node01 ~]# cat /etc/lvm/lvm.conf | grep locking_type  
      locking_type = 3 
[root@node01 ~]# systemctl stop lvm2-lvmetad.service  

[root@node02 ~] # cat /etc/lvm/lvm.conf | grep use_lvmetad  
      use_lvmetad = 0  
[root@node02 ~]# cat /etc/lvm/lvm.conf | grep locking_type  
      locking_type = 3 
[root@node02 ~] # systemctl stop lvm2-lvmetad.service  

2. Comment the volume_list parameter in the file /etc/lvm/lvm.conf.

[root@node01 ~] # cat /etc/lvm/lvm.conf | grep volume_list  
     # volume_list = [ "centos_root", "centos_home" ]  
[root@node02 ~] # cat /etc/lvm/lvm.conf | grep volume_list  
     # volume_list = [ "centos_root", "centos_home" ]  

3. Rebuild the initramfs boot image and reboot both the nodes.

Before rebuilding the initramfs boot image we take a backup of the initramfs boot image.

[root@node01 ~] # cp -p /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak  
[root@node02 ~] # cp -p /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak  

Now we rebuild the initramfs boot image and reboot the nodes.

[root@node01 ~]# dracut -H -f /boot/initramfs-$(uname -r).img $(uname -r)
[root@node02 ~]# dracut -H -f /boot/initramfs-$(uname -r).img $(uname -r)

[root@node01 ~]# reboot
[root@node02 ~]# reboot

Configure CLVMD for Active/Active Mode

After removing HA-LVM configuration, we removed the previous Logical Volumes, Volume Groups and Physical Volumes that were on the shared storage. Since there was no data, we proceeded with the above step for ease. 

Then we re-created the PV, VG and LV for use in cluster mode and managed by CLVMD.

1. Install required packages.

We install lvm2-cluster and gfs2-utils packages.


 [root@node01 ~]# yum install lvm2-cluster gfs2-utils  
 [root@node02 ~]# yum install lvm2-cluster gfs2-utils  


2. Set no_quorum_policy to freeze in order to prevent fencing of all nodes when quorum is lost.

 [root@node01 ~]# pcs property set no-quorum-policy=freeze  

3. Setup DLM and CLVMD cluster resource.

Before proceeding with this step it is important to note that Cluster Fencing (STONITH) needs to be preconfigured. Otherwise the DLM and CLVMD resources do not activate the LVM and the shared storage will not be accessible. We had already configured iLO5 fencing as shown below.

[root@node01 ~]# pcs stonith create HPEiLO_N01_FENCE fence_ilo5_ssh \
ipaddr="192.168.3.5"login="fenceuser1" secure="true" passwd="password" \
method="onoff" delay=10 pcmk_reboot_action="reboot" pcmk_host_list="node01"

[root@node01 ~]# pcs stonith create HPEiLO_N02_FENCE fence_ilo5_ssh \
ipaddr="192.168.3.6" login="fenceuser2" secure="true" passwd="password" \
method="onoff" pcmk_reboot_action="reboot" pcmk_host_list="node02"

 [root@node01 ~]# pcs status
.........
HPEiLO_N01_FENCE      (stonith:fence_ilo5_ssh):      Started node01  
HPEiLO_N02_FENCE      (stonith:fence_ilo5_ssh):      Started node02  
.........

Setting up DLM resource.

[root@node01 ~]# pcs resource create dlm ocf:pacemaker:controld op \
monitor interval=30s on-fail=fence clone interleave=true ordered=true  

Setting up CLVMD resource.

[root@node01 ~]# pcs resource create clvmd ocf:heartbeat:clvm op \
monitor interval=30s on-fail=fence clone interleave=true ordered=true  

Setting DLM and CLVMD start up order and dependency. First the DLM resource must start then the CLVMD resource. Both must run on the same node.

[root@node01 ~]# pcs constraint order start dlm-clone then clvmd-clone
Adding dlm-clone clvmd-clone (kind: Mandatory) (Options: first-action=start then-action=start)
[root@node01 ~]# pcs constraint colocation add clvmd-clone with dlm-clone

We can verify if the above resources have been created by checking the status of the cluster.

[root@node01 ~]# pcs status
Clone Set: dlm-clone [dlm]
     Started: [ node01 node02 ]
Clone Set: clvmd-clone [clvmd]
     Started: [ node01 node02 ]

Configure GFS2 File System

Since we have deleted the previous LVM of the shared storage, we need to recreate the LVM and format as GFS2 Filesystem.

1. Create Clustered LVM

[root@node01 ~]# pvcreate /dev/mapper/shared01
[root@node01 ~]# vgcreate -Ay -cy vg_shared01 /dev/mapper/shared01
[root@node01 ~]# lvcreate -l 100%FREE -n lv_shared01 vg_shared01

The first command creates a Physical Volume of the shared storage mapped as device file /dev/mapper/shared01.

The second command creates a Volume Group vg_shared01 with the attributes Clustered (-cy) and Autobackup (-Ay) enabled.

The third command creates a Logical Volume lv_shared01 utilizing all the free space available in the Volume Group.

2. Create GFS2 file system

[root@node01 ~]# mkfs.gfs2 -p lock_dlm -j 2 -t dev_cluster:dev01 \
/dev/vg_shared01/lv_shared01

The above command formats the LVM device created in step 1 as GFS2 file system. It is recommended to only use GFS2 as the file system for Active/Active shared storage. For Active/Passive cluster EXT4 or XFS file system can be used as well.

The option -p stands for LockProtoName. We used lock_dlm. 

The option -j represents the number of journals. It is important to note that this number should be equal to the number of nodes in the cluster. So we have set this option to 2 journals. It creates one journal per system that mounts the file system.

The -t option stands for LockTableName. It's format is clustername:fsname. Clustername name must the same as the name of the cluster and fsname is a unique name of the GFS2 file system to differentiate from other file system names.

All the details are described here.

3. Create Filesystem resource to manage and mount the file system.

The /shared01 directory must be created on both the nodes before the following command is run since the command mounts the device to the directory /shared01 on both the nodes simultaneously.

[root@node01 ~]# pcs resource create FS_shared01 ocf:heartbeat:Filesystem \
device="/dev/vg_shared01/lv_shared01" directory="/shared01" fstype="gfs2" --clone

4. Set CLVMD and Filesystem resource startup order and dependency.

[root@node01 ~]# pcs constraint order start clvmd-clone then FS_shared01-clone
Adding dlm-clone clvmd-clone (kind: Mandatory) (Options: first-action=start then-action=start)
[root@node01 ~]# pcs constraint colocation add FS_shared01-clone with clvmd-clone

Configure Virtual IP Resource 

First we create the Virtual IP resource with the IP and subnet details.

[root@node01 ~]# pcs resource create VirtualIP IPaddr2 ip=198.168.90.17 cidr_netmask=24

Then we clone the Virtual IP resource. This step also depends on the application usage. If the application in the cluster requires load-balancing and failover, then this configuration is useful.

If only shared storage needs to be active on both the nodes and Virtual IP only connects to the application on one node at a time, then we do not need to clone the Virtual IP resource. If both shared storage and VIP only need to be active on a single node then an Active/Passive cluster mode is sufficient.

[root@node01 ~]# pcs resource clone VirtualIP \
globally-unique=true clone-max=2 clone-node-max=2
[root@node01 ~]# pcs resource update VirtualIP clusterip_hash=sourceip

The clone options are:

1. Globally-unique=true

When set true,  each copy of the clone performs different functions.

2. Clone-max=2

The number of resources to start, in this case 2.

3. Clone-node-max=2

The number of copies of resource to be started on a single node, in this case 2.

The clusterip_hash decides which hosts receive and process which requests. The parameter we have chosen is sourceip. The source IP address of incoming packets are hashed and the nodes each will receive certain hashes to process the requests.

Then we set the startup order and dependency of FS_shared01-clone and Virtual IP resource.

[root@node01 ~]# pcs constraint order start FS_shared01-clone then VirtualIP-clone
Adding dlm-clone clvmd-clone (kind: Mandatory) (Options: first-action=start then-action=start)
[root@node01 ~]# pcs constraint colocation add VirtualIP-clone with FS-shared01-clone

Similarly, we can setup other resources as per our requirement like Web Servers, Network File Shares or Database Services.

Finally checking the status of the cluster, we get the below output.

[root@node01 ~]# pcs status
Cluster name: dev_cluster
Stack: corosync

2 nodes configured
10 resources configured

Online: [ node01 node02 ]

Full list of resources:

 HPEiLO_N01_FENCE      (stonith:fence_ilo5_ssh):      Started node01  
 HPEiLO_N02_FENCE      (stonith:fence_ilo5_ssh):      Started node02  
 Clone Set: dlm-clone [dlm]
     Started: [ node01 node02 ]
 Clone Set: clvmd-clone [clvmd]
     Started: [ node01 node02 ]
 Clone Set: FS_shared01-clone [FS_shared01]
     Started: [ node01 node02 ]
 Clone Set: VirtualIP-clone [VirtualIP] (unique)
     VirtualIP:0        (ocf::heartbeat:IPaddr2) Started
     VirtualIP:1        (ocf::heartbeat:IPaddr2) Started

Red Hat Cluster Part 7: High Availability Cluster using Pacemaker

So, we are going to setup a High Availability Active/Passive Cluster running NFS server. Although we are setting this environment in VMware vCenter, this is not a VMware cluster, rather an OS level cluster. We can see Node-N1 and Node-N2 virtual machines in VMware in the below image. I have setup RDM (Raw Device Mapping) as shared storage on both the nodes provided from FreeNAS.



We will be using CentOS 7.2 for the cluster test.

[root@node02 ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)

The IP and Hostname details of the nodes:

[root@node01 ~]# cat /etc/hosts
127.0.0.1   cluster-node1.domain.com localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.200.124 node01  node01.test.com
192.168.200.125 node02  node02.test.com
[root@node02 ~]# cat /etc/hosts
127.0.0.1   cluster-node2.domain.com localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.200.124 node01  node01.test.com
192.168.200.125 node02  node02.test.com

Install Pacemaker Configuration Tools

We will install the required packages on both the nodes, however, we will only install the vmware-soap fencing agent as the nodes are Virtual Machines in a VMware environment.

[root@node01 ~]# yum -y install pcs pacemaker fence-agents-vmware-soap
[root@node02 ~]# yum -y install pcs pacemaker fence-agents-vmware-soap

Add Exception rule in Firewall

[root@node01 ~]# firewall-cmd --permanent --add-service=high-availability
success
[root@node01 ~]# firewall-cmd --add-service=high-availability
success
[root@node02 ~]# firewall-cmd --permanent --add-service=high-availability
success
[root@node02 ~]# firewall-cmd --add-service=high-availability
success

Setup password for hacluster user

[root@node01 ~]# passwd hacluster
Changing password for user hacluster.
New password:
[root@node02 ~]# passwd hacluster
Changing password for user hacluster.
New password:

Start the service

[root@node01 ~]# systemctl start pcsd.service
[root@node01 ~]# systemctl enable pcsd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/pcsd.service to /usr/lib/systemd/system/pcsd.service.
[root@node02 ~]# systemctl start pcsd.service
[root@node02 ~]# systemctl enable pcsd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/pcsd.service to /usr/lib/systemd/system/pcsd.service.

Authorize the nodes in the cluster

[root@node01 ~]# pcs cluster auth node01.test.com node02.test.com
Username: hacluster
Password:
node02.test.com: Authorized
node01.test.com: Authorized

Create Cluster

[root@node01 ~]# pcs cluster setup --start --name cluster_pr node01.test.com node02.test.com
Destroying cluster on nodes: node01.test.com, node02.test.com...
node01.test.com: Stopping Cluster (pacemaker)...
node02.test.com: Stopping Cluster (pacemaker)...
node01.test.com: Successfully destroyed cluster
node02.test.com: Successfully destroyed cluster

Sending 'pacemaker_remote authkey' to 'node01.test.com', 'node02.test.com'
node01.test.com: successful distribution of the file 'pacemaker_remote authkey'
node02.test.com: successful distribution of the file 'pacemaker_remote authkey'
Sending cluster config files to the nodes...
node01.test.com: Succeeded
node02.test.com: Succeeded

Starting cluster on nodes: node01.test.com, node02.test.com...
node01.test.com: Starting Cluster...
node02.test.com: Starting Cluster...

Synchronizing pcsd certificates on nodes node01.test.com, node02.test.com...
node02.test.com: Success
node01.test.com: Success
Restarting pcsd on the nodes in order to reload the certificates...
node02.test.com: Success
node01.test.com: Success

Enable Cluster

[root@node01 ~]# pcs cluster enable --all
node01.test.com: Cluster Enabled
node02.test.com: Cluster Enabled

We can see below that the cluster is enabled and running.

[root@node01 ~]# pcs cluster status
Cluster Status:
 Stack: corosync
 Current DC: node01.test.com (version 1.1.16-12.el7_4.8-94ff4df) - partition with quorum
 Last updated: Thu May 10 02:58:50 2018
 Last change: Thu May 10 02:55:42 2018 by hacluster via crmd on node01.test.com
 2 nodes configured
 0 resources configured

PCSD Status:
  node01.test.com: Online
  node02.test.com: Online

Fencing Agent Configuration

For fencing, we are going to use VMware fencing agent, so we need to create a vCenter user with privileges to Power on and off the VMs.






Test the Fencing Agent

[root@node01 ~]# fence_vmware_soap -z --ssl-insecure -a 192.168.200.212 -l 'fenceuser@vsphere.local' -p '1CLUP@ss3rd' -o list | grep Node
Node-N1,421fd583-88b7-24ce-401d-5f59222d07ab
Node-N2,421fd09e-754b-bc16-aa46-5398b59261a9

Configure Fencing Agent

[root@node01 ~]# pcs stonith create vm_fence fence_vmware_soap ipaddr=192.168.200.212 ipport=443 ssl=1 ssl_insecure=1 login='fenceuser@vsphere.local' passwd='1CLUP@ss3rd' pcmk_off_action=reboot pcmk_host_map="node01.test.com:Node-N1;node02.test.com:Node-N2" delay=10
[root@node01 ~]# echo $?
0

We can see that the fencing agent has been created successfully and is running.

[root@node01 ~]# pcs status
Cluster name: cluster_pr
Stack: corosync
Current DC: node01.test.com (version 1.1.16-12.el7_4.8-94ff4df) - partition with quorum
Last updated: Thu May 10 04:18:14 2018
Last change: Thu May 10 04:16:44 2018 by root via cibadmin on node01.test.com

2 nodes configured
1 resource configured

Online: [ node01.test.com node02.test.com ]

Full list of resources:

 vm_fence       (stonith:fence_vmware_soap):    Started node01.test.com

Daemon Status:
  corosync: active/enabled
  pacemaker: active/enabled
  pcsd: active/enabled

Ignore Quorum

We ignore quorum configuration as it is not supported in 7.2.

 [root@node01 ~]# pcs property set no-quorum-policy=ignore  

Configure LVM on shared storage

We can see in the below images, the shared storage (sdb) is present on both the nodes.

[root@node01 ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
fd0               2:0    1    4K  0 disk
sda               8:0    0   20G  0 disk
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   19G  0 part
  ├─centos-root 253:0    0   17G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sdb               8:16   0   90G  0 disk
sr0              11:0    1 1024M  0 rom

[root@node02 ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
fd0               2:0    1    4K  0 disk
sda               8:0    0   20G  0 disk
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   19G  0 part
  ├─centos-root 253:0    0   17G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sdb               8:16   0   90G  0 disk
sr0              11:0    1 1024M  0 rom

The following steps are to be performed on one node only. First create Physical Volume.

[root@node01 ~]# pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created.

Then Volume Group named "vg_cluster".

[root@node01 ~]# vgcreate vg_cluster /dev/sdb
  Volume group "vg_cluster" successfully created

Finally Logical Volume named "lv_cluster".

[root@node01 ~]# lvcreate -l 23039 -n lv_cluster vg_cluster
  Logical volume "lv_cluster" created.
[root@node01 ~]# lvs
  LV         VG         Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root       centos     -wi-ao---- <17.00g
  swap       centos     -wi-ao----   2.00g
  lv_cluster vg_cluster -wi-a----- <90.00g

Now, formatting the Logical Volume to 'xfs'.

[root@node01 ~]# mkfs.xfs /dev/vg_cluster/lv_cluster
[root@node01 ~]# blkid |grep cluster
/dev/mapper/vg_cluster-lv_cluster: UUID="886d99c3-a1d1-46f0-bfa7-00c81677e5c1" TYPE="xfs"

[root@node01 ~]# lsblk
NAME                    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
fd0                       2:0    1    4K  0 disk
sda                       8:0    0   20G  0 disk
├─sda1                    8:1    0    1G  0 part /boot
└─sda2                    8:2    0   19G  0 part
  ├─centos-root         253:0    0   17G  0 lvm  /
  └─centos-swap         253:1    0    2G  0 lvm  [SWAP]
sdb                       8:16   0   90G  0 disk
└─vg_cluster-lv_cluster 253:2    0   90G  0 lvm
sr0                      11:0    1 1024M  0 rom

We can see above that the LVM partition has been created on sdb.

Create the NFS Share

We will create the Network File System Share that is highly available which is the main objective of this cluster.

[root@node01 ~]# mkdir /Nfs
[root@node01 ~]# mount /dev/vg_cluster/lv_cluster /Nfs/

[root@node01 ~]# mkdir /Nfs/BACKUPDIR{1..5}
[root@node01 ~]# ls /Nfs/
BACKUPDIR1  BACKUPDIR2  BACKUPDIR3  BACKUPDIR4  BACKUPDIR5

[root@node01 ~]# touch /Nfs/BACKUPDIR1/hello_world{1..5}
[root@node01 ~]# ls /Nfs/BACKUPDIR1/
hello_world1  hello_world2  hello_world3  hello_world4  hello_world5

[root@node01 ~]# umount /Nfs
[root@node01 ~]# vgchange -an vg_cluster
  0 logical volume(s) in volume group "vg_cluster" now active

Activate Volume Group in a Cluster

The following steps need to be performed on both the nodes. We need to make some changes in the LVM configuration file so that the OS does not activate the LVM partition we created above as it will be managed by the Cluster services.


[root@node01 ~]# lvmconf --enable-halvm --services --startstopservices
Warning: Stopping lvm2-lvmetad.service, but it can still be activated by:
  lvm2-lvmetad.socket
Removed symlink /etc/systemd/system/sysinit.target.wants/lvm2-lvmetad.socket.  
[root@node02 ~]# lvmconf --enable-halvm --services --startstopservices
Warning: Stopping lvm2-lvmetad.service, but it can still be activated by:
  lvm2-lvmetad.socket
Removed symlink /etc/systemd/system/sysinit.target.wants/lvm2-lvmetad.socket.

We list all the Volume Groups present in the OS.

[root@node01 ~]# vgs --noheadings -o vg_name
  centos
  vg_cluster
[root@node02 ~]# vgs --noheadings -o vg_name
  centos
  vg_cluster

Then, we edit the LVM configuration file as shown below. We have added the "centos" Volume Group and not "vg_cluster". The "centos" Volume Group will be activated and managed by the OS.

[root@node01 ~]# vim /etc/lvm/lvm.conf
[root@node02 ~]# vim /etc/lvm/lvm.conf

[root@node01 ~]# vim /etc/lvm/lvm.conf
[root@node01 ~]# cat /etc/lvm/lvm.conf |grep volume_list
        # it is auto-activated. The auto_activation_volume_list setting
        # Configuration option activation/volume_list.
        #     or VG. See tags/hosttags. If any host tags exist but volume_list
        # volume_list = [ "vg1", "vg2/lvol1", "@tag1", "@*" ]
        volume_list = [ "centos" ]
[root@node02 ~]# vim /etc/lvm/lvm.conf
[root@node02 ~]# cat /etc/lvm/lvm.conf |grep volume_list
        # it is auto-activated. The auto_activation_volume_list setting
        # Configuration option activation/volume_list.
        #     or VG. See tags/hosttags. If any host tags exist but volume_list
        # volume_list = [ "vg1", "vg2/lvol1", "@tag1", "@*" ]
        volume_list = [ "centos" ]

Take a backup of the "initramfs-$(uname -r).img" file.

[root@node01 ~]# cp -p /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak

[root@node02 ~]# cp -p /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak

Now, we are going to rebuild the initramfs boot image for the changes to be permanent.

[root@node01 ~]# dracut -H -f /boot/initramfs-$(uname -r).img $(uname -r)
[root@node02 ~]# dracut -H -f /boot/initramfs-$(uname -r).img $(uname -r)

And finally we need to reboot both the nodes.

[root@node01 ~]# reboot
[root@node02 ~]# reboot

After rebooting we need to make sure that the cluster services are running and the status is good.

[root@node01 ~]# pcs status
Cluster name: cluster_pr
Stack: corosync
Current DC: node01.test.com (version 1.1.16-12.el7_4.8-94ff4df) - partition with quorum
Last updated: Thu May 10 05:29:30 2018
Last change: Thu May 10 05:27:12 2018 by hacluster via crmd on node01.test.com

2 nodes configured
1 resource configured

Online: [ node01.test.com node02.test.com ]

Full list of resources:

 vm_fence       (stonith:fence_vmware_soap):    Started node01.test.com

Daemon Status:
  corosync: active/enabled
  pacemaker: active/enabled
  pcsd: active/enabled

Create Resource

We need to create resources for services to be run and be managed by the cluster. 

First we create the LVM resource provided by 'OCF' (Open Cluster Framework).

[root@node01 ~]# pcs resource create lvm_res LVM volgrpname=vg_cluster exclusive=true --group group_Nfs
Assumed agent name 'ocf:heartbeat:LVM' (deduced from 'LVM')
[root@node01 ~]# echo $?
0

Second we create the Filesystem resource.

[root@node01 ~]# pcs resource create nfsshare Filesystem device=/dev/vg_cluster/lv_cluster directory=/Nfs fstype=xfs --group group_Nfs
Assumed agent name 'ocf:heartbeat:Filesystem' (deduced from 'Filesystem')
[root@node01 ~]# echo $?
0

Third we create the nfs server and nfs-export resource

[root@node01 ~]# pcs resource create nfs-daemon nfsserver nfs_shared_infodir=/Nfs/nfsinfo nfs_no_notify=true --group group_Nfs
Assumed agent name 'ocf:heartbeat:nfsserver' (deduced from 'nfsserver')
[root@node01 ~]# echo $?
0

[root@node01 ~]# pcs resource create nfs-root exportfs clientspec=192.168.200.0/255.255.255.0 options=rw,sync,no_root_squash directory=/Nfs/BACKUPDIR1 fsid=0 --group group_Nfs
Assumed agent name 'ocf:heartbeat:exportfs' (deduced from 'exportfs')

We also need the VIP (Virtual IP) for the shared resources.

[root@node01 ~]# pcs resource create nfs_ip IPaddr2 ip=192.168.200.123 cidr_netmask=24 --group group_Nfs
Assumed agent name 'ocf:heartbeat:IPaddr2' (deduced from 'IPaddr2')

Finally, the nfs-notify resource is created.

[root@node01 ~]# pcs resource create nfs-notify nfsnotify source_host=192.168.200.123 --group group_Nfs
Assumed agent name 'ocf:heartbeat:nfsnotify' (deduced from 'nfsnotify')
The resources have been created and are running.

[root@node02 ~]# pcs status
Cluster name: cluster_pr
Stack: corosync
Current DC: node01.test.com (version 1.1.16-12.el7_4.8-94ff4df) - partition with quorum
Last updated: Thu May 10 12:54:42 2018
Last change: Thu May 10 12:50:14 2018 by root via cibadmin on node01.test.com

2 nodes configured
7 resources configured

Online: [ node01.test.com node02.test.com ]

Full list of resources:

 vm_fence       (stonith:fence_vmware_soap):    Started node01.test.com
 Resource Group: group_Nfs
     lvm_res    (ocf::heartbeat:LVM):   Started node02.test.com
     nfsshare   (ocf::heartbeat:Filesystem):    Started node02.test.com
     nfs-daemon (ocf::heartbeat:nfsserver):     Started node02.test.com
     nfs-root   (ocf::heartbeat:exportfs):      Started node02.test.com
     nfs_ip     (ocf::heartbeat:IPaddr2):       Started node02.test.com
     nfs-notify (ocf::heartbeat:nfsnotify):     Started node02.test.com

Daemon Status:
  corosync: active/enabled
  pacemaker: active/enabled
  pcsd: active/enabled

The NFS share is running on the second node.

[root@node02 ~]# df -h
Filesystem                         Size  Used Avail Use% Mounted on
/dev/mapper/centos-root             17G  1.3G   16G   8% /
devtmpfs                           1.9G     0  1.9G   0% /dev
tmpfs                              1.9G   39M  1.9G   3% /dev/shm
tmpfs                              1.9G  8.6M  1.9G   1% /run
tmpfs                              1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1                         1014M  164M  851M  17% /boot
tmpfs                              378M     0  378M   0% /run/user/0
/dev/mapper/vg_cluster-lv_cluster   90G   33M   90G   1% /Nfs

The first node is in passive mode, so the NFS share is not present.

[root@node01 ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   17G  1.3G   16G   8% /
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G   54M  1.8G   3% /dev/shm
tmpfs                    1.9G  8.5M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1               1014M  164M  851M  17% /boot
tmpfs                    378M     0  378M   0% /run/user/0

Check the exports from client machine.

[root@srv ~]# showmount -e 192.168.200.123
clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)

There was an error. So, we need to add firewall exceptions.

[root@node02 ~]# firewall-cmd --permanent --add-service=rpc-bind
success
[root@node02 ~]# firewall-cmd --permanent --add-service=mountd
success
[root@node02 ~]# firewall-cmd --permanent --add-port=2049/tcp
success
[root@node02 ~]# firewall-cmd --permanent --add-port=2049/udp
success
[root@node02 ~]# firewall-cmd --reload
success

Now, the command will be run successfully.

[root@srv ~]# showmount -e 192.168.200.123
Export list for 192.168.200.123:
/Nfs/BACKUPDIR1 192.168.200.0/255.255.255.0

The firewall exceptions need to be added on the first node as well.

[root@node01 ~]# firewall-cmd --permanent --add-service=rpc-bind
success
[root@node01 ~]# firewall-cmd --permanent --add-service=mountd
success
[root@node01 ~]# firewall-cmd --permanent --add-port=2049/tcp
success
[root@node01 ~]# firewall-cmd --permanent --add-port=2049/udp
success
[root@node01 ~]# firewall-cmd --reload
success

Testing NFS share


[root@srv ~]# mount  192.168.200.123:/Nfs/BACKUPDIR1 nfsshare
[root@srv ~]# df -h
Filesystem                       Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root             50G  8.0G   42G  16% /
devtmpfs                         2.9G     0  2.9G   0% /dev
tmpfs                            2.9G   80K  2.9G   1% /dev/shm
tmpfs                            2.9G   17M  2.9G   1% /run
tmpfs                            2.9G     0  2.9G   0% /sys/fs/cgroup
/dev/mapper/rhel-home            1.3T  253G 1019G  20% /home
/dev/sda1                        497M  119M  379M  24% /boot
192.168.200.123:/Nfs/BACKUPDIR1   90G   33M   90G   1% /root/nfsshare

[root@srv ~]# ls /root/nfsshare/
BACKUPDIR2  BACKUPDIR4  hello_world1  hello_world3  hello_world5
BACKUPDIR3  BACKUPDIR5  hello_world2  hello_world4

Changing the node02 to standby mode.

[root@node01 ~]# pcs cluster standby node02.test.com

We can still access the NFS share and list the contents.

[root@srv ~]# ls /root/nfsshare/
BACKUPDIR2  BACKUPDIR4  hello_world1  hello_world3  hello_world5
BACKUPDIR3  BACKUPDIR5  hello_world2  hello_world4

So, we have successfully tested the Cluster.