Operations 5 min read

How to Build a Linux HA Cluster with Heartbeat and Nginx for Seamless Failover

This guide walks through installing and configuring a Linux high‑availability (HA) solution using Heartbeat and Nginx, detailing environment setup, host preparation, configuration files, service startup, testing failover, and troubleshooting common errors to achieve reliable, seamless server redundancy.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Build a Linux HA Cluster with Heartbeat and Nginx for Seamless Failover

Introduction

By installing this Linux‑HA software you can achieve a high‑availability solution for a dual‑machine Linux system, providing hot‑standby, seamless failover, and stable, reliable services, ultimately delivering high‑performance RAS (reliability, availability, serviceability).

Test Environment

The experiment uses Heartbeat to build the HA cluster and Nginx as the service under HA.

Chumjtest01 – eth0 172.31.24.199, eth0:1 192.168.1.109, VIP 172.31.24.202

Chumjtest02 – eth0 172.31.24.200, eth0:1 192.168.1.110, VIP 172.31.24.202

Preparation

Edit the /etc/hosts file to add both server IPs.

Disable the firewall ( iptables -F) and SELinux ( setenforce 0).

Install eprl, heartbeat, and libnet.

Main Configuration

Configure the virtual IP (VIP), node files, and HA configuration files (illustrated by the following images).

Copy the configuration files from the master to the slave.

Start Heartbeat

Start the master node first, then the slave.

Master startup status (image):

Check whether Nginx is running:

ps aux | grep nginx
root      6989  0.0  0.0 109336  2036 ?        Ss   17:40   0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx     6990  0.0  0.0 109760  2704 ?        S    17:40   0:00 nginx: worker process
nginx     6991  0.0  0.0 109760  2756 ?        S    17:40   0:00 nginx: worker process
root      6995  0.0  0.0 103252   824 pts/1    S+   17:41   0:00 grep nginx

Slave startup status (image):

Testing

Create a simple HTML page under Nginx on the master and access it.

Do the same on the slave.

Access the VIP address; initially the page is served by the master.

After disabling the master’s network (firewall), the HA log shows “We are dead”, indicating the master has failed.

Slave logs show Nginx started, and the VIP now serves the page from the slave (image):

Troubleshooting

ERROR: Client child command [/usr/lib/heartbeat/ipfail] is not executable – on 64‑bit systems place the command under /usr/lib64/heartbeat/ipfail and reference it in ha.cf.

ERROR: Illegal directive [node ] in /etc/ha.d//ha.cf – ensure the ucast eth0 172.31.24.200 network interface matches the configuration.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

HeartbeatLinux HA
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.