First, the environment introduction:
lvs_master:192.168.1.18
lvs_backup:192.168.1.19
web1:192.168.1.16
web2:192.168.1.17
vip:192.168.1.20
Second, installation:
Install the lvs+keepalived on both LVS:
Yum Install Lvsadm keepalived-y
Installing Nginx on two Web servers (installation configuration skipped)
Configuration keepalived:
Configuration on main LVS:
Vim/etc/keepalived/keepalived.conf
! Configuration File for Keepalived
Global_defs {
Notification_email {
[email protected]
}
notification_email_from [email protected]
Smtp_server 127.0.0.1
Smtp_connect_timeout 30
router_id Lvs_1
}
Vrrp_instance Vi_1 {
State MASTER
Interface eth0
VIRTUAL_ROUTER_ID 51
Priority
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
virtual_ipaddress {
192.168.1.20
}
}
Virtual_server 192.168.1.20 80 {
Delay_loop 6
Lb_algo RR #lvs轮询方式
Lb_kind DR #lvs工作方式
Nat_mask 255.255.255.255
Protocol TCP
Real_server 192.168.1.16 80 {
Weight 10
Tcp_check {
Connect_timeout 10
Nb_get_retry 3
Delay_before_retry 3
Connect_port 80
}
}
Real_server 192.168.1.17 80 {
Weight 10
Tcp_check {
Connect_timeout 10
Nb_get_retry 3
Delay_before_retry 3
Connect_port 80
}
}
}
Only the red part can be modified on the prepared LVS:
State BACKUP
Priority
The above section is the end of the LVS machine configuration
The following is a configuration script on the Web machine, primarily binding the VIP and shutting down the ARP response
#!/bin/bash
vip=192.168.1.20
. /etc/rc.d/init.d/functions
Case $ in
Start
Ifconfig lo:0 $VIP netmask 255.255.255.255 broadcast $VIP
Route add-host $VIP Dev lo:0
Echo 1 >/proc/sys/net/ipv4/conf/lo/arp_ignore
Echo 2 >/proc/sys/net/ipv4/conf/lo/arp_announce
Echo 1 >/proc/sys/net/ipv4/conf/all/arp_ignore
Echo 2 >/proc/sys/net/ipv4/conf/all/arp_announce
echo "Realserver Start OK"
;;
Stop
Ifconfig lo:0 Down
Route del $VIP >/dev/null 2>&1
Echo 0 >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo 0 >/proc/sys/net/ipv4/conf/lo/arp_announce
echo 0 >/proc/sys/net/ipv4/conf/all/arp_ignore
echo 0 >/proc/sys/net/ipv4/conf/all/arp_announce
echo "Realserver stoped"
;;
*)
echo "Usage: $ start|stop"
Exit 1
Esac
Exit 0
Because the use of intranet IP, if you want to access the external network only the VIP 80 port on the router mapping can
This article from "People want to have a dream, in case the realization of" blog, please be sure to keep this source http://yangke.blog.51cto.com/9530509/1580940
Lvs+keepalived Dr mode for web load balancing high availability