You can use the high-availability virtual IP address (HAVIP) feature of virtual private clouds (VPCs) together with Address Resolution Protocol (ARP) and Keepalived or Heartbeat to deploy high-availability services. This ensures that IP addresses are not changed when failover is performed.
What is an HAVIP?
Definition
An HAVIP is a private IP address that can be created and released as an independent resource. Similar to the primary IP addresses of Elastic Compute Service (ECS) instances, HAVIPs support network communication. HAVIPs can work with high-availability software, such as Keepalived, to deploy high-availability services.
An HAVIP can be associated with multiple ECS instances, or the primary or secondary elastic network interface (ENIs) of multiple ECS instances. Combined with these resources, HAVIPs can be used to implement automatic IP switchover between multiple high-availability servers in the same zone. This ensures that the private IP address used to provide services remains unchanged. Additionally, you can associate an HAVIP with an elastic IP address (EIP) to provide services over the Internet. In addition, ECS instances associated with HAVIPs can use deployment sets to further improve service reliability. For more information, see Deployment set.
Scenarios
As shown in the following figure, ECS1 and ECS2 are used to deploy a high-availability service in a VPC by using Keepalived. The service is accessible to ECS3 in the VPC. The service address is the IP address of the HAVIP. If ECS1 is down, ECS2 automatically takes over. This ensures the availability of the services.
If you need to access the Internet, you can associate the HAVIP with an EIP to provide high-available services over the Internet through the EIP.
Quotas and billing
The HAVIP feature is in beta testing. To use this feature, submit an application in the Alibaba Cloud Quota Center console.
The HAVIP feature is free of charge in beta testing. Alibaba Cloud does not provide service-level agreement (SLA) guarantees during the beta period.
Supported regions
Area | Region |
Asia Pacific | China (Hangzhou), China (Shanghai), China (Nanjing - Local Region), China (Qingdao), China (Beijing), China (Zhangjiakou), China (Hohhot), China (Ulanqab), China (Shenzhen), China (Heyuan), China (Guangzhou), China (Chengdu), China (Hong Kong), China (Wuhan - Local Region), China (Fuzhou - Local Region), Japan (Tokyo), South Korea (Seoul), Singapore, Malaysia (Kuala Lumpur), Indonesia (Jakarta), Philippines (Manila), and Thailand (Bangkok) |
Europe & Americas | Germany (Frankfurt), UK (London), US (Silicon Valley), and US (Virginia) |
Middle East | UAE (Dubai) and SAU (Riyadh) Important The SAU (Riyadh - Partner Region) region is operated by a partner. |
Limits and quotas
Name/ID | Description | Default value | Adjustable |
N/A | Network types that support HAVIPs | VPC | N/A |
Maximum number of HAVIPs that can be associated with each ECS instance | 5 | ||
Maximum number of EIPs that can be associated with each HAVIP | 1 | ||
Maximum number of ECS instances or ENIs that can be associated with each HAVIP | 10 Note
| ||
Whether HAVIPs support broadcasting or multicasting | N/A Note HAVIPs only support unicast. If using third-party software like Keepalived for high availability, change the communication mode to unicast in the configuration file. | ||
Maximum number of HAVIPs that can be created with each Alibaba Cloud account | 50 | ||
Maximum number of HAVIPs that can be created in each VPC | 50 | ||
vpc_quota_havip_custom_route_entry | Maximum number of route entries that point to an HAVIP in each VPC | 5 | You can increase the quota by performing the following operations:
|
HAVIP use cases
You can use Terraform automation scripts to simplify the deployment, or manually deploy ECS instances in primary/secondary mode by using HAVIPs and Keepalived. For more information, see Scenarios.
Procedure
Prerequisites
Privilege: The privilege to create HAVIPs is obtained by submitting an application in the Quota Center console.
Permissions: Resource Access Management (RAM) users are granted minimum permissions on the VPC and ECS instances by the Alibaba Cloud account.
For more information, see Grant permissions to a RAM user and RAM users.
If you choose manual deployment in the console, prepare the following resources:
Three ECS instances with NGINX deployed. Ensure that NGINX is running in primary and secondary ECS instances. For more information, see Create an instance on the Custom Launch tab and Install NGINX.
Billing
Quick deployment: After you run Terraform automation scripts, three preemptible ECS instances with one vCPU and 2 GiB of memory, one VPC, one vSwitch, and one HAVIP are created. Your expenses depend on how long you keep your ECS instances. We recommend that you remove unused resources to avoid additional cost.
Manual deployment: The fees that you are charged depend on the specifications of the ECS instances that you create.
If you have a need for Internet access, please note that there are fees for the EIP linked to your HAVIP. For more information, please see Billing overview.
Procedure
Quick deployment by using Terraform
Download the project file iac-example-havip.zip.
Log on to Alibaba Cloud Cloud Shell and upload the file.
Run the following commands in sequence to decompress the package, enter the project root directory, initialize the script, and then create resources:
unzip iac-example-havip.zip cd iac-example-havip terraform init terraform apply -auto-approve
Command output:
Test network connectivity.
Log on ECS3. Run the
curl ha_vip_private_ip
command to view the information returned by ECS1 (primary).Run the following command to stop ECS1 in Cloud Shell:
aliyun ecs StopInstance --InstanceId <$instance_id_ecs1> --ForceStop false --StoppedMode KeepCharging -- Dryrun false
Log on ECS3. Run the
curl ha_vip_private_ip
command again to view the information returned by ECS2.In this example, when ECS1 is down, ECS2 automatically takes over. The IP address that is used to provide services remains unchanged, making IP address switchover possible.
Run the following command to release all the resources so that billing can stop:
terraform destroy -auto-approve
Manual deployment in the console
Step 1: Create an HAVIP
Log on to the VPC console.
In the left-side navigation pane, click HaVip.
In the top navigation bar, select the region where you want to create the HAVIP.
On the HaVip page, click Create HaVip.
In the Create HaVip dialog box, set the following parameters, keep other parameters at their default values or modify them as needed, and click OK.
VPC: specifies the VPC to which the HAVIP belongs.
vSwitch: specifies the vSwitch to which the HAVIP belongs.
Whether to automatically assign private IP addresses: Select whether to automatically assign a private IP address.
Yes: The system automatically allocates an idle private IP address from the vSwitch CIDR block.
No: Manually enter an idle private IP address from the vSwitch CIDR block.
After the HAVIP is created, you can view the HAVIP on the HaVip page.
Step 2: Install Keepalived on the primary and secondary ECS instances
In this example, the ECS instances use the CentOS.
Log on to ECS1. For more information, see Connection methods.
Run the following command to install keepalived:
yum install keepalived
Modify the keepalived.conf file.
Run the following command to modify the keepalived.conf file:
vim /etc/keepalived/keepalived.conf
Run the
i
command to enter the input mode. Modify the keepalived.conf file based on the following instructions:! Configuration File for keepalived vrrp_instance VI_1 { state MASTER #Specify ECS1 as the primary ECS instance. interface eth0 #Specify the name of the ENI. eth0 is used in this example. virtual_router_id 51 nopreempt priority 100 #Specify a priority for the ECS instance. A larger value indicates a higher priority. A priority of 100 is specified for the ECS instance in this example. advert_int 1 authentication { auth_type PASS auth_pass 1111 } unicast_src_ip 192.168.0.209 #Specify the private IP address of the ECS instance. 192.168.0.209 is used in this example. unicast_peer { 192.168.0.210 #Specify the private IP address of the peer ECS instance. 192.168.0.210 is used in this example. } virtual_ipaddress { 192.168.0.88 #Specify the IP address of the HAVIP. 192.168.0.88 is used in this example. } garp_master_delay 1 garp_master_refresh 5 track_interface { eth0 #Specify the name of the ENI of the ECS instance. eth0 is used in this example. } }
NoteThis example shows only the parts that need to be modified. Modify the keepalived.conf file based on the instances you are using. Do not copy the content in this example over the keepalived.conf file.
Press the Esc key to exit the edit mode. Enter
:wq
and press the Enter key to save and close the configuration file.
Run the following command to start keepalived on ECS1:
systemctl start keepalived
Log on to ECS2.
Run the following command to install keepalived:
yum install keepalived
Modify the keepalived.conf file.
Run the following command to modify the keepalived.conf file:
vim /etc/keepalived/keepalived.conf
Run the
i
command to enter the input mode. Modify the keepalived.conf file based on the following instructions:! Configuration File for keepalived vrrp_instance VI_1 { state BACKUP #Specify ECS2 as the secondary ECS instance. interface eth0 #Specify the name of the ENI. eth0 is used in this example. virtual_router_id 51 nopreempt priority 10 #Specify a priority for the secondary ECS instance. A larger value indicates a higher priority. A priority of 10 is specified for the ECS instance in this example. advert_int 1 authentication { auth_type PASS auth_pass 1111 } unicast_src_ip 192.168.0.210 #Specify the private IP address of the ECS instance. 192.168.0.210 is used in this example. unicast_peer { 192.168.0.209 #Specify the private IP address of the peer ECS instance. 192.168.0.209 is used in this example. } virtual_ipaddress { 192.168.0.88 #Specify the IP address of the HAVIP. 192.168.0.88 is used in this example. } garp_master_delay 1 garp_master_refresh 5 track_interface { eth0 #Specify the name of the ENI of the ECS instance. eth0 is used in this example. } }
NoteThis example shows only the parts that need to be modified. Modify the keepalived.conf file based on the instances you are using. Do not copy the content in this example over the keepalived.conf file.
Press the Esc key to exit the edit mode. Enter
:wq
and press the Enter key to save and close the configuration file.Run the following command to start keepalived on ECS2:
systemctl start keepalived
Step 3: Associate the HAVIP with the primary and secondary ECS instances
You can associate the HAVIP with both the primary and secondary ECS instances. Then, the ECS instances can announce the HAVIP by sending ARP messages.
An HAVIP can be associated only with ECS instances in the same vSwitch. Each HAVIP can be associated with at most 10 ECS instances.
Perform the following steps to associate the HAVIP with both the primary and secondary ECS instances:
Log on to the VPC console.
In the left-side navigation pane, click HaVip.
In the top navigation bar, select the region where the HAVIP is created.
Find the HAVIP created in Step 1 and click its ID.
Click Bind next to ECS Instances in the Resources section.
In the dialog box that appears, select ECS1 and click OK.
Repeat the preceding steps to associate the HAVIP with ECS2.
After the HAVIP is associated with ECS1 and ECS2, you can view the ECS instances in the Resources section.
Step 4: Test network connectivity
Log on to ECS3. Run the curl ha_vip_private_ip
command to access NGINX delopyed in the instance.
Test results:
If ECS1 works as expected, ECS1 is accessible.
If ECS1 is down, ECS2 takes over the virtual IP address and workloads of ECS1. This ensures service high availability.
Manage HAVIPs
Manage HAVIPs in the console
Operation platform
Log on to the VPC console.
In the left-side navigation pane, click HaVip.
In the top navigation bar, select the region where you want to create the HAVIP.
Perform the following operations as needed.
Create an HAVIP
Associate with and disassociate from an ECS instance or an ENI
Associate with and disassociate from an EIP
API references
You can manage HAVIPs by calling SDK operations, running Terraform scripts, or calling the following API operations:
CreateHaViP: Create a HAVIP.
DeleteHaVip: Delete a HAVIP.
AssociateHaVip: Associate a HAVIP with an ECS instance or ENI.
UnassociateHaVip: Disassociate a HAVIP from an ECS instance or ENI.
AssociateEipAddress: Associate an EIP with an instance.
UnassociateEipAddress: Disassociate an EIP from an instance.
FAQ
Which version of Keepalived is recommended?
We recommend that you use the version 1.2.15 or later.
What can I do if I run into problems when I use Keepalived?
We recommend that you seek solutions on Keepalived GitHub.
If I use third-party software such as Keepalived to implement high availability, how do I configure the source IP address for heartbeat detection?
If you use third-party software such as Keepalived to implement high availability, you need to change the source IP address of heartbeat detection to the private IP address of the ECS instance, instead of the private IP address of the HAVIP.
Can I use HAVIPs to implement high availability for user-created Linux virtual servers (LVS)?
No, you cannot use HAVIPs to implement high availability for user-created LVS.
When an ECS instance that is associated with an HAVIP accesses the Internet, what is the source IP address of the data packets?
In this case, the HAVIP is associated with the ECS instance and an EIP. The EIP is mapped to the private IP address of the HAVIP instead of the private IP address of the ECS instance. Therefore, the source IP address of the data packets is the private IP address of the HAVIP instead of the private IP address of the ECS instance.