The basic architecture diagram is as follows:
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/77/24/wKioL1ZkB2HxXxwCAAEk-GGAgoU809.jpg "title=" Keeplived+lvs.jpg "alt=" Wkiol1zkb2hxxxwcaaek-ggagou809.jpg "/>
Platform Environment: centos6.x
1. Install the keepalived, install the Ipvsadm
Yum–y Install keepalived Ipvsadm
2. Configure the Service
2.1 LVs realserver Configuration Script
#!/bin/bash
vip1=192.168.1.199
Case "$" in
Start
echo "Start LVS of Realserver"
/sbin/ifconfig lo:0 $VIP 1 broadcast $VIP 1 netmask 255.255.255.255 up
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
;;
Stop
/sbin/ifconfig lo:0 Down
echo "Close LVS directorserver"
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 "Usage: $ {start|stop}"
Exit 1
Esac
2.2 Keepalived Master configuration file
! 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_devel
}
Vrrp_instance Vi_1 {
State MASTER
Interface eth0
VIRTUAL_ROUTER_ID 52
Priority 100
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
virtual_ipaddress {
192.168.1.199
}
Notify_master "/etc/keepalived/notify.sh Master"
Notify_backup "/etc/keepalived/notify.sh Backup"
Notify_fault "/etc/keepalived/notify.sh Fault"
}
Virtual_server 192.168.1.199 80 {
Delay_loop 6
Lb_algo RR
Lb_kind DR
Nat_mask 255.255.255.0
Persistence_timeout 50
Protocol TCP
Real_server 192.168.1.204 80 {
Weight 1
Http_get {
URL {
Path http://192.168.1.204/index.html
Status_code 200
}
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}
Real_server 192.168.1.205 80 {
Weight 1
Http_get {
URL {
Path http://192.168.1.205/index.html
Status_code 200
}
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}
}
2.3 Keepalived Backup configuration file
! 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_devel
}
Vrrp_instance Vi_1 {
State BACKUP
Interface eth0
VIRTUAL_ROUTER_ID 52
Priority 99
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
virtual_ipaddress {
192.168.1.199
}
Notify_master "/etc/keepalived/notify.sh Master"
Notify_backup "/etc/keepalived/notify.sh Backup"
Notify_fault "/etc/keepalived/notify.sh Fault"
}
Virtual_server 192.168.1.199 80 {
Delay_loop 6
Lb_algo RR
Lb_kind DR
Nat_mask 255.255.255.0
Persistence_timeout 50
Protocol TCP
Real_server 192.168.1.204 80 {
Weight 1
Http_get {
URL {
Path http://192.168.1.204/index.html
Status_code 200
}
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}
Real_server 192.168.1.205 80 {
Weight 1
Http_get {
URL {
Path http://192.168.1.205/index.html
Status_code 200
}
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}
}
3. Testing
Start the service and view the Ipvs rule status on Master
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/77/24/wKioL1ZkCCPQ-O0oAAA8DylHHEQ106.png "title=" QQ picture 20151206180136.png "alt=" Wkiol1zkccpq-o0oaaa8dylhheq106.png "/>
Maill command to view messages
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/77/26/wKiom1ZkB_WRdpVvAABzuddlizE646.png "title=" QQ picture 20151206180359.png "alt=" Wkiom1zkb_wrdpvvaabzuddlize646.png "/>
down master to see If Backup can take over successfully
View whether the state is converted
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/77/25/wKioL1ZkCMKTj8N7AABSX_RoIR4544.png "style=" float: none; "title=" QQ picture 20151206173752.png "alt=" Wkiol1zkcmktj8n7aabsx_roir4544.png "/>
See if the Ipvs rule is in effect
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/77/26/wKiom1ZkCFWS41OMAAA8DylHHEQ573.png "style=" float: none; "title=" QQ picture 20151206180136.png "alt=" Wkiom1zkcfws41omaaa8dylhheq573.png "/>
See if VIP transfers
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/77/25/wKioL1ZkCMOyTuj3AABgqbSuC6c088.png "style=" float: none; "title=" QQ picture 20151206180534.png "alt=" Wkiol1zkcmoytuj3aabgqbsuc6c088.png "/>
This article is from the "left-handed" blog, make sure to keep this source http://mofeihu.blog.51cto.com/1825994/1720089
keepalived configuration of HA based on LVS Dr model