標籤:lvs keepalived 高可用
一、環境介紹:
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
二、安裝:
在兩台lvs上安裝lvs+keepalived:
yum install lvsadm keepalived -y
在兩台web伺服器上安裝nginx(安裝配置略過)
配置keepalived:
主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 100
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
}
}
}
備lvs上只需修改紅色部分即可:
state BACKUP
priority 90
以上部分為lvs機器配置結束
下面為web機器上配置指令碼,主要為綁定vip並關閉arp響應
#!/bin/bash
VIP=192.168.1.20
. /etc/rc.d/init.d/functions
case $1 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: $0 (start|stop)"
exit 1
esac
exit 0
因為都是使用內網IP,如果想在外網訪問只需將VIP的80連接埠在路由器上映射即可
本文出自 “人要有夢想,萬一實現了呢” 部落格,請務必保留此出處http://yangke.blog.51cto.com/9530509/1580940
LVS+Keepalived DR模式實現web負載平衡高可用