Showing posts with label LVM. Show all posts
Showing posts with label LVM. Show all posts

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

Monday, February 5, 2018

Red Hat Cluster Part 5: Extend Shared Storage

Often times we have the requirement to increase the storage size in the servers. In a clustered environment, the process is similar to that of non-clustered environments. However, since we have setup virtualized nodes for cluster setup in VMware vCenter, we have to perform some extra steps. We will discuss these steps in detail in this blog.

Increase the Volume size from Storage

The first step is to increase the size of the volumes that have been configured as shared RDM disks among the nodes. I have already increased the size of the zvol from 10 GB to 15 GB in free NAS and restarted the iSCSI service in the free NAS.

Check shared RDM disk compatibility settings

There are two settings for the disk compatibility in a RDM disk.
  • Physical - The SCSI commands are not operated by the hypervisor, allows for SAN management of the LUN and useful for low level operations.
  • Virtual - The SCSI commands are operated by the hypervisor, so snapshots are supported. Lots of VMware hypervisor features are supported in this mode.
Detailed explanation can be found here and here.

The RDM disks that I have added before have the compatibility mode set as "Virtual".  


If the compatibility mode was set as "Physical", after re-scanning the iSCSI adapter, the shared disk would need to be re-scanned in the operating system and the shared block device size would be increased.

However, since the RDM disk compatibility mode is set to "Virtual", we need to remove the RDM disk from the virtual machine settings, delete files from the datastore and then re-add it for the changes to the disk to be seen. 

Remove the RDM disk

Before removing the RDM disk we need to note the "Virtual Device Node" controller and the SCSI(X:Y) settings. Here the disk is using "SCSI controller 2" with "SCSI(2:0)" settings.

But first we need to bring the cluster services down and power off both the nodes.

Then we delete the disk and select "Delete files from datastore" option to completely remove the previous disk size settings.



Re-scan the iSCSI Adapter in the Host

The next step is to re-scan the iSCSI software adapter in the ESXi host. We can see in the image below that the changes are imminent after the re-scan.



Re-add the RDM disk

Now, we can re-add the RDM disk and verify the increased size of the disk. We can see that the new capacity of the LUN is 15 GB.


Then we change the new hard disk settings where the compatibility mode is "Virtual", the sharing mode is "Multi-writer" and the virtual device node is set to the same settings as we previously noted which is "SCSI controller 2" and "SCSI(2:0)".

We remove and re-add the RDM disk on both the nodes.

Extend the LVM

We can then power on the virtual machines and extend the disks from the OS. First we need to check that the disk block device size has increased from the terminal by issuing the command "lsblk". Although on boot the disk size should have increased, if the disk size has not increased we can issue the following command to re-scan the device:

 [root@N2 ~]# echo "1" > /sys/class/block/sdc/device/rescan  

We can now check and verify that the block device size has increased to 15 GB.

 [root@N2 ~]# lsblk  
 NAME             MAJ:MIN RM SIZE RO TYPE MOUNTPOINT  
 sr0              11:0  1 1024M 0 rom  
 sda              8:0  0  50G 0 disk  
 ├─sda1             8:1  0 500M 0 part /boot  
 └─sda2             8:2  0 49.5G 0 part  
  ├─vg_redhat-lv_root (dm-0) 253:0  0 45.6G 0 lvm /  
  └─vg_redhat-lv_swap (dm-1) 253:1  0 3.9G 0 lvm [SWAP]  
 sdb              8:16  0  1G 0 disk  
 sdc              8:32  0  15G 0 disk /Test  

The logical volume can be extended by issuing the following commands. These commands should be run on only one of the nodes as it is a shared disk:

 [root@N2 ~]# pvresize /dev/sdc  
 [root@N2 ~]# vgextend shared_vg /dev/sdc  
 [root@N2 ~]# lvresize -l +100% -n ha_lv shared_vg  

Finally we resize the ext4 file system.

 [root@N2 ~]# resize2fs /dev/shared_vg/ha_lv  

 [root@N2 ~]# df -h  
 Filesystem                     Size Used Avail Use% Mounted on  
 /dev/mapper/vg_redhat-lv_root  45G  11G  33G   25%  /  
 tmpfs                          1.9G 26M  1.9G  2%   /dev/shm  
 /dev/sda1                      485M 39M  421M  9%   /boot  
 /dev/mapper/shared_vg-ha_lv    15G  172M 14G   1%   /Test  

Finally, we have increased and verified the size of the shared storage in a clustered environment.