Help Center/ Virtual Private Cloud/ User Guide/ Virtual IP Address/ Virtual IP Address Configuration Example/ Using a Virtual IP Address and Keepalived to Set Up a High-Availability Web Cluster
Updated on 2026-03-23 GMT+08:00

Using a Virtual IP Address and Keepalived to Set Up a High-Availability Web Cluster

Scenarios

A virtual IP address is a private IP address assigned from a VPC subnet. You can use a virtual IP address and Keepalived to set up a high-availability active/standby web cluster. In such a cluster, if the active ECS goes down, the virtual IP address is bound to the standby ECS to provide services. This section describes how to use a virtual IP address and Keepalived to set up a high-availability web cluster.

Architecture

Figure 1 shows a high-availability web cluster using Keepalived. In this architecture, the virtual IP address is bound to both ECS-HA1 and ECS-HA2. To allow ECS-HA1 and ECS-HA2 to access and be accessed from the Internet, an EIP is bound to the virtual IP address. They work as follows:
  1. ECS-HA1 works as the active ECS and provides services accessible from the Internet using the EIP bound to the virtual IP address. ECS-HA2 works as the standby ECS, with no services deployed on it.
  2. If ECS-HA1 goes down, ECS-HA2 takes over services, ensuring service continuity.
Figure 1 A high-availability web cluster using a virtual IP address and Keepalived

Advantages

A high-availability cluster can have one active ECS and one standby ECS or one active ECS and multiple standby ECSs. You can bind a virtual IP address to these ECSs. If the active ECS goes down, the standby ECS becomes the active ECS and continues to provide services.

Notes and Constraints

All servers of the HA cluster must be in the same subnet.

Resource Planning

In this example, the VPC, subnet, virtual IP address, EIP, and ECSs must be in the same region but can be in different AZs.

The following resource details are only for your reference. You can modify them if needed.

Table 1 Resource planning

Resource Type

Quantity

Description

VPC and subnet

1

  • VPC name: Set it as needed. In this example, VPC-A is used.
  • VPC IPv4 CIDR block: Set it as needed. In this example, 192.168.0.0/16 is used.
  • Subnet name: Set it as needed. In this example, Subnet-A01 is used.
  • Subnet IPv4 CIDR block: Set it as needed. In this example, 192.168.0.0/24 is used.

ECS

2

In this example, two ECSs are required for active/standby switchover. Configure the two ECSs as follows:

  • Name: Set this parameter as needed. In this example, the two ECSs are named ECS-HA1 and ECS-HA2.
  • Image: Select an image as needed. In this example, a public image (CentOS 7.8 64bit) is used.
  • System Disk: General Purpose SSD | 40 GiB
  • Data Disk: In this example, no data disk is required. You can attach data disks based on service requirements and ensure data consistency between the two ECSs.
  • Network parameters
    • VPC: Select a VPC. In this example, VPC-A is used.
    • Subnet: Select a subnet. In this example, Subnet-A01 is used.
  • Security Group: Select a security group as needed. In this example, ECS-HA1 and ECS-HA2 are associated with the same security group (Sg-A).
  • Private IP address: Specify 192.168.0.195 for ECS-HA1 and 192.168.0.233 for ECS-HA2.

Virtual IP address

1

Assign a virtual IP address from Subnet-A01.

  • Assignment Mode: Set it as needed. In this example, Automatic is selected.
  • The virtual IP address 192.168.0.177 is used in this example.
  • Bind the virtual IP address to both ECS-HA1 and ECS-HA2.
  • Bind the virtual IP address to EIP-A.

EIP

1

  • Billing Mode: Select a billing mode as needed. In this example, Pay-per-use is used.
  • EIP Name: Set it as needed. In this example, EIP-A is used.
  • EIP: The EIP is randomly assigned. In this example, 124.X.X.187 is used.

Procedure

You can follow the process in Figure 2 to set up a high-availability web cluster using a virtual IP address and Keepalived

Figure 2 Process for setting up a high-availability web cluster