Yüksek kullanılabilirlikli sanal IP adresi (HaVip), aynı alan içindeki ECS örnekleri arasında yük devretme sırasında hizmet IP'nizin değişmeden kalmasını sağlar.
Nasıl çalışır?
Tipik bir yüksek kullanılabilirlik kümesi, birincil/ikincil yapılandırmada bir HaVip ve iki ECS örneğinden oluşur:
Keepalived yapılandırması: HaVip'i ECS1 ve ECS2 ile ilişkilendirin ve her ikisine de Keepalived yükleyin.
virtual_ipaddressparametresini HaVip adresine ayarlayın ve birprioritydeğeri atayın; daha yüksek önceliğe sahip olan örnek birincil seçimi kazanır.Birincil seçimi: Keepalived, VRRP aracılığıyla
prioritydeğerlerini karşılaştırır ve daha yüksek önceliğe sahip örneği birincil olarak seçer. Sistem HaVip eşlemesini günceller ve HaVip'e yönelik tüm trafik ECS1'e yönlendirilir.Yük devretme: ECS1,
advert_intile belirtilen aralıkta ECS2'ye kalp atışı sinyalleri gönderir. ECS2 zaman aşımı süresi içinde bir kalp atışı sinyali almazsa Keepalived ECS2'yi birincil olarak yükseltir. Sistem HaVip eşlemesini ECS2'ye günceller ve tüm trafik buna göre aktarılır; hizmet IP'si değişmeden kalır.
Genel erişimi etkinleştirmek için HaVip'i bir EIP ile ilişkilendirin. Trafik daha sonra yüksek kullanılabilirliğe sahip internete yönelik hizmetler sağlamak üzere EIP üzerinden yönlendirilir.
Yük devretme için HaVip kullanma
Bir HaVip'i aynı vSwitch içindeki ECS örnekleri veya esnek ağ arabirimleri (ENI) ile ilişkilendirin. Bu işlem, Keepalived ile birlikte kullanıldığında yük devretme sırasında hizmet IP'nizin değişmeden kalmasını sağlar.
Kota: Quota Center konsoluna gidin ve HaVip oluşturma izni için başvurun. Kota değeri 1 ise HaVip oluşturma etkinleştirilmiş demektir.
IP sürümü: HaVip yalnızca IPv4'ü destekler.
-
İlişkili kaynaklar:
Bir HaVip aynı anda yalnızca bir kaynak türüyle ilişkilendirilebilir. Türü değiştirmek için önce mevcut kaynakların ilişkisini kaldırın.
Bir HaVip'i bir ENI ile ilişkilendirdiğinizde ENI'nin bir ECS örneğine ekli olduğundan emin olun.
İlişkili bir ECS örneği veya ENI silindiğinde sistem HaVip'in söz konusu kaynaktan ilişkisini otomatik olarak kaldırır.
İkincil bir ENI'yi bir ECS örneğinden ayırmak HaVip-ENI ilişkisini etkilemez.
Konsol
HaVip oluşturma ve ilişkilendirme
VPC Konsolu - HaVip sayfasına şuraya gidin. ECS örneklerinizin bulunduğu bölgeyi seçin ve ardından Create HaVip öğesine tıklayın.
ECS örneklerinin ait olduğu VPC ve vSwitch'i seçin. vSwitch'in CIDR bloğundan otomatik olarak bir özel IP adresi atayabilir veya atanmamış bir IP adresi belirtebilirsiniz.
-
Birincil ve yedek ECS örneklerine Keepalived yükleyin ve Keepalived'i başlatmak için
systemctl start keepalivedkomutunu çalıştırın. -
Hedef HaVip'in kimliğine tıklayın. Resources bölümünde Bind seçeneğine tıklayın ve ardından ECS Instances öğesinin sağ tarafındaki ilişkilendirmek istediğiniz ECS örneklerini veya ENI'leri seçin.
İlişkilendirme tamamlandıktan sonra birincil ve ikincil durumunu Associated Instance sütununda veya ayrıntılar sayfasının Resources bölümünde görüntüleyebilirsiniz.
-
Sonucu doğrulayın:
-
Farklı sonuçlar döndüren bir web test hizmeti oluşturmak için birincil ve ikincil örneklerde aşağıdaki komutları çalıştırın.
Port kullanımını kontrol etmek için
netstat -an | grep 8000komutunu çalıştırın. 8000 numaralı bağlantı noktası kullanılıyorsa başka bir bağlantı noktası seçmeniz gerekir.Birincil örnek:
echo "ECS 1" > index.html # The primary instance returns "ECS 1" python3 -m http.server 8000İkincil örnek:
echo "ECS 2" > index.html # The secondary instance returns "ECS 2" python3 -m http.server 8000 -
Aynı VPC içindeki başka bir ECS örneğinden
curl <havip_private_ip>:8000komutunu çalıştırdığınızdaECS 1yanıtı döner. Birincil sunucu durdurulduktan sonraECS 2yanıtı döner.Birincil ve ikincil örneklerin güvenlik gruplarının, aynı VPC içinden 8000 numaralı bağlantı noktasına HTTP trafiğine izin verdiğinden emin olun.
-
Kaynakların ilişkisini kaldırma
Hedef HaVip'in kimliğine tıklayın. Resources bölümünde Associated kaynaklar listesinde hedef ECS örneğini veya esnek ağ arabirimini bulun ve Delete Association seçeneğine tıklayın.
HaVip silme
Bir HaVip'i silmeden önce herhangi bir ECS örneği, ENI veya EIP ile ilişkilendirilmemiş olduğundan emin olun. Hedef HaVip'in Actions sütununda veya ayrıntılar sayfasında Delete seçeneğine tıklayın.
API
Bir HaVip oluşturmak için CreateHaVip API'sini çağırın.
Bir HaVip'i bir ECS örneği veya ENI ile ilişkilendirmek için AssociateHaVip API'sini çağırın.
Bir HaVip'in bir ECS örneği veya ENI ile ilişkisini kaldırmak için UnassociateHaVip API'sini çağırın.
Bir HaVip'i silmek için DeleteHaVip API'sini çağırın.
Terraform
Kaynaklar: 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.
}
Genel erişim için EIP ilişkilendirme
HaVip, bir vSwitch içindeki özel bir IP adresidir. İnternet erişimini etkinleştirmek için Esnek IP Adresi (EIP) ile HaVip'i ilişkilendirin. EIP'lerin ücretlendirildiğini unutmayın.
1. EIP, HaVip ile aynı bölgede olmalı ve kullanılabilir durumda bulunmalıdır.
2. Bir ECS örneği, HaVip ile ilişkilendirilmiş bir EIP üzerinden internete eriştiğinde giden paketlerin kaynak IP'si ECS örneğinin özel IP'si değil HaVip'in özel IP'sidir.
Konsol
EIP ilişkilendirme veya ilişkinin kaldırılması
Bir EIP ilişkilendirmeden önce EIP konsolunda bir EIP oluşturun veya ilişkilendirme sayfasında Create EIP seçeneğine tıklayın.
Hedef HaVip'in Actions sütununda Associate EIP veya Disassociate EIP seçeneğine tıklayın.
API
Bir EIP ilişkilendirmeden önce bir tane oluşturmak için AllocateEipAddress API'sini çağırın.
Bir EIP'yi bir HaVip ile ilişkilendirmek için AssociateEipAddress API'sini çağırın.
Bir EIP'nin bir HaVip ile ilişkisini kaldırmak için UnassociateEipAddress API'sini çağırın.
Terraform
Kaynaklar: 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.
}
Daha fazla bilgi
Ücretlendirme
HaVip genel önizleme aşamasındadır ve ücretsizdir. Genel önizleme sırasında SLA sağlanmaz.
ECS örnekleri ve EIP'ler gibi ilişkili kaynaklar kendi fiyatlandırma kurallarına göre ücretlendirilir.
Desteklenen bölgeler
Alan | Bölgeler |
Asya Pasifik - Çin | China (Hangzhou), China (Shanghai), China (Nanjing - Local Region, Closing Down), 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) ve China (Fuzhou - Local Region, Closing Down) |
Asya Pasifik - Diğerleri | Japan (Tokyo), South Korea (Seoul), Singapore, Malaysia (Kuala Lumpur), Indonesia (Jakarta), Philippines (Manila), Thailand (Bangkok) ve Malaysia (Johor) |
Avrupa ve Amerika | Germany (Frankfurt), UK (London), France (Paris), US (Silicon Valley), US (Virginia), Mexico ve Brazil (São Paulo) |
Orta Doğu | UAE (Dubai) ve Saudi Arabia (Riyadh - Partner Region) |
Kotalar
HaVip genel önizleme aşamasındadır. Etkinleştirmek için Quota Center konsoluna gidin ve bir başvuru gönderin.
Kota adı | Açıklama | Varsayılan sınır | Ayarlanabilir |
Yok | HaVip'leri destekleyen ağ türü. | VPC | Hayır |
ECS örneği başına maksimum HaVip sayısı. | 5 | ||
HaVip başına maksimum EIP sayısı. | 1 | ||
Bir HaVip ile aynı anda ilişkilendirilebilecek maksimum ECS örneği veya esnek ağ arabirimi (ENI) sayısı. | 10 1. Bir HaVip en fazla 10 ECS örneği veya 10 ENI ile ilişkilendirilebilir ancak aynı anda her ikisiyle birden ilişkilendirilemez. 2. Bir HaVip yalnızca HaVip ile aynı vSwitch içinde bulunan ECS örnekleri veya ENI'ler ile ilişkilendirilebilir. | ||
HaVip'lerin yayın ve çoklu yayın iletişimini destekleyip desteklemediği. | Desteklenmez HaVip yalnızca tekli yayın iletişimini destekler. Keepalived gibi üçüncü taraf yazılımları kullanarak yüksek kullanılabilirlik uyguluyorsanız yapılandırma dosyasında iletişim modunu tekli yayına değiştirmeniz gerekir. | ||
vpc_quota_havip_custom_route_entry | Hedefi bir HaVip olan bir yönlendirme tablosundaki maksimum yönlendirme girişi sayısı. | 5 | Evet. Kota artışı talep etmek için Kota Yönetimi sayfasına veya Quota Center'a gidin. |