您的位置:首页 > 运维架构 > 网站架构

使用KeepAlive实现将lvs进行高可用

2015-10-31 22:07 477 查看
配置keepalived:
1、使用DR模式:

环境说明:
192.168.2.205 node1.sky.com keepalived+lvs 服务器 DIP
192.168.2.206 node2.sky.com keepalived+lvs 服务器 DIP
192.168.2.220 lvs VIP
192.168.2.207 web1.sky.com apache服务器
192.168.2.208 web2.sky.com apache服务器
192.168.2.100 window客户端
首先进行时间同步

配置说明:

global_defs {
notification_email {
6924038@qq.com
}
notification_email_from root@node1.sky.com
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
}
}
}
如果后端的httpd服务监控端口是8080,可以在web服务器上用 iptables进行端口转发
iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination :8080

2、使用nat模式

环境说明:
192.168.2.205 node1.sky.com keepalived+lvs 服务器 DIP
192.168.2.206 node2.sky.com keepalived+lvs 服务器 DIP
192.168.2.220 lvs VIP
192.168.2.207(管理IP) 172.16.2.207 (VIP) web1.sky.com apache服务器
192.168.2.208(管理IP) 172.16.2.208 (VIP) web2.sky.com apache服务器
192.168.2.100 window客户端

配置说明:
global_defs {
notification_email {
6924038@qq.com
}
notification_email_from root@node1.sky.com
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
}
}
}

注意:

1、二台lvs服务器开启端口转发
2、二台web服务器网关指向172.16.2.220

echo "101 rip" >> /etc/iproute2/rt_tablesip route add default via 172.16.2.220 dev eth1 tableripip rule add from 172.16.2.207(208) table rip

本文出自 “秋天的童话” 博客,请务必保留此出处http://wushank.blog.51cto.com/3489095/1708430
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: