Part 4: Configure Apache & Cluster Resources for High Availability

In this article we will see how to install Apache Web Server and then configure cluster resources using pcs command to achieve high availability of web service. And this post is final and 4rth part of our Apache High Availability Cluster Configuration series; you can find previous articles on below links:

  • Part 1: Basic Concepts of High Availability Cluster
  • Part 2: Apache High Availability LAB Initial Setup & Configuration
  • Part 3: iSCSI Storage Server & Initiator Configuration
  • Part 4: Configure Apache & Cluster Resources for High Availability
  • Part 4: Configure Apache & Cluster Resources for High Availability

    Apache Server

    Before we start web server installation we need to format and mount newly created iscsi partition that we attached on all nodes coming from storage server.

    Step 1: Create Partition

    fdisk /dev/sdb

    Apache Data Directory Partitioning Using Fdisk
    Apache Data Directory Partitioning Using Fdisk

    pvcreate /dev/sdb1

    vgcreate data_vg /dev/sdb1

    lvcreate -l 100%FREE -n data_lv data_vg

    Step 2: Format with ext4

    mkfs.ext4 /dev/mapper/data_vg-data_lv

    Step 3: Install Apache webserver on all nodes using yum

    yum install httpd -y

    Step 4: Edit configuration file

    Open httpd.conf file using vi editor and add following lines at the very bottom. perform same steps on all nodes.

    vi /etc/httpd/conf/httpd.conf

    Apache Config

    Step 5: Mount Apache Data Directory and Set Selinux Policies

    Mount apache webserver data directory on /dev/mapper/data_vg-data_lv logical volume which is available via iscsi shared storage storage.

    mount /dev/mapper/data_vg-data_lv /var/www/html

    Set Selinux Policies for apache data directory

    restorecon -R /var/www

    Now un-mount because later cluster will mount it automatically

    umount /dev/mapper/data_vg-data_lv

    Step 6: Allow in Firewall

    Open firewall ports of apache web server in os firewall

    firewall-cmd --permanent --add-service=http
    firewall-cmd --reload

    Installing and configuring Pacemaker

    Now it’s time to install cluster software (Pacemaker) on all nodes using below command

    Step 1: Install required packages.

    Enter below command on all nodes to install cluster software

    yum install pcs pacemaker -y

    • pcs is stands for Pacemaker Configuration System, which is command-line tool used to view and modify a cluster configuration.

    Step 2: Firewall Rules

    Before we go further, you must add firewall rule to allow all cluster applications traffic . Add below firewall rules and restart firewall service on all of cluster nodes to have smooth communication between nodes.

    firewall-cmd --permanent --add-service=high-availability
    firewall-cmd --add-service=high-availability
    firewall-cmd --reload

    Step 3: Start The Cluster Service

    Start pcsd service and enable it on startup. Run below command on all three nodes

    systemctl start pcsd
    systemctl enable pcsd

    Step 4: Set “hacluster” User Password

    This is cluster administrator account, you must set hacluster password on all nodes. It is recommended to keep hacluster user password same across nodes as it is convenient.

    passwd hacluster

    Step 5: Authenticate Cluster Nodes

    After setting password for hacluster user the cluster is all set to authenticate all nodes. Now run below command on node1.

    pcs cluster auth node1 node2 node3

    Step 6: Creating & Start Cluster

    Create cluster by entering below command on node1.

    pcs cluster setup --name apache_ha node1 node2 node3

    Step 7: Enable and Verify Cluster Service

    use below command to enable cluster service and run at system startup

    pcs cluster start --all
    pcs cluster enable --all

    Continue by verifying cluster service using below command

    pcs cluster status

    Fencing

    The concept of fencing is to simply isolate a cluster node when a particular node misbehaves, this mechanism comes into action to protect the shared cluster data and prevent cluster corruption. It is mandatory to use fencing in production environment, If you do not configure fencing the cluster data can be corrupted in case of malfunction of cluster node.

    • In pacemaker fencing is called STONITH (Shoot The Other Node In The Head).

    we are going to use fence-agents-scsi.x86_64 rpm as fence agent and add STONISH device as we have 1GB iscsi target (/dev/sdc) already attached with cluster nodes in previous steps which is available on storage server.

    Step 1: Install Fencing Agent Package

    yum install fence-agents-scsi.x86_64 -y

    Step 2: Partitioning

    We will use /dev/sdc disk and create LVM named fence_lv to use as a fencing device.

    Fence Device LVM Using fdisk
    Fence Device LVM Using fdisk

    Creating logical volume for fencing device

    pvcreate /dev/sdc1

    vgcreate fence_vg /dev/sdc1

    lvcreate -l 100%FREE -n fence_lv fence_vg

    Step 3: Create Fencing Device

    Create fencing device in cluster using pcs command

    pcs stonith create Fence_Dev fence_scsi pcmk_host_list=”node1 node2 node3″ pcmk_monitor_action=”metadata” pcmk_reboot_action=”off”devices=”/dev/mapper/fence_vg-fence_lv” meta provides=”unfencing” --group WebServer

    Configure Resources

    Cluster Virtual IP

    Configure cluster virtual ip that will make cluster accessible for clients and it will automatically fail over if a node fails.

    pcs resource create Cluster_Vip IPaddr2 ip=10.0.0.100 cidr_netmask=24 --group WebServer

    Step 2: Create Apache File System Resource in Cluster

    Now create Apache File System Resource using pcs command

    pcs resource create Apache_FS Filesystem device=”/dev/mapper/data_vg-data_lv” directory=”/var/www/html” fstype=”ext4″ --group WebServer

    Step 3: Add Apache Cluster Resource

    Add an Apache web server cluster resource with the following command

    pcs resource create Apache_Res apache configfile=”/etc/httpd/conf/httpd.conf” statusurl=”http://127.0.0.1/server-status” --group WebServer

    Apache High Availability Cluster Status
    Apache High Availability Cluster Status

    Testing on client machine, see screen shot below

    Apache Cluster on Linux RHEL 7 / CentOS
    Apache Cluster on Linux RHEL 7 / CentOS