Configuration keepalived:
1. Using Dr Mode:
Environment Description:
192.168.2.205 node1.sky.com Keepalived+lvs server DIP
192.168.2.206 node2.sky.com Keepalived+lvs server DIP
192.168.2.220 LVs VIP
192.168.2.207 web1.sky.com Apache Server
192.168.2.208 web2.sky.com Apache Server
192.168.2.100 Window Client
Start with time synchronization
Configuration Description:
Global_defs {
Notification_email {
[Email protected]
}
Notification_email_from [email protected]
Smtp_server 127.0.0.1
Smtp_connect_timeout 30
router_id node1.sky.com
Vrrp_mcast_group4 224.0.0.28
}
Vrrp_script Chk_mantaince_down {
Script "[[[-f/etc/keepalived/down]] && Exit 1 | | Exit 0 "
Interval 1
Weight-20
}
Vrrp_instance LVs {
State MASTER
Interface eth0
VIRTUAL_ROUTER_ID 51
Track_interface {
Eth0 Weight 5
Eth1 weight-20
}
Priority 110
Advert_int 2
Authentication {
Auth_type PASS
Auth_pass 1111
}
virtual_ipaddress {
192.168.2.220/32 Dev eth0 label eth0:0
}
Track_script {
Chk_mantaince_down
}
Notify_backup "/usr/local/keepalived/bin/show.sh http Backup"
Notify_master "/usr/local/keepalived/bin/show.sh http Master"
Notify_fault "/usr/local/keepalived/bin/show.sh http Fault"
Smtp_alert
}
Virtual_server 192.168.2.220 80 {
Delay_loop 3
Lb_algo RR
Lb_kind DR
Persistence_timeout 10
Protocol TCP
Real_server 192.168.2.207 80 {
Weight 1
Http_get {
URL {
Path/status
Status_code 200
}
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}
Real_server 192.168.2.208 80 {
Weight 1
Http_get {
URL {
Path/status
Status_code 200
}
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}
}
If the backend httpd service monitoring port is 8080, port forwarding can be done with iptables on the Web server
Iptables-t nat-a prerouting-p tcp--dport 80-j DNAT--to-destination:8080
2. Using NAT mode
Environment Description:
192.168.2.205 node1.sky.com Keepalived+lvs server DIP
192.168.2.206 node2.sky.com Keepalived+lvs server DIP
192.168.2.220 LVs VIP
192.168.2.207 (Management IP) 172.16.2.207 (VIP) web1.sky.com Apache Server
192.168.2.208 (Management IP) 172.16.2.208 (VIP) web2.sky.com Apache Server
192.168.2.100 Window Client
Configuration Description:
Global_defs {
Notification_email {
[Email protected]
}
Notification_email_from [email protected]
Smtp_server 127.0.0.1
Smtp_connect_timeout 30
router_id node1.sky.com
Vrrp_mcast_group4 224.0.0.28
}
Vrrp_script Chk_mantaince_down {
Script "[[[-f/etc/keepalived/down]] && Exit 1 | | Exit 0 "
Interval 1
Weight-20
}
Vrrp_instance LVs {
State MASTER
Interface eth0
VIRTUAL_ROUTER_ID 51
Track_interface {
Eth0 Weight 5
Eth1 weight-20
}
Priority 110
Advert_int 2
Authentication {
Auth_type PASS
Auth_pass 1111
}
virtual_ipaddress {
192.168.2.220/24 brd 192.168.2.255 dev eth0 label eth0:0
172.16.2.220/24 BRD 172.16.2.255 Dev eth1 label eth1:0
}
Track_script {
Chk_mantaince_down
}
Notify_backup "/usr/local/keepalived/bin/show.sh http Backup"
Notify_master "/usr/local/keepalived/bin/show.sh http Master"
Notify_fault "/usr/local/keepalived/bin/show.sh http Fault"
Smtp_alert
}
Virtual_server 192.168.2.220 80 {
Delay_loop 3
Lb_algo RR
Lb_kind NAT
Persistence_timeout 10
Nat
Protocol TCP
Real_server 172.16.2.207 8080 {
Weight 1
Http_get {
URL {
Path/status
Status_code 200
}
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}
Real_server 172.16.2.208 8080 {
Weight 1
Http_get {
URL {
Path/status
Status_code 200
}
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}
}
Attention:
1, two LVS server open port forwarding
2. two Web server gateways point to 172.16.2.220
echo "101 Rip" >>/etc/iproute2/rt_tables
IP route add default via 172.16.2.220 dev eth1 tablerip
IP rule Add from 172.16.2.207 (208) Table RIP
This article is from the "Autumn Fairy tale" blog, please be sure to keep this source http://wushank.blog.51cto.com/3489095/1708430
High availability of LVS using the KeepAlive implementation