High-availability virtual IP (HaVip)

更新时间:
复制 MD 格式

A high-availability virtual IP address (HaVip) keeps your service IP unchanged during failover between ECS instances in the same zone.

Why use an HaVip when Keepalived already supports high availability for virtual IPs?

In traditional data centers, Keepalived uses VRRP to elect a new primary instance during failover. The new primary binds the virtual IP to its network interface and sends a gratuitous ARP broadcast. Other devices on the LAN receive this broadcast and update their ARP caches to map the virtual IP to the new primary's MAC address.

Cloud providers use software-defined networking (SDN) and virtualization, where the platform manages IP allocation. Applications cannot modify host IPs directly, and the virtual network terminates ARP at the source, preventing hosts from announcing IP addresses. Alibaba Cloud provides HaVip to solve this.

An HaVip is an independently managed private IP. Set the Keepalived virtual IP to the HaVip address and associate the HaVip with multiple servers. When Keepalived elects a new primary, the system updates the HaVip-to-instance mapping — achieving the same effect as a gratuitous ARP broadcast while keeping the service IP unchanged during failover.

How it works

A typical high-availability cluster consists of one HaVip and two ECS instances in a primary/secondary configuration:

  1. Keepalived configuration: Associate the HaVip with ECS1 and ECS2, and install Keepalived on both. Set virtual_ipaddress to the HaVip address and assign a priority value — higher priority wins the primary election.

  2. Primary election: Keepalived compares priority values via VRRP and elects the higher-priority instance as primary. The system updates the HaVip mapping, and all traffic destined for the HaVip forwards to ECS1.

  3. Failover: ECS1 sends heartbeats to ECS2 at the interval specified by advert_int. If ECS2 misses a heartbeat within the timeout, Keepalived promotes ECS2 to primary. The system updates the HaVip mapping to ECS2, and all traffic shifts accordingly — the service IP remains unchanged.

To enable public access, associate the HaVip with an EIP. Traffic then routes through the EIP to provide highly available internet-facing services.

image

Use an HaVip for failover

Associate an HaVip with ECS instances or elastic network interfaces (ENIs) in the same vSwitch. Combined with Keepalived, this keeps your service IP unchanged during failover.

  • Quota: Log on to the Quota Center console and apply for HaVip creation permission. A quota value of 1 means HaVip creation is enabled. Each account can create up to 50 HaVips.

  • IP version: HaVip supports only IPv4.

  • Associated resources:

    • An HaVip can be associated with only one resource type at a time. To switch types, disassociate the current resources first.

    • When you associate an HaVip with an ENI, make sure the ENI is attached to an ECS instance.

    • If an associated ECS instance or ENI is deleted, the system automatically disassociates the HaVip from that resource.

    • Detaching a secondary ENI from an ECS instance does not affect the HaVip-to-ENI association.

Console

Create and associate an HaVip

  1. Navigate to the VPC Console - HaVip page. Select the region of your ECS instances, and then click Create HaVip.

  2. Select the VPC and vSwitch to which the ECS instances belong. You can automatically assign a private IP address from the vSwitch's CIDR block or specify an unassigned IP address.

  3. Install Keepalived on the primary and standby ECS instances, and run systemctl start keepalived to start Keepalived.

    Keepalived installation example

    This example installs Keepalived on CentOS-based ECS instances in a two-node primary/secondary cluster. Use Keepalived V1.2.15 or later.

    If you have multiple standby ECS instances, you must declare the IP addresses of all peer instances in each ECS instance's unicast_peer.
    Report issues and find troubleshooting resources on Keepalived GitHub.

    Primary Server Configuration

    1. Log on to the primary ECS instance.

    2. Run yum install keepalived to install Keepalived.

    3. Run vim /etc/keepalived/keepalived.conf to edit the keepalived.conf file.

      This example shows only the parameters that require modification. Configure for your specific instance. Do not overwrite your existing keepalived.conf file with this example.
      ! Configuration File for keepalived
      vrrp_instance VI_1 {
          state MASTER            # Set as the primary instance.
          interface eth0          # The network interface controller (NIC) to which the virtual IP (VIP) address is bound. This example uses eth0.
          virtual_router_id 51    # The virtual_router_id of the primary/standby cluster. Different primary/standby clusters in the same Virtual Private Cloud (VPC) must have different virtual_router_id values.
          nopreempt               # Set to non-preemptive mode.
          priority 100            # The priority. A larger number indicates a higher priority. In this example, the priority is set to 100 to make this the primary instance.
          advert_int 1            # The interval, in seconds, for sending heartbeat packets. A small value can cause frequent failovers or a temporary split-brain due to network jitter. A large value can increase the failover time if the primary instance fails.
          authentication {
              auth_type PASS
              auth_pass 1111
          }
          unicast_src_ip 192.168.0.25     # The private IP address of this instance. This example uses 192.168.0.25.
          unicast_peer {
              192.168.0.26          # The private IP address of the peer instance. This example uses 192.168.0.26. If you have multiple standby ECS instances, list the IP address of each peer instance on a separate line without commas or other separators.
          }
          virtual_ipaddress {
              192.168.0.24          # The virtual IP address. Set this to the IP address of the HaVip. This example uses 192.168.0.24.
          }   
          garp_master_delay 1       # The delay, in seconds, to update the ARP cache after the instance becomes the primary.
          garp_master_refresh 5     # The interval, in seconds, for sending ARP packets.
      
          track_interface {
              eth0                  # The NIC bound to the VIP address. This example uses eth0.
          }
      }
    4. Run systemctl start keepalived to start Keepalived.

    Secondary Server Configuration

    1. Log on to the secondary ECS instance.

    2. Run yum install keepalived to install Keepalived.

    3. Run vim /etc/keepalived/keepalived.conf to edit the keepalived.conf file.

      This example shows only the sections that require modification. Configure for your specific instance. Do not overwrite your existing keepalived.conf file with this example.
      ! Configuration File for keepalived
      vrrp_instance VI_1 {
          state BACKUP            # Set the instance as the secondary instance.
          interface eth0          # The NIC to which the VIP is bound. This example uses eth0.
          virtual_router_id 51    # The virtual_router_id of the primary/secondary cluster. Different primary/secondary clusters in the same VPC must have different virtual_router_id values.
          nopreempt               # Set to non-preemptive mode.
          priority 10             # The priority. A larger value indicates a higher priority. In this example, the priority is set to 10 to configure this instance as the secondary instance.
          advert_int 1            # The interval for sending heartbeat packets, in seconds. If this value is too small, the service is susceptible to network jitter, which can cause frequent failovers and temporary dual-primary scenarios (split-brain). If this value is too large, the failover time may be long after the primary instance fails.
          authentication {
              auth_type PASS
              auth_pass 1111
          }
          unicast_src_ip 192.168.0.26   # The private IP address of this instance. In this example, it is 192.168.0.26.
          unicast_peer {
              192.168.0.25          # The private IP address of the peer instance. In this example, it is 192.168.0.25. You must declare the IP addresses of all peer instances. Each address must be on a separate line, without commas or other separators.
          }
          virtual_ipaddress {
              192.168.0.24          # The virtual IP address. Set this to the IP address of the HaVip. In this example, it is 192.168.0.24.
          }    
          garp_master_delay 1       # The delay, in seconds, to update the ARP cache after this instance becomes the primary instance.
          garp_master_refresh 5     # The interval for sending ARP packets, in seconds.
      
          track_interface {
              eth0                  # The NIC to which the VIP is bound. This example uses eth0.
          }
      }
    4. Run systemctl start keepalived to start Keepalived.

  4. Click the ID of the target HaVip. In the Resources section, click Bind to the right of ECS Instances, and then select the ECS instances or ENIs to associate.

    After the association is complete, you can view the primary and secondary status in the Associated Instance column or in the Resources section of the details page.
  5. Verify the result:

    1. Run the following commands on the primary and secondary instances to create a web test service that returns different results.

      Check the port usage by running the netstat -an | grep 8000 command. If port 8000 is occupied, you need to select another port.

      Primary instance:

      echo "ECS 1" > index.html  # The primary instance returns "ECS 1"
      python3 -m http.server 8000

      Secondary instance:

      echo "ECS 2" > index.html  # The secondary instance returns "ECS 2"
      python3 -m http.server 8000
    2. From another ECS instance in the same VPC, running curl <havip_private_ip>:8000 returns ECS 1. After the primary server stops, it returns ECS 2.

      Ensure that the security groups of the primary and secondary instances allow HTTP traffic from within the same VPC to access port 8000.

Disassociate resources

Click the ID of the target HaVip. In the Resources section, find the target ECS instance or elastic network interface in the Associated resources list, and click Delete Association.

Delete an HaVip

Before you delete an HaVip, make sure it is not associated with any ECS instances, ENIs, or EIPs. In the Actions column for the target HaVip, or on its details page, click Delete.

API

Terraform

Resource: alicloud_havip, alicloud_havip_attachment, alicloud_instance, alicloud_security_group, alicloud_security_group_rule
# Specify the region where you want to create the HaVip.
provider "alicloud" {
  region = "cn-hangzhou"
}

# Specify the ID of the VPC.
variable "vpc_id" {
  default = "vpc-bp1k******" # Replace with the actual ID of your VPC.
}

# Specify the vSwitch ID.
variable "vswitch_id" {
  default = "vsw-bp1y******" # Replace with the actual ID of your vSwitch.
}

# Specify the instance type.
variable "instance_type" {
  default = "ecs.e-c1m1.large"
}

# Specify the image ID.
variable "image_id" {
  default = "aliyun_3_x64_20G_alibase_20221102.vhd"
}

# Create an HaVip.
resource "alicloud_havip" "test_havip" {
  ha_vip_name = "test_havip_name"
  vswitch_id  = var.vswitch_id
  ip_address  = "192.168.0.24" # Specify an IP address for the HaVip from the vSwitch CIDR block. If not specified, the system assigns one.
}

# Create a security group.
resource "alicloud_security_group" "test_security_group" {
  security_group_name = "test_security_group_name"
  vpc_id              = var.vpc_id
}

# Create a security group rule. You need to adjust the protocol, source, and port based on your actual traffic.
resource "alicloud_security_group_rule" "allow_vpc_tcp" {
  type              = "ingress"
  ip_protocol       = "tcp"
  nic_type          = "intranet"
  policy            = "accept"
  port_range        = "8000/8000"
  priority          = 1
  security_group_id = alicloud_security_group.test_security_group.id
  cidr_ip           = "192.168.0.0/24"
}

# Create the primary server. 
resource "alicloud_instance" "test_master_instance" {
  instance_name        = "test_master_instance_name"
  vswitch_id           = var.vswitch_id
  instance_type        = var.instance_type
  image_id             = var.image_id
  system_disk_category = "cloud_essd"
  security_groups      = [alicloud_security_group.test_security_group.id]
  user_data = base64encode(<<-EOT
    #!/bin/sh
    yum install keepalived -y

    printf '! Configuration File for keepalived
    vrrp_instance VI_1 {
        state MASTER            # Set as the primary instance.
        interface eth0          # The network interface to which the virtual IP address is bound. This example uses eth0.  
        virtual_router_id 51    # The virtual_router_id of the primary/secondary cluster. Different clusters in the same VPC require different virtual_router_id values.
        nopreempt               # Set to non-preemptive mode.
        priority 100            # The priority. A higher value indicates a higher priority. This example sets the priority to 100 to make this instance the primary instance.
        advert_int 1            # The interval at which heartbeat messages are sent, in seconds. A small value makes the configuration susceptible to network jitter, which can cause frequent failovers or temporary split-brain scenarios. A large value can increase the failover time after the primary instance fails.
        authentication {
            auth_type PASS
            auth_pass 1111
        }
        unicast_src_ip 192.168.0.25     # The private IP address of this instance. This example uses 192.168.0.25.
        unicast_peer {
            192.168.0.26                # The private IP address of the peer instance. This example uses 192.168.0.26. If you have multiple secondary ECS instances, declare the IP address of each peer instance on a new line. Do not use commas or other separators.
        }
        virtual_ipaddress {
            192.168.0.24                # The virtual IP address. Set this to the HaVip's IP address. This example uses 192.168.0.24.
        }   
        garp_master_delay 1             # The delay in seconds before updating the ARP cache after a failover to this instance. 
        garp_master_refresh 5           # The interval at which ARP messages are sent, in seconds. 

        track_interface {
            eth0                        # The network interface to which the virtual IP address is bound. This example uses eth0.
        }
    }' > /etc/keepalived/keepalived.conf
    systemctl start keepalived
  EOT
  )                                           # Specify the initialization script for the primary server to install Keepalived.
  private_ip           = "192.168.0.25"       # Specify the private IP address of the primary server.
  instance_charge_type = "PostPaid"           # Set the billing method to pay-as-you-go.
  spot_strategy        = "SpotWithPriceLimit" # Set as a spot instance with a price limit.
}

# Create the secondary server. 
resource "alicloud_instance" "test_backup_instance" {
  instance_name        = "test_backup_instance_name"
  vswitch_id           = var.vswitch_id
  instance_type        = var.instance_type
  image_id             = var.image_id
  system_disk_category = "cloud_essd"
  security_groups      = [alicloud_security_group.test_security_group.id]
  user_data = base64encode(<<-EOT
    #!/bin/sh
    yum install keepalived -y

    printf '! Configuration File for keepalived
    vrrp_instance VI_1 {
        state BACKUP            # Set as the secondary instance.
        interface eth0          # The network interface to which the virtual IP address is bound. This example uses eth0.  
        virtual_router_id 51    # The virtual_router_id of the primary/secondary cluster. Different clusters in the same VPC require different virtual_router_id values.
        nopreempt               # Set to non-preemptive mode.
        priority 10             # The priority. A higher value indicates a higher priority. This example sets the priority to 10 to make this instance the secondary instance.
        advert_int 1            # The interval at which heartbeat messages are sent, in seconds. A small value makes the configuration susceptible to network jitter, which can cause frequent failovers or temporary split-brain scenarios. A large value can increase the failover time after the primary instance fails.
        authentication {
            auth_type PASS
            auth_pass 1111
        }
        unicast_src_ip 192.168.0.26   # The private IP address of this instance. This example uses 192.168.0.26.
        unicast_peer {
            192.168.0.25          # The private IP address of the peer instance. This example uses 192.168.0.25. If you have multiple secondary ECS instances, declare the IP address of each peer instance on a new line. Do not use commas or other separators.
        }
        virtual_ipaddress {
            192.168.0.24          # The virtual IP address. Set this to the HaVip's IP address. This example uses 192.168.0.24. 
        }    
        garp_master_delay 1       # The delay in seconds before updating the ARP cache after a failover to this instance. 
        garp_master_refresh 5     # The interval at which ARP messages are sent, in seconds. 

        track_interface {
            eth0                  # The network interface to which the virtual IP address is bound. This example uses eth0.
        }
    }' > /etc/keepalived/keepalived.conf
    systemctl start keepalived
  EOT
  )                                           # Specify the initialization script for the secondary server to install Keepalived.
  private_ip           = "192.168.0.26"       # Specify the private IP address of the secondary server. 
  instance_charge_type = "PostPaid"           # Set the billing method to pay-as-you-go.
  spot_strategy        = "SpotWithPriceLimit" # Set as a spot instance with a price limit.
}

# Associate with the primary server.
resource "alicloud_havip_attachment" "test_havip_attachment" {
  ha_vip_id   = alicloud_havip.test_havip.id
  instance_id = alicloud_instance.test_master_instance.id # Specify the ID of the instance to associate with the HaVip.
}

# Associate with the secondary server.
resource "alicloud_havip_attachment" "test_havip_attachment_new" {
  ha_vip_id   = alicloud_havip.test_havip.id
  instance_id = alicloud_instance.test_backup_instance.id # Specify the ID of the instance to associate with the HaVip.
}

Associate an EIP for public access

An HaVip is a private IP within a vSwitch. To enable internet access, associate an Elastic IP Address (EIP) with the HaVip. Note that EIPs incur fees.

1. The EIP must be in the same region as the HaVip and be available.
2. When an ECS instance accesses the internet through an EIP associated with an HaVip, the source IP of outbound packets is the HaVip's private IP, not the ECS instance's private IP.

Console

Associate or disassociate an EIP

Before associating an EIP, create one in the EIP console or click Create EIP on the association page.

In the Actions column for the target HaVip, click Associate EIP or Disassociate EIP.

API

Before associating an EIP, call AllocateEipAddress to create one.

Terraform

Resource: alicloud_eip_address, alicloud_eip_association
# Specify the region of the HaVip. 
provider "alicloud" {
  region = "cn-hangzhou"
}

# Specify the ID of the HaVip.
variable "havip_id" {
  default = "havip-8vb0******"  # Replace with the actual ID of your HaVip.
}

# Create an EIP.
resource "alicloud_eip_address" "test_eip" {
  address_name = "test_eip_name"
  isp          = "BGP"
  netmode      = "public"
  bandwidth    = "1"
  payment_type = "PayAsYouGo"
}

# Associate the EIP.
resource "alicloud_eip_association" "test_eip_havip_association" {
  allocation_id = alicloud_eip_address.test_eip.id
  instance_type = "HAVIP"
  instance_id   = var.havip_id # Specify the ID of the HaVip.
}

More information

Billing

HaVip is in public preview and free of charge. No SLA is provided during the public preview.

Associated resources such as ECS instances and EIPs are billed according to their respective pricing rules.

Supported regions

Supported public cloud regions

Area

Regions

Asia Pacific - China

China (Hangzhou), China (Shanghai), China (Nanjing - Local Region, decommissioning), China (Qingdao), China (Beijing), China (Zhangjiakou), China (Hohhot), China (Ulanqab), China (Shenzhen), China (Heyuan), China (Guangzhou), China (Chengdu), China (Zhongwei), China (Hong Kong), China (Wuhan - Local Region), and China (Fuzhou - Local Region, decommissioning)

Asia Pacific - Others

Japan (Tokyo), South Korea (Seoul), Singapore, Malaysia (Kuala Lumpur), Indonesia (Jakarta), Philippines (Manila), Thailand (Bangkok), and Malaysia (Johor)

Europe & Americas

Germany (Frankfurt), UK (London), France (Paris), US (Silicon Valley), US (Virginia), and Mexico

Middle East

UAE (Dubai) and Saudi Arabia (Riyadh, partner region)

Supported Finance Cloud regions

Area

Regions

Asia Pacific

China (Shenzhen) Finance, China (Shanghai) Finance, and China (Beijing) Finance (invitation-only beta)

Supported Gov Cloud regions

Area

Regions

Asia Pacific

China (Beijing) Government Cloud 1

Quotas

HaVip is in public preview. To enable it, log on to the Quota Center console and submit an application.

Quota name

Description

Default limit

Adjustable

None

The network type that supports high-availability virtual IP addresses (HaVips).

VPC

No.

HaVips per ECS instance.

5

EIPs per HaVip.

1

ECS instances or ENIs per HaVip.

10

1. An HaVip can be associated with 10 ECS instances or 10 ENIs at the same time. However, an HaVip cannot be associated with ECS instances and ENIs at the same time.
2. An HaVip has the subnet property. It can be associated only with ECS instances or ENIs that are in the same vSwitch.

Whether HaVips support broadcast and multicast.

No

HaVips support only unicast communication. If you use third-party software such as Keepalived to implement high availability, you must change the communication mode to unicast in the configuration file.

HaVips per account.

50

HaVips per VPC.

50

vpc_quota_havip_custom_route_entry

Entries whose destination is an HaVip in a route table.

5

Yes.

Go to the Quota Management page or Quota Center to request a quota increase.