配置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_tables
ip route add default via 172.16.2.220 dev eth1 tablerip
ip rule add from 172.16.2.207(208) table rip
本文出自 “秋天的童话” 博客,请务必保留此出处http://wushank.blog.51cto.com/3489095/1708430
原文地址:http://wushank.blog.51cto.com/3489095/1708430