High-availability LVS and keepalived model lvs Based on the keepalived dual-Master Model
Background:
Keepalived: the purpose of Keepalived is to check the status of the web server. If a web server crashes or a job fails, Keepalived will detect it, and remove the faulty web server from the system. When the web server works normally, Keepalived automatically adds the web server to the server group. All these tasks are completed automatically without manual interference, only the web servers that need to be manually repaired.
LVS: LVS is short for Linux Virtual Server. It is a Virtual Server cluster system.
Experimental System: CentOS 6.6 _ x86_64
Prerequisites: Prepare the compiling environment in advance, and disable both firewall and selinux.
Tutorial Description: In this experiment, there are four hosts, of which keep1 and keep2 are two front-end keepalived servers. real1 and real2 are the realservers in LVS, And the IP addresses correspond to the topology.
Experimental software: httpd-2.2.15 keepalived-1.2.19
Tutorial topology:
1. Configure realserver
1. Install httpd:
yum -y install httpd
2. Configure kernel parameters:
Echo 1>/proc/sys/net/ipv4/conf/lo/arp_ignore // respond to echo 1>/proc/sys/ net/ipv4/conf/all/arp_ignoreecho 2>/proc/sys/net/ipv4/conf/lo/arp_announce // indicates that only the address of the directly connected network interface is advertised echo 2>/ proc/sys/net/ipv4/conf/all/arp_announce
3. Add the test page and configure the VIP:
On real1:
Ifconfig lo: 0 192.168.19.150 netmask 255.255.255.255 broadcast 192.168.19.150 up // configure VIP
Ifconfig lo: 1 192.168.19.151 netmask 255.255.255.255 broadcast 192.168.19.151 up
Route add-host 192.168.19.150 dev lo: 0 // configure the route
Route add-host 192.168.19.151 dev lo: 1vim/var/www/html/index.html ---------------------------------------------
On real2:
ifconfig lo:0 192.168.19.150 netmask 255.255.255.255 broadcast 192.168.19.150 up
ifconfig lo:1 192.168.19.151 netmask 255.255.255.255 broadcast 192.168.19.151 up
route add -host 192.168.19.150 dev lo:0
route add -host 192.168.19.151 dev lo:1vim /var/www/html/index.html---------------------------------------------
Ii. install and configure keepalived
1. Compile and install keepalived and operate on keep1 and keep2:
Wget http://www.keepalived.org/software/keepalived-1.2.19.tar.gz
Tar xf keepalived-1.2.19.tar.gz cd keepalived-1.2.19. /configure -- prefix =/usr/local/keepalivedmake & make installcp-p/usr/local/keepalived/etc/rc. d/init. d/keepalived/etc/init. d/chkconfig -- add keepalivedchkconfig keepalived on
Ln-sv/usr/local/keepalived/etc/sysconfig/keepalived
Cp-p/usr/local/keepalived/sbin/keepalived/usr/sbin/keepalived
Ln-sv/usr/local/keepalived/etc/keepalived
Yum-y install ipvsadm // install LVS
2. Configure keepalived:
Keep1:
Vim/etc/keepalived. conf reset vrrp_instance VI_1 {state MASTER interface eth0 limit 31 priority 100 limit 1 authentication {auth_type PASS auth_pass abcd} virtual_ipaddress {192.168.19.150} vrrp_instance VI_2 {state BACKUP interface eth0 limit 41 priority 99 limit 1 authentication {auth_type PASS auth_pass abcd} virtual_ipaddress {region} virtual_server 192.168.19.150 80 {delay_loop 6 protocol rr // LVS algorithm DR // scheduling type protocol TCP real_server 192.168.19.29 {weight 1 connect_timeout 3 timeout 3 Route 3} real_server 192.168.19.34 {weight 1 connect_timeout 3 Route 3 Route 3 }}virtual_server Route 80 {delay_loop 6 lb_algo rr lb_kind DR protocol TCP real_server 192.168.19.29 {weight 1 connect_timeout 3 Route 3} real_server 192.168.19.34 {weight 1 connect_timeout 3 nb_get_retry 3 delay_before_retry 3 }}
On keep2:
vim /etc/keepalived/keepalived.conf
----------------------------------------------
vrrp_instance VI_1 { state BACKUP interface eth0 virtual_router_id 31 priority 99 advert_int 1 authentication { auth_type PASS auth_pass abcd } virtual_ipaddress { 192.168.19.150 }}vrrp_instance VI_2 { state MASTER interface eth0 virtual_router_id 41 priority 100 advert_int 1 authentication { auth_type PASS auth_pass abcd } virtual_ipaddress { 192.168.19.151 }}virtual_server 192.168.19.150 80 { delay_loop 6 lb_algo rr lb_kind DR protocol TCP real_server 192.168.19.29 { weight 1 connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } real_server 192.168.19.34 { weight 1 connect_timeout 3 nb_get_retry 3 delay_before_retry 3 }}virtual_server 192.168.19.151 80 { delay_loop 6 lb_algo rr lb_kind DR protocol TCP real_server 192.168.19.29 { weight 1 connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } real_server 192.168.19.34 { weight 1 connect_timeout 3 nb_get_retry 3 delay_before_retry 3 }}
3. Start keepalived on two machines:
Service keepalived startipvsadm-L-n // use The LVS tool to view keepalived running ip addr show // view VIP
The LVS rules take effect on both machines, and the two VIPs run on two nodes:
Keep1:
On keep2:
Open the test page to test:
When any node is stopped, resources are automatically transferred:
Now, the demo is complete. Thank you! If you have any questions, contact me. QQ: 82800452