How to Install and Configure Cluster with Two Nodes in Linux?


In today's era, use of clusters has become increasingly important in field of computing. A cluster is a group of interconnected computers that work together as a single entity. They are used for high-performance computing, data analysis, and other applications where a single computer is not sufficient to handle load. In this article, we will discuss how to install and configure a cluster with two nodes in Linux.

Before we proceed, it's important to understand concept of a cluster. A cluster consists of two or more nodes that work together as a single system. Each node is a separate computer with its own resources, such as CPU, memory, and storage. These nodes are connected to each other through a network, which allows them to communicate and share resources.

To install and configure a cluster with two nodes in Linux, we will be using Pacemaker and Corosync software. Pacemaker is a cluster resource manager that manages availability of services, whereas Corosync is a cluster messaging system that enables communication between nodes. We will be using CentOS 7 as our operating system.

Step 1: Install Pacemaker and Corosync

The first step is to install Pacemaker and Corosync on both nodes. To do this, open terminal and run following command −

sudo yum install pacemaker corosync

Step 2: Configure Cluster

The next step is to configure cluster. We will start by configuring Corosync cluster messaging system. To do this, open file /etc/corosync/corosync.conf in your preferred text editor and add following lines −

totem {
   version: 2
   secauth: off
   cluster_name: mycluster
   transport: udpu
}

nodelist {
   node {
      ring0_addr: <IP address of node 1>
      name: <hostname of node 1>
   }

   node {
      ring0_addr: <IP address of node 2>
      name: <hostname of node 2>
   }
}

In above configuration, replace <IP address of node 1> and <IP address of node 2> with IP addresses of two nodes, and <hostname of node 1> and <hostname of node 2> with hostnames of two nodes.

Next, start Corosync service by running following command −

sudo systemctl start corosync

Step 3: Configure Pacemaker Cluster Resource Manager

The next step is to configure Pacemaker cluster resource manager. To do this, open file /etc/pacemaker/pcs.conf in your preferred text editor and add following lines −

pcs cluster setup --name mycluster <hostname of node 1> <hostname of node 2>
pcs cluster enable --all

In above configuration, replace <hostname of node 1> and <hostname of node 2> with hostnames of two nodes.

Next, start Pacemaker service by running following command −

sudo systemctl start pacemaker

Step 4: Configure Cluster Resources

The final step is to configure cluster resources. We will start by configuring a virtual IP address that will be used to access cluster. To do this, run following command −

pcs resource create virtual_ip ocf:heartbeat:IPaddr2 ip=<IP address of virtual IP> cidr_netmask=24 op monitor interval=30s

In above command, replace <IP address of virtual IP> with IP address of virtual IP.

Next, configure a simple Apache web server that will be used to test cluster. To do this, run following command −

pcs resource create apache ocf:heartbeat:apache

This command will create a cluster resource for Apache web server. You can now access web server by navigating to virtual IP address in your web browser.

Step 5: Verify Cluster Status

To verify that cluster is functioning correctly, run following command −

pcs status

This command will display status of cluster and its resources. You should see that virtual IP address and Apache web server resources are both running on one of nodes.

Step 6: Failover Testing

To test failover capability of cluster, you can simulate a node failure by stopping Pacemaker service on one of nodes. To do this, run following command −

sudo systemctl stop pacemaker

This will cause resources on failed node to be migrated to other node. You can verify this by running pcs status command again. You should see that resources are now running on other node.

Clustering is a powerful tool for increasing performance, availability, and scalability of your applications. By distributing workload across multiple nodes, a cluster can handle a larger number of requests and provide a higher level of service to users.

In addition to basic configuration outlined above, there are many other resources and services that can be added to a cluster, such as databases, load balancers, and storage. Each of these resources requires its own configuration, but basic principles of clustering remain same.

When setting up a cluster, it's important to consider factors such as network bandwidth, node capacity, and resource usage. These factors can impact performance and reliability of cluster, and should be carefully evaluated before deploying cluster in a production environment.

Another important consideration when setting up a cluster is security. A cluster can be a valuable target for attackers, and it's important to ensure that cluster is properly secured. This includes measures such as using strong authentication, encrypting data in transit and at rest, and restricting access to sensitive resources.

One of benefits of using a cluster is ability to scale resources up or down depending on workload. This means that you can add or remove nodes as needed to meet changing demands. When adding a node to an existing cluster, you can use same configuration as existing nodes, which makes process relatively simple.

Another important consideration when setting up a cluster is disaster recovery. In event of a disaster such as a power outage or network failure, it's important to have a plan in place to recover cluster and its resources. This may involve setting up a secondary or backup cluster at a different location, or using cloud-based services for backup and recovery.

When setting up a cluster, it's also important to consider maintenance and management of cluster. This includes tasks such as monitoring resource usage, performing routine backups, and updating software and security patches. Automated tools such as Ansible or Chef can be used to simplify these tasks and ensure that they are performed consistently across all nodes in cluster.

In addition to factors mentioned above, it's also important to consider network topology when setting up a cluster. network topology can impact performance and reliability of cluster, and should be carefully evaluated before deploying cluster in a production environment.

There are several different network topologies that can be used when setting up a cluster, including −

  • Bus topology − In a bus topology, all nodes in cluster are connected to a single cable. This topology is simple and inexpensive, but can be slow and prone to network congestion.

  • Star topology − In a star topology, each node in cluster is connected to a central hub or switch. This topology is more reliable and efficient than a bus topology, but can be more expensive to implement.

  • Ring topology − In a ring topology, each node is connected to nodes on either side of it, forming a ring. This topology is highly reliable, but can be difficult to manage and troubleshoot.

  • Mesh topology − In a mesh topology, each node is connected to multiple other nodes, forming a highly redundant network. This topology is highly reliable and scalable, but can be complex and expensive to implement.

When choosing a network topology for your cluster, it's important to consider factors such as bandwidth, latency, and network congestion. You should also consider potential for network failures and how you will handle them.

In addition to network topology, you should also consider hardware requirements of cluster. This includes factors such as CPU, memory, and storage capacity, as well as types of storage and networking devices that will be used.

Finally, you should also consider software requirements of cluster. This includes operating system, cluster resource manager, messaging system, and any other software that will be used to manage and monitor cluster.

Conclusion

In conclusion, setting up a cluster with two nodes in Linux is a relatively straightforward process. By following steps outlined in this article, you can configure a basic cluster with a virtual IP address and an Apache web server. This configuration can be customized to suit your specific requirements, such as adding more resources or configuring more complex failover scenarios. With right tools and knowledge, you can leverage power of clustering to improve performance, reliability, and availability of your applications.

Updated on: 12-May-2023

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements