Requirements: Using keepalived to achieve high-availability load balancing of Web service clusters, which is the role of director in the LVS_DR model, the request from the user is assigned to the back-end server by a certain algorithm, and the keepalived server is highly available.
Keepalived is an implementation of the VRRP protocol designed specifically for LVS to enable redundancy of the dirctor in the cluster and health detection of the realserver in the high availability of LVS. When a host (master) has a problem, keepalived is able to automatically assign the VIP to the standby host (backup), enabling its own (director) to be highly available.
Steps:
1. Deploy 172.16.10.17 and 172.16.10.77 two hosts as real_server in the LVS_DR model and are guaranteed to be available (omit steps here)
2.172.16.10.16 and 172.16.10.66 Two hosts acting as Director and standby director
1) Install keepalived on both hosts
Yum-y Install keepalived
2) Edit the configuration file
Vim/etc/keepalived/keepalived.conf
The contents are:
Global_defs {
Notification_email {
[email protected] # # Backend Server when there is a problem with the message recipient, you can multiple
}
notification_email_from [email protected] # # e-Mail Sender
smtp_server 127.0.0.1 # # Mailbox Server
Smtp_connect_timeout 30
router_id c616 # # route Tag
vrrp_mcast_group4 224.0.10.18 # #多播使用的地址
}
Vrrp_instance Vi_1 {
State MASTER # # Set as the primary server
Interface eth0 # # network interface
virtual_router_id 10 # # Virtual route ID with a value of 0-255
Priority 100 # # Precedence
advert_int 3 # # VRRP interval of notice time
Authentication {
auth_type PASS # # authentication method
auth_pass Douhua # Authentication string, up to 8 bits
}
virtual_ipaddress {
172.16.10.99/16 # # Virtual server address, VIP
}
}
Host 172.16.10.66 Similar, note that the change priority is 98, and the current node's initial state is backup
3) Start the service
A) Start the 172.16.10.16 keepalived service to see if 172.16.10.99 addresses are added (available)
b) Start the 172.16.10.66 keepalived service to see if 172.16 has been added. 10.99 Address (none)
c) Close the 172.16.10.16 keepalived Service to see if the 172.16.10.16 host deleted 172.10.16.99 address, 172.16.10.66 host added 172.16.10.99 Address
d) Start the 172.16.10.16 keepalived service to see if the 172.16.10.16 host has added 172.16.10.99 address, 172.16.10.66 whether the host deleted 172.16.10.99 Address
3. Add virtual server for load Balancing function
1) Add the following after the above configuration file:
Virtual_server 172.16.10.99 80 {
Delay_loop 3 # # Polling Time
Lb_algo WRR # # scheduling algorithm
lb_kind DR # # LVS Type
persistence_timeout 50 # # Long Connection Timeout length
Protocol TCP # # protocol
sorry_server 127.0.0.1 # #real_server都故障后的页面
Real_server 172.16.10.17 80 {
weight 1 # # Weight
Http_get {
URL {
path/index.html
Status_code 200
}
connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}
Real_server 172.16.10.77 80 {
Weight 2
Http_get {
URL {
path/index.html
Status_code 200
}
connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}
}
2) Add a similar configuration on the 172.16.10.66 host and change the state,priority
3) test if the keepalived redundancy function is possible, similar to the previous method, you can change the later view to see if the Web page can open correctly
Keepalived implementing high-availability load balancing for Web services clusters