The cart is empty

Clustering is a technique that allows a group of independent servers to work together as a single system to ensure higher availability, resilience, and scalability. In this article, we'll focus on configuring a cluster environment on the CentOS 7 operating system using Pacemaker and Corosync tools. These tools provide a flexible and robust solution for managing cluster environments.

System Preparation

Before configuring the cluster environment, several preparatory steps need to be performed on all servers that will be part of the cluster.

  1. System Update: Ensure all your servers are running on the latest version of CentOS 7. You can do this by running the command sudo yum update and restarting the system.

  2. Setting Hostname: Each server should have a unique hostname. Set the hostname using the command sudo hostnamectl set-hostname node1 (replace "node1" with your desired hostname).

  3. Network Configuration: Ensure all servers have a static IP address and correctly configured network settings.

Installation and Configuration of Corosync and Pacemaker

  1. Software Installation: Install Pacemaker and Corosync on all servers using the command:

    sudo yum install pacemaker corosync pcs psmisc policycoreutils-python
    
  2. Setting Password for hacluster User: Set a password for the hacluster user using the command sudo passwd hacluster. This password will be used for authentication between nodes in the cluster.

  3. Starting Services: Enable and start Corosync, Pacemaker, and pcsd (configuration service) using the following commands:

    sudo systemctl enable pcsd
    sudo systemctl enable corosync
    sudo systemctl enable pacemaker
    sudo systemctl start pcsd
    sudo systemctl start corosync
    sudo systemctl start pacemaker
    
  4. Node Authentication: On one of the nodes, authenticate all nodes in the cluster using the command:

    sudo pcs cluster auth node1 node2 -u hacluster -p <password>
    

    Replace "node1 node2" with your node names and <password> with the password set for hacluster.

  5. Cluster Setup: After successful authentication, set up the cluster configuration using the command:

    sudo pcs cluster setup --name my_cluster node1 node2
    

    Change "my_cluster" to your cluster name and "node1 node2" to your node names.

  6. Starting the Cluster: Finally, start the cluster services on all nodes using the command:

    sudo pcs cluster start --all
    

 

Configuration of Cluster Resources

After successful installation and initialization of the cluster, it's time to add resources that will be monitored and managed by Pacemaker.

  1. Adding Resources: You can add resources using the pcs resource create command. For example, to add a simple virtual IP resource:
    sudo pcs resource create VirtualIP ocf:heartbeat:IPaddr2 ip=192.168.1.100 cidr_netmask=24 op monitor interval=30s
    ​
    Replace the IP address with the address that will serve as the shared IP for services in the cluster.
     

 

Testing and Managing the Cluster

After configuring resources, it's essential to test if the cluster functions as expected. You can try stopping services on one node and observe how Pacemaker automatically moves resources to another available node.

  • Use the pcs status command to display the cluster status.
  • For managing cluster resources, you can use various pcs resource commands like enable, disable, move, etc.

 

Configuring a cluster environment with Pacemaker and Corosync on CentOS 7 requires careful preparation and configuration. After successfully completing these steps, you'll have a robust and resilient cluster environment capable of handling failures and ensuring high availability of your critical services.