Showing posts with label VMware. Show all posts
Showing posts with label VMware. Show all posts

Thursday, September 28, 2023

Configure Active Directory with BIND as DNS Server

If we are configuring Windows Active Directory, then it is always preferable to use the DNS server from Windows server as well. However, for test purposes I have setup a Cent OS 7 server as a DNS server running BIND and a separate Windows 2016 server running Active Directory services. 

The primary reason for this setup was to change the FQDN of my ESXi server to the domain (prv.com) that I had setup in my DNS server running BIND. After changing the hostname (srv) and domain name (prv.com), the FQDN of ESXi server was srv.prv.com and the vCenter was vc.prv.com. Now, I wanted to test authentication of the ESXi and vCenter servers through Active Directory. So, I setup a Windows server and configured Active Directory services but did not add DNS services. In this blog we are going to configure the linux DNS server and authenticate the vCenter and ESXi servers using AD authentication services. 


The details of the servers are as follows:
  • ns01                   192.168.2.1            ns01.prv.com
  • ns02                   192.168.2.2            ns02.prv.com
  • ns03                   192.168.2.3            ns03.prv.com
  • vCenter              192.168.2.181        vc.prv.com
  • ESXi server        192.168.2.208       srv.prv.com
  • AD server           192.168.2.35         dc01.prv.com
After changing the FQDN of the ESXi server, I added the A and PTR records for the vCenter, ESXi server and the AD server in the DNS server as following.

 [root@ns01 ~]# cat /var/named/zones/forward.prv  
 $TTL 86400  
 @    IN   SOA   ns01.prv.com.  root.prv.com. (  
         2018110521;Serial  
         3600   ;Refresh  
         1800   ;Retry  
         604800  ;Expire  
         86400   ;minimum TTL  
 )  
 @                IN   NS   ns01.prv.com.  
 @                IN   NS   ns02.prv.com.  
 @                IN   NS   ns03.prv.com.  
 ns01              IN   A    192.168.2.1
 ns02              IN   A    192.168.2.2  
 ns03              IN   A    192.168.2.3  
 vc                IN   A    192.168.2.181  
 srv               IN   A    192.168.2.208  
 dc01              IN   A    192.168.2.35  

 [root@ns01 ~]# cat /var/named/zones/reverse.prv  
 $TTL 86400  
 @    IN   SOA   ns01.prv.com. root.prv.com. (  
         2018110513 ;Serial  
         3600    ;Refresh  
         1800    ;Retry  
         604800   ;Expire  
         86400   ;Minimum TTL  
 )  
 @     IN   NS    nso1.prv.com  
 @     IN   NS    ns02.prv.com.  
 @     IN   NS    ns03.prv.com.  
 @     IN   PTR   prv.com.  
 1     IN   PTR   ns01.prv.com.  
 2     IN   PTR   ns02.prv.com.  
 3     IN   PTR   ns03.prv.com.  
 181   IN   PTR   vc.prv.com.   
 208   IN   PTR   srv.prv.com.  
 35    IN   PTR   dc01.prv.com.  

Now, I try to join the ESXi server to the AD, however, an error was thrown saying the server could not join AD.

After a few tries I decide to check the logs from ESXi and the DNS server as well. After running tcpdump on both the servers, I try to join the ESXi server to the AD again. Then, the following logs show up:

NS01

 15:27:21.388453 IP srv.prv.com.51314 > ns01.prv.com.domain: 6822+ A? dc01.prv.com. (30)  
 15:27:21.388769 IP ns01.prv.com.domain > srv.prv.com.51314: 6822* 1/3/3 A 192.168.200.35 (151)  
 15:27:21.409225 ARP, Request who-has 192.168.200.234 tell srv.prv.com, length 46  
 15:27:21.487515 IP srv.prv.com.60836 > ns01.prv.com.domain: 38511+ SRV? _ldap._tcp.dc._msdcs.DC01.PRV.COM. (51)  
 15:27:21.487808 IP ns01.prv.com.domain > srv.prv.com.60836: 38511 NXDomain* 0/1/0 (96)  

ESXi

 09:42:21.388352 IP srv.prv.com.51314 > ns01.prv.com.domain: 6822+ A? dc01.prv.com. (30)  
 09:42:21.388870 IP truncated-ip - 97 bytes missing! ns01.prv.com.domain > srv.prv.com.51314: 6822* 1/3/3 A 192.168.200.35 (151)  
 09:42:21.487656 IP srv.prv.com.60836 > ns01.prv.com.domain: 38511+ SRV? _ldap._tcp.dc._msdcs.DC01.PRV.COM. (51)  

The communication between srv.prv.com (ESXi server) and ns01.prv.com (DNS server) can be broken down as follows:
  • srv.prv.com is sending a query to ns01.prv.com asking for the A record details (hostname to IP) of dc01.prv.com which is the AD server.
  • ns01.prv.com then sends a reply saying that the IP of dc01.prv.com is 192.168.2.35 as per the A record found in the zone file in the DNS server.
  • Then srv.prv.com sends a query to ns01.prv.com asking for the SRV record details of "_ldap._tcp.dc._msdcs.DC01.PRV.COM."
  • ns01.prv.com replies with NXDomain, meaning "_ldap._tcp.dc._msdcs.DC01.PRV.COM" is non-existent, it does not exist as there is no record of it in the zone file in the DNS server.
After googling for an hour or so, I found this link that has detailed steps to add records in the DNS zone file. These entries are required to allow AD authentication services to be used along with BIND DNS. Then I modified the forward zone file to add the missing SRV records:

 [root@ns01 ~]# cat /var/named/zones/forward.prv  
 $TTL 86400  
 @    IN   SOA   ns01.prv.com.  root.prv.com. (  
         2018110522;Serial  
         3600   ;Refresh  
         1800   ;Retry  
         604800  ;Expire  
         86400   ;minimum TTL  
 )  
 @                          IN   NS   ns01.prv.com.  
 @                          IN   NS   ns02.prv.com.  
 @                          IN   NS   ns03.prv.com.  
 ns01                       IN   A    192.168.2.1  
 ns02                       IN   A    192.168.2.2  
 ns03                       IN   A    192.168.2.3
 vc                         IN   A    192.168.2.181   
 srv                        IN   A    192.168.2.208  
 dc01                       IN   A    192.168.2.35  
 _ldap._tcp.pdc._msdcs      IN   SRV   0 100  389  dc01.prv.com.  
 _ldap._tcp.gc._msdcs       IN   SRV   0 100  3268 dc01.prv.com.  
 _kerberos._tcp.dc._msdcs   IN   SRV   0 100  88   dc01.prv.com.  
 _ldap._tcp.dc._msdcs       IN   SRV   0 100  389  dc01.prv.com. 

Then I restarted the named service for the changes to be reflected.

Now, when I try to join the ESXi and vCenter to AD server with the following credentials, I finally succeed.

Saturday, December 29, 2018

Security: Palo Alto Virtual Appliance HA Test

I wanted to test the High Availability features of Palo Alto Virtual Appliance (version - PAN OS 8.0) firewall, so I have deployed two appliances named PA-HA-01 and PA-HA-02 in a single host running ESXi 6.7 managed by a vCenter Appliance 6.7. This is just a simple Active-Passive HA setup with successful tests of configuration synchronization.

It is better to run those two appliances in different hosts for better availability but I have to manage with a single host, so I have made some changes in the vSwitch which I will discuss below.

Palo Alto HA feature requires two separate control and data networks to be setup. There is also the management network for the appliances. So I have setup a vSwitch named vSwitch2 in the host without any uplink physical ports from the server. And then I created a Port Group named PA-HA. The above mentioned data and control network will be utilizing this Port Group (PA-HA). It should be noted that we are not using any physical uplink ports in the vSwitch2 configuration, so the data and control networks from both the appliances will communicate each other through the vSwitch2. 

In production environments, where two virtual appliances are deployed in two different hosts, the HA data and control networks would communicate with each other through dedicated physical uplink ports. 



Server Configuration



vCenter: vc2.prv.com
ESXi host: srv.prv.com

Virtual Appliance Configuration

PA-HA-01


Management IP: 192.168.200.3 (vNIC 1)
Primary Control Link IP: 192.168.5.3 (vNIC 3)
Primary Data Link IP: 192.168.6.3 (vNIC 4)
Device Priority: 77

PA-HA-02


Management Network: 192.168.200.4 (vNIC 1)
Primary Control Link IP: 192.168.5.4 (vNIC 3)
Primary Data Link IP: 192.168.6.4 (vNIC 4)
Device Priority: 100

We can also setup secondary control and data links but I have omitted them as this is optional.


We can see in the above image the details of the PA-HA-01 Appliance.


Then the details of the PA-HA-02 Appliance.

The images below show the details of the Virtual Machine's hardware. Network adapter 1 is used by the Palo Alto management interface which we will access through the browser. Network adapters 3 and 4 are Control and Data Links respectively for both the appliances.




Interface Configuration


So now we access the web interface of the PA-HA-01 through the IP 192.168.200.3. When we select the Network tab and the Interfaces section we can see the three interfaces. We have seen above that there are four network adapters for both the appliances, but we can see below that there are only three interfaces. This is because the first interface is used by the Appliance management and provides the web interface shown below through the IP (192.168.200.3).

I have already setup the interfaces ethernet1/2 and ethernet 1/3 as Interface Type "HA". 


We can see similar setup in the PA-HA-02 Appliance below when browsing through the management IP 192.168.200.4. 


We change the Interface Type by clicking the interface name and select HA in the Interface Type as shown below. There are other options such as Tap, Virtual Wire, Layer2 and Layer3 as well.



High Availability Configuration



The HA configuration dashboard shows us various configuration options in the above image. Under General tab, the first Setup option gives us the options of enabling HA, config sync and the peer HA1 IP address. Since this is the first appliance (192.168.200.3), the peer HA1 IP address is the second appliance Control Link IP (192.168.5.4).  

The Control Link option lets us choose the Port (ethernet1/2) and IP address (192.168.5.3).

The Data Link option has similar configuration options - Port (ethernet1/3) and IP address (192.168.6.3).

Then in the Election settings, we can change the device priority. For PA-HA-01, I have set the priority to 77 and for PA-HA-02 the priority is set to 100. The lower priority appliance will be active in the HA while the higher priority appliance will be passive. As per our configuration, PA-HA-01 will be active with priority 77 and PA-HA-02 will be passive with priority 100.

There are other options as well but we will not make further changes in the HA configuration.




In the second appliance (PA-HA-02) with management IP 192.168.200.4, under General tab, in the first Setup option the first appliance's Control Link IP (192.168.5.3) will be the peer HA1 IP address.

The Control Link option has the Port (ethernet1/2) and IP address (192.168.5.4).

The Data Link option has similar configuration options - Port (ethernet1/3) and IP address (192.168.6.4).

The device priority as stated above is 100 making this appliance passive.

The HA configuration as stated above for both the appliances can be viewed in the below images.










Verify Configuration


After completing the HA configuration, we can add the High Availability widget from the Widgets drop down box from the Dashboard tab on both the appliances to monitor the HA status.

In the below image, we can see that the local appliance (192.168.200.3 / PA-HA-01) is the Active Node and the peer (192.168.200.4 / PA-HA-02) is the Passive Node.



Similarly, as shown in the second appliance (192.168.200.4 / PA-HA-02), we can see that the local appliance is the Passive Node and the peer (192.168.200.3 / PA-HA-01) is the Active Node.




HA Configuration Synchronization Test


For testing the HA configuration, I have simply created three Zones under the Network tab named Support_LAN, DMZ, ISP in the Active Node.


Then I commit the changes made in the Active Node, as shown below.



After the commit is successful, we can see in the HA widget the running configuration synchronization is in process, which means the changes made in the Active Node is being saved in the Passive Node. 


Then, we can finally verify the configuration in the Passive Node. The three zones have been created in the Passive Node as well.



Thus, we have successfully completed this simple HA configuration in Palo Alto Virtual Appliances. In future blog posts I hope to post more PA or other security related content.

Tuesday, May 22, 2018

vSphere: Process Lock Issue

Recently, we faced an issue in vSphere 6.5, after cancelling an OVF export mid-process. In this blog we will go through the troubleshooting process in detail and the resolution. 


The Issue


One of our customers exported a Virtual Machine from vCenter and cancelled the process before completion. Then the VM could not be powered ON. The error received was:

 Error Stack:   
   An error was received from the ESX host while powering on VM TEST-VM.  
  Failed to start the virtual machine.  
  Module 'Disk' power on failed.   
  Cannot open the disk '/vmfs/volumes/5753f99f-d235ca6c-a280-d89d6779a96c/TEST-VM/TEST-VM_1.vmdk' or one of the snapshot disks it depends on.   
  Failed to lock the file  
  File system specific implementation of LookupAndOpen[file] failed  
  File system specific implementation of LookupAndOpen[file] failed  
  File system specific implementation of LookupAndOpen[file] failed  
  File system specific implementation of OpenFile[file] failed  

On checking the vmkernel log file we find the below issue.

 [root@test:/var/log] tail -f vmkernel.log   
 num 1 gblnum 0 gblgen 0 gblbrk 0] alloc owner 3833856  
 2019-11-12T11:38:08.515Z cpu18:72666)DLX: 4312: vol 'RAID5_DATASTORE2', lock at 94683136: [Req mode 1] Checking liveness:  
 2019-11-12T11:38:08.515Z cpu18:72666)[type 10c00001 offset 3763970 v 55, hb offset 3686970  
 gen 745, mode 2, owner 00000000-00000000-0000-000000000000 mtime 6167 num 1 gblnum 0 gblgen 0 gblbrk 0]  

On running the following command we can see that there is a Lock of type 10c00001 and mode 0. However the owner is 00000000-00000000-0000-000000000000.

 [root@test:/vmfs/volumes/5753f99f-d235ca6c-a280-d89d6779a96c/TEST-VM] vmkfstools -D /vmfs/volumes/5753f99f-d235ca6c-a280-d89d6779a96c/TEST-VM/TEST-VM.vmx   

 Lock [type 10c00001 offset 60387328 v 456, hb offset 3686970 gen 3, mode 0, owner 00000000-00000000-0000-000000000000 mtime 12601 num 0 gblnum 0 gblgen 0 gblbrk 0]   
 Addr <4, 121, 70>, gen 142, links 1, type reg, flags 0, uid 0, gid 0, mode 100755 len 3486, nb 1 tbz 0, cow 0, newSinceEpoch 1, zla 2, bs 8192  

The different mode types described on VMware site are as following:

  • mode 0 = no lock
  • mode 1 = is an exclusive lock (vmx file of a powered on VM, the currently used disk (flat ir delta), *vswp, etc)
  • mode 2 = is a read-only lock (e.g. on the ..-flat.vmdk of a running VM with snapshots)
  • mode 3 = is a multi-writer lock. (e.g. used for MSCS clusters disks or FT VMs)

We can determine the owner (host) where the process is locked by running the following command with the offset value from previous output (offset 3686970).

 [root@test: /vmfs/volumes/5753f99f-d235ca6c-a280-d89d6779a96c/TEST-VM] hexdump -C /vmfs/volumes/5753f99f-d235ca6c-a280-d89d6779a96c/.vh.sf -n 512 -s 3686970  

 003ba000 00 40 5d 7e 00 00 00 00 00 00 00 00 89 00 00 00 |……;………|  
 003ba010 00 00 00 00 c9 dd 7f a1 5c 01 00 00 89 e8 ba 55 |….._../…….|  
 003ba020 e1 ff 30 43 c1 dd 7f 8e 3d 3a 21 1a a4 a6 8a 99 |..m....S...….|  
 003ba030 e0 00 00 00 9d 04 00 00 00 00 00 00 00 00 00 00 |…......……..|  
 003ba040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |…………….|  

By checking the MAC address of the hosts, we can verify the host where the process is locked. In this case it was the same host where the VM was located. The MAC address of one the host's NIC included (7f 8e 3d 3a), as indicated in the above output.


Troubleshooting Steps


First, we removed the VM (TEST-VM) from inventory. Then registered the VM to the same host. The problem was still persistent.

Second, removed the VM from inventory and created a new VM with the same virtual drives from the problematic VM (TEST-VM). While trying to power ON the new VM the problem still persisted.

Third, we restarted the ESXi host daemon 'hostd' and vCenter Agent 'vpxa' services on the host to no avail.

 /etc/init.d/hostd restart  
 /etc/init.d/vpxa restart  

Fourth, we restarted all the management services on the host. However, the problem was not resolved.

 services.sh restart  

Fifth, we rebooted the host and tried to power ON the VM. The issue was still there.


The Resolution


Since the OVF export process was run from vCenter, there was still a process that was locking the VM in vCenter and we were unable to power on the VM. We had already rebooted the host, so we could conclude that the host was not locking the VM.

We rebooted the vCenter and finally we could power ON the VM without any issues.



References



Tuesday, May 15, 2018

vSphere: ESXi Space Reclaim

In a thin provisioned Datastore before ESXi 6.5 in format VMFS 5, we need to reclaim unused storage blocks manually. To confirm that unmap/reclaim is supported, we need to run the following command from a SSH session to the host. 

 # esxcli storage core device vaai status get -d naa  

If the naa details show Delete Status: supported, then we can proceed with unused space reclamation.

The following command executes the unmap procedure and needs to be run from each host mapped with the thin provisioned LUN.

 # esxcli storage vmfs unmap --volume-label=volume_label|--volume-uuid=volume_uuid --reclaim-unit=number  

The command can be run with the option of either volume label -l or volume UUID -u. The option of reclaim-unit is not necessary unless there is a need to change the default value of 200. It is advised to consult with storage provider while using a different reclaim-unit number.

 # esxcli storage vmfs unmap -l DatastoreLabel 

Or

 # esxcli storage vmfs unmap -u 90af8df1-709bc101-8ff9-a90154e32ddff24f

After running the above command from each host, the reclaim command needs to be run from the storage. Then the unused and reclaimed space will be shown and can be used.

Monday, May 14, 2018

vSphere: Unable to add Datastore error

This is a short blog post regarding an issue I faced in VMware ESXi 6.0. I installed the ESXi after creating array from the array controller settings but local datastore was not present. When trying to add the datastore, an error was thrown: 

Call "HostDatastoreSystem.QueryVmfsDatastoreCreateOptions" for object "ha-datastore ...."

After quickly googling the issue, I found out the issue was caused due to existing information on the disk that had been previously used. Even after creating new array this information was not deleted and the vSphere was unable to understand it. So, the datastore was not allowed to be created. 

So to delete the partition and extra data present, I could connect through SSH to the host and use partedUtil utility for this purpose. So, first I enable SSH from the host Configuration tab and Security Profile settings under Software.  




We login to the host and go to the following location and list the partitions.

 [root@localhost:~] cd /vmfs/devices/disks  
 [root@localhost:/dev/disks] pwd  
 /vmfs/devices/disks  

 [root@localhost:/dev/disks] ls  
 naa.600508b1001c17376aeda14dd3174f90  
 naa.600508b1001c17376aeda14dd3174f90:1  
 naa.600508b1001c17376aeda14dd3174f90:2  
 naa.600508b1001c17376aeda14dd3174f90:3  
 vml.0200010000600508b1001c17376aeda14dd3174f904c4f47494341  
 vml.0200010000600508b1001c17376aeda14dd3174f904c4f47494341:1  
 vml.0200010000600508b1001c17376aeda14dd3174f904c4f47494341:2  
 vml.0200010000600508b1001c17376aeda14dd3174f904c4f47494341:3  

We need to change label as msdos.

 [root@localhost:/dev/disks] partedUtil mklabel "/vmfs/devices/disks/naa.600508b1001c17376aeda14dd3174f90" msdos  

Now, we can add the datastore normally and no errors will be thrown. And do not forget to disable SSH after completing your job !

Thursday, February 22, 2018

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.

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.