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.
Cara kerja
Gunakan satu HaVip dan dua instance ECS untuk membuat kluster dengan ketersediaan tinggi. Prosesnya bekerja sebagai berikut:
Konfigurasikan Keepalived: HaVip dikaitkan dengan ECS1 dan ECS2, dengan kedua instance telah menginstal Keepalived. Di file konfigurasi Keepalived, atur
virtual_ipaddresske alamat HaVip untuk kedua instance, lalu tentukan nilaipriority. Nilai yang lebih tinggi menunjukkan prioritas lebih tinggi untuk menjadi server utama.Pilih server utama: Keepalived membandingkan nilai
prioritydari 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.Failover: Server utama, ECS1, secara berkala mengirim pesan heartbeat ke server sekunder, ECS2. Intervalnya diatur oleh
advert_intdi 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).
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
Buka VPC Console - HaVip, pilih wilayah tempat instance ECS Anda berada di bagian atas halaman, lalu klik Create HaVip.
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.
Instal Keepalived pada instance ECS utama dan sekunder, lalu jalankan
systemctl start keepaliveduntuk memulai Keepalived.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.
Verifikasi hasilnya:
Jalankan perintah berikut pada instance utama dan sekunder untuk membuat layanan uji web yang mengembalikan hasil berbeda.
Jalankan
netstat -an | grep 8000untuk 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 8000Instance sekunder:
echo "ECS 2" > index.html # The secondary instance returns "ECS 2" python3 -m http.server 8000Pada instance ECS lain dalam VPC yang sama, jalankan
curl <havip_private_ip>:8000. Perintah ini mengembalikanECS 1. Saat instance ECS utama dihentikan, perintah tersebut mengembalikanECS 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
Panggil CreateHaVip untuk membuat HaVip.
Panggil AssociateHaVip untuk mengaitkan HaVip dengan instance ECS atau ENI.
Panggil UnassociateHaVip untuk memutuskan kaitan HaVip dari instance ECS atau ENI.
Panggil DeleteHaVip untuk menghapus HaVip.
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.
Panggil AssociateEipAddress untuk mengaitkan EIP dengan HaVip.
Panggil UnassociateEipAddress untuk memutuskan kaitan EIP dari HaVip.
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. |