全部产品
Search
文档中心

Virtual Private Cloud:HaVip

更新时间:Dec 17, 2025

Alamat IP virtual dengan ketersediaan tinggi (HaVip) memastikan alamat IP layanan tetap tidak berubah selama proses failover primary/secondary untuk instance Elastic Compute Service (ECS) dalam zona yang sama.

Mengapa menggunakan HaVip jika Keepalived sudah mendukung ketersediaan tinggi?

Di pusat data tradisional, Keepalived menggunakan Virtual Router Redundancy Protocol (VRRP) untuk memilih server utama baru saat terjadi failover. Server utama baru tersebut mengikat alamat IP virtual ke antarmuka jaringannya dan mengirim siaran ARP gratis (gratuitous ARP broadcast) untuk mengumumkan pengambilalihan. Perangkat di jaringan area lokal menerima siaran ini dan memperbarui cache ARP lokal mereka agar memetakan alamat IP virtual ke alamat MAC server utama baru tersebut.

Namun, dalam lingkungan cloud, sebagian besar penyedia menggunakan software-defined networking (SDN) dan virtualisasi, di mana stack virtualisasi mengontrol semua alamat IP. Akibatnya, server tidak dapat memodifikasi alamat IP host secara langsung seperti pada infrastruktur tradisional. Selain itu, jaringan berbasis teknik tunneling Lapisan 3 menyebabkan paket ARP dihentikan di pengirim, sehingga host tidak dapat mengklaim alamat IP. Untuk mengatasi keterbatasan ini, Alibaba Cloud memperkenalkan fitur HaVip.

HaVip adalah alamat IP pribadi mengambang (floating private IP) yang beroperasi sebagai resource independen. Anda dapat mengonfigurasi Keepalived untuk menggunakan HaVip sebagai alamat IP virtual dan mengaitkannya dengan server Anda. Saat terjadi failover, Keepalived memilih server utama baru, dan pemetaan HaVip secara otomatis diperbarui ke server utama tersebut. Dengan demikian, HaVip memberikan hasil yang setara dengan siaran ARP gratis, sehingga alamat IP layanan tetap tidak berubah.

Cara kerja

Gunakan satu HaVip dan dua instance ECS untuk membuat kluster dengan ketersediaan tinggi. Prosesnya bekerja sebagai berikut:

  1. Konfigurasikan Keepalived: HaVip dikaitkan dengan ECS1 dan ECS2, dengan kedua instance telah menginstal Keepalived. Di file konfigurasi Keepalived, atur virtual_ipaddress ke alamat HaVip untuk kedua instance, lalu tentukan nilai priority. Nilai yang lebih tinggi menunjukkan prioritas lebih tinggi untuk menjadi server utama.

  2. Pilih server utama: Keepalived membandingkan nilai priority dari ECS1 dan ECS2 melalui VRRP dan memilih ECS1—yang memiliki prioritas lebih tinggi—sebagai server utama. Sistem kemudian secara otomatis memperbarui pemetaan antara HaVip dan server utama. Semua traffic ke HaVip diteruskan ke ECS1.

  3. Failover: Server utama, ECS1, secara berkala mengirim pesan heartbeat ke server sekunder, ECS2. Intervalnya diatur oleh advert_int di file konfigurasi. Jika ECS2 berhenti menerima heartbeat selama periode tertentu, Keepalived mendeteksi bahwa server utama telah mati dan menjadikan ECS2 sebagai server utama baru. Sistem kemudian memperbarui pemetaan HaVip ke ECS2. Semua traffic ke HaVip diteruskan ke ECS2, sehingga alamat IP layanan tetap tidak berubah.

Untuk mengaktifkan akses Internet, kaitkan HaVip dengan elastic IP (EIP).

image

Menggunakan HaVip

HaVip dapat dikaitkan dengan instance ECS atau elastic network interfaces (ENIs) dalam vSwitch yang sama. Saat digunakan bersama Keepalived, HaVip memastikan alamat IP layanan tetap tidak berubah selama proses failover primary/secondary.

  • Kuota: Sebelum memulai, login ke Quota Center dan dapatkan izin untuk membuat HaVip. Nilai kuota 1 menunjukkan bahwa pembuatan HaVip diaktifkan, dan satu akun dapat membuat hingga 50 HaVip.

  • Versi IP: Hanya IPv4 yang didukung.

  • Resource yang dikaitkan:

    • HaVip hanya dapat dikaitkan dengan satu jenis resource. Untuk mengganti jenis resource, putuskan kaitan resource yang ada terlebih dahulu.

    • Saat mengaitkan HaVip dengan ENI, pastikan ENI tersebut telah disambungkan ke instance ECS.

    • Jika instance ECS atau ENI yang dikaitkan dihapus, sistem secara otomatis melepaskan HaVip dari resource tersebut.

    • Jika Anda melepaskan ENI sekunder dari instance ECS, hal ini tidak memengaruhi kaitan ENI tersebut dengan HaVip.

Konsol

Buat HaVip dan kaitkan dengan instance ECS

  1. Buka VPC Console - HaVip, pilih wilayah tempat instance ECS Anda berada di bagian atas halaman, lalu klik Create HaVip.

  2. Pilih VPC dan vSwitch tempat instance ECS berada. Anda dapat memilih untuk secara otomatis menetapkan alamat IP pribadi dari Blok CIDR vSwitch atau menentukan alamat IP yang tidak ditugaskan.

  3. Instal Keepalived pada instance ECS utama dan sekunder, lalu jalankan systemctl start keepalived untuk memulai Keepalived.

    Instalasi Keepalived

    Contoh ini menunjukkan cara menginstal Keepalived pada instance ECS yang menjalankan CentOS. Kami merekomendasikan penggunaan Keepalived V1.2.15 atau versi yang lebih baru.

    Jika Anda memiliki beberapa instance ECS sekunder, deklarasikan semua alamat IP instance tersebut di unicast_peer di setiap instance ECS.
    Kunjungi Keepalived GitHub untuk informasi lebih lanjut.

    Konfigurasi instance ECS utama

    1. Login ke instance ECS utama.

    2. Jalankan yum install keepalived untuk menginstal Keepalived.

    3. Jalankan vim /etc/keepalived/keepalived.conf untuk mengedit file keepalived.conf.

      Contoh ini hanya menampilkan bagian yang perlu diubah. Sesuaikan file keepalived.conf dengan pengaturan Anda. Jangan timpa file Anda dengan kode ini.
      ! Configuration File for keepalived
      vrrp_instance VI_1 {
          state MASTER            # Set as the primary ECS.
          interface eth0          # The network interface to which the VIP 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 need 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. If this value is too small, the configuration is susceptible to network jitter, which may cause frequent failovers and temporary split-brain scenarios. If this value is too large, the failover may take a long 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 addresses of all peer instances. Each address must be on a separate line without a comma or other separator.
          }
          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 switching to the primary instance.
          garp_master_refresh 5     # The interval at which ARP messages are sent, in seconds.
      
          track_interface {
              eth0                  # The network interface to which the VIP is bound. This example uses eth0.
          }
      }
    4. Jalankan systemctl start keepalived untuk memulai Keepalived.

    Konfigurasi instance ECS sekunder

    1. Login ke instance ECS sekunder.

    2. Jalankan yum install keepalived untuk menginstal Keepalived.

    3. Jalankan vim /etc/keepalived/keepalived.conf untuk memodifikasi file keepalived.conf.

      Contoh ini hanya menampilkan bagian yang perlu diubah. Sesuaikan file keepalived.conf dengan pengaturan Anda. Jangan timpa file Anda dengan kode ini.
      ! Configuration File for keepalived
      vrrp_instance VI_1 {
          state BACKUP            # Set as the secondary instance.
          interface eth0          # The network interface to which the VIP 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 need 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. If this value is too small, the configuration is susceptible to network jitter, which can cause frequent failovers and temporary split-brain scenarios. If this value is too large, the primary/secondary failover may take a long 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. Declare the IP addresses of all peer instances. Each address must be on a separate line without a comma or other separator.
          }
          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 switching to the primary instance.
          garp_master_refresh 5     # The interval at which ARP messages are sent, in seconds.
      
          track_interface {
              eth0                  # The network interface to which the VIP is bound. This example uses eth0.
          }
      }
    4. Jalankan systemctl start keepalived untuk memulai Keepalived.

  4. Klik ID HaVip target. Di bagian Resources, klik Bind di samping ECS Instances. Pilih instance ECS atau ENI yang akan dikaitkan. Untuk mengaitkan ENI, pastikan ENI tersebut telah dikaitkan dengan instance ECS. Jika belum, klik Manage ENI untuk membuka halaman detail ENI, klik Bind to instance, pilih instance ECS, lalu klik Confirm.

    Setelah kaitan selesai, lihat resource primary/secondary di kolom Associated Resources untuk HaVip target atau di bagian Resources pada halaman detailnya.
  5. Verifikasi hasilnya:

    1. Jalankan perintah berikut pada instance utama dan sekunder untuk membuat layanan uji web yang mengembalikan hasil berbeda.

      Jalankan netstat -an | grep 8000 untuk memeriksa penggunaan port. Jika port 8000 sedang digunakan, pilih port lain.

      Instance utama:

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

      Instance sekunder:

      echo "ECS 2" > index.html  # The secondary instance returns "ECS 2"
      python3 -m http.server 8000
    2. Pada instance ECS lain dalam VPC yang sama, jalankan curl <havip_private_ip>:8000. Perintah ini mengembalikan ECS 1. Saat instance ECS utama dihentikan, perintah tersebut mengembalikan ECS 2.

      Pastikan grup keamanan instance utama dan sekunder mengizinkan traffic HTTP dari dalam VPC yang sama untuk mengakses port 8000.

Putuskan kaitan HaVip dari resource

Klik ID HaVip target. Di bagian Resources, temukan resource target di bawah ECS Instances atau ENIs di bagian Associated, lalu klik Delete Association.

Hapus HaVip

Pastikan HaVip tidak dikaitkan dengan instance ECS, ENI, atau EIP apa pun. Klik Delete di kolom Actions HaVip target atau buka halaman detailnya dan klik 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 ID of the vSwitch.
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.
resource "alicloud_security_group_rule" "allow_vpc_tcp" {
  type              = "ingress"
  ip_protocol       = "tcp"
  nic_type          = "intranet"
  policy            = "accept"
  port_range        = "1/65535"
  priority          = 1
  security_group_id = alicloud_security_group.test_security_group.id
  cidr_ip           = "0.0.0.0/0"
}

# 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 card to which the VIP 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 need 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. If this value is too small, the configuration is susceptible to network jitter, which can cause frequent failovers and temporary split-brain scenarios. If this value is too large, the primary/secondary failover may take a long 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 addresses of all peer instances. Each address must be on a separate line without a comma or other separator.
        }
        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 switching to the primary instance.
        garp_master_refresh 5           # The interval at which ARP messages are sent, in seconds.

        track_interface {
            eth0                        # The network interface card to which the VIP 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 card to which the VIP 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 need 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. If this value is too small, the configuration is susceptible to network jitter, which can cause frequent failovers and temporary split-brain scenarios. If this value is too large, the primary/secondary failover may take a long 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. Declare the IP addresses of all peer instances. Each address must be on a separate line without a comma or other separator.
        }
        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 switching to the primary instance.
        garp_master_refresh 5     # The interval at which ARP messages are sent, in seconds.

        track_interface {
            eth0                  # The network interface card to which the VIP 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.
}

Kaitkan dengan EIP untuk akses Internet

HaVip adalah resource IP pribadi dalam vSwitch. Untuk mendapatkan akses Internet, Anda dapat mengaitkan EIP dengan HaVip. Penggunaan EIP dikenai biaya.

1. EIP harus berada di wilayah yang sama dengan HaVip dan berstatus Available.
2. Saat instance ECS mengakses Internet melalui EIP yang dikaitkan dengan HaVip, instance ECS mengirim paket data dengan IP sumber diatur ke alamat IP HaVip, bukan alamat IP-nya sendiri.

Konsol

Ikat atau lepas ikatan EIP

Sebelum memulai, pastikan Anda memiliki EIP yang tersedia. Buat satu di EIP console atau klik Create EIP di halaman asosiasi.

Di kolom Actions untuk HaVip target, klik Associate EIP atau Disassociate EIP.

API

Sebelum mengaitkan EIP, pastikan Anda telah memanggil AllocateEipAddress untuk membuat EIP.

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.
}

Informasi tambahan

Penagihan

Fitur HaVip gratis selama masa pengujian beta. Tidak ada jaminan service-level agreement (SLA).

Wilayah yang didukung

Area

Wilayah

Asia Pasifik - Tiongkok

Tiongkok (Hangzhou), Tiongkok (Shanghai), Tiongkok (Nanjing - Local Region, Ditutup), Tiongkok (Qingdao), Tiongkok (Beijing), Tiongkok (Zhangjiakou), Tiongkok (Hohhot), Tiongkok (Ulanqab), Tiongkok (Shenzhen), Tiongkok (Heyuan), Tiongkok (Guangzhou), Tiongkok (Chengdu), Tiongkok (Hong Kong), Tiongkok (Wuhan - Local Region), dan Tiongkok (Fuzhou - Local Region, Ditutup)

Asia Pasifik - Lainnya

Jepang (Tokyo), Korea Selatan (Seoul), Singapura, Malaysia (Kuala Lumpur), Indonesia (Jakarta), Filipina (Manila), dan Thailand (Bangkok)

Eropa & Amerika

Jerman (Frankfurt), Inggris (London), AS (Silicon Valley), AS (Virginia), dan Meksiko

Timur Tengah

UEA (Dubai) dan SAU (Riyadh - Partner Region)

Kuota

Fitur HaVip sedang dalam pratinjau publik. Untuk menyesuaikan kuota, login ke Konsol Quota Center dan ajukan peningkatan.

Nama kuota

Deskripsi

Batas default

Tingkatkan kuota

Tidak ada

Jenis jaringan yang mendukung alamat IP virtual dengan ketersediaan tinggi (HaVip).

VPC

Tidak dapat ditingkatkan.

Jumlah HaVip yang dapat dikaitkan dengan satu instance ECS secara bersamaan.

5

Jumlah EIP yang dapat dikaitkan dengan satu HaVip secara bersamaan.

1

Jumlah instance ECS atau ENI yang dapat dikaitkan dengan satu HaVip secara bersamaan.

10

1. Satu HaVip dapat dikaitkan dengan 10 instance ECS atau 10 ENI secara bersamaan. Namun, HaVip tidak dapat dikaitkan dengan instance ECS dan ENI secara bersamaan.
2. HaVip memiliki properti subnet. HaVip hanya dapat dikaitkan dengan instance ECS atau ENI yang berada dalam vSwitch yang sama.

Apakah HaVip mendukung komunikasi broadcast dan multicast.

Tidak

HaVip hanya mendukung komunikasi unicast. Jika Anda menggunakan perangkat lunak pihak ketiga seperti Keepalived untuk mengimplementasikan ketersediaan tinggi, Anda harus mengubah mode komunikasi ke unicast di file konfigurasi.

Jumlah HaVip yang dapat dibuat oleh satu akun.

50

Jumlah HaVip yang dapat dibuat dalam satu VPC.

50

vpc_quota_havip_custom_route_entry

Jumlah entri rute yang tujuannya adalah HaVip dalam tabel rute.

5

Buka halaman Quota Management atau Quota Center untuk meminta peningkatan kuota.