|
LVS使用DR模式,Keepalived作高可用,以前部署lvs+keepalived的时候全都是一主一被,看了抚琴煮酒老师的Nginx互为主备模式,也就试着把lvs搭建成双主模式,测试方法:停止任意一台keepalived服务器,在当前服务器上的VIP就会自动漂到另一台服务器
这样两个VIP使用两个外网IP的80端口,映射到一个域名上
缺点:使用了两个外网ip,浪费了部分资金
####################################
web服务器
[iyunv@localhost~]vim /etc/rc.d/realserver.sh
#!/bin/bash
#description: Config realserver lo and apply noarp
vip1=192.168.5.253
vip2=192.168.5.254
case"$1" in
start)
ifconfig lo:0 $vip1 netmask 255.255.255.0
ifconfi lo:1 $vip2 netmask 255.255.255.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
sysctl-p >/dev/null 2>&1
echo"RealServer Start OK"
;;
stop)
ifconfig lo:0 down
ifconfig lo:1 down
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}"
exit1
esac
exit0
[iyunv@localhost~]/usr/rc.d/realserver.sh start
[iyunv@localhost~]echo /usr/rc.d/realserver.sh start >> /etc/rc.local
#################################################
LVS+KeepalivedMaster
######################keepalived.conf####################
! Configuration File for keepalived
global_defs {
notification_email {
jqbash@gmail.com
}
notification_email_from root@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id Web-HA
}
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.5.253/24 dev eth0
}
}
virtual_server 192.168.5.253 80 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 50
protocol TCP
real_server 192.168.5.50 80 {
weight 100
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.5.60 80 {
weight 100
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
vrrp_instance VI_2 {
state BACKUP
interface eth0
virtual_router_id 52
priority 80
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.5.254/24 dev eth0
}
}
virtual_server 192.168.5.254 80 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 50
protocol TCP
real_server 192.168.5.50 80 {
weight 100
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.5.60 80 {
weight 100
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
######################################################
[iyunv@localhost~]service keepalived start
[iyunv@localhost~]chkconfig keepalived on
[iyunv@localhost~]ip addr
1:lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue
link/loopback00:00:00:00:00:00 brd 00:00:00:00:00:00
inet127.0.0.1/8 scope host lo
inet6::1/128 scope host
valid_lftforever preferred_lft forever
2:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdiscpfifo_fast qlen 1000
link/ether00:24:1d:86:18:2c brd ff:ff:ff:ff:ff:ff
inet192.168.5.3/24 brd 192.168.5.255 scope global eth0
inet192.168.5.253/24 scope global secondary eth0
inet6fe80::224:1dff:fe86:182c/64 scope link
valid_lftforever preferred_lft forever
3:sit0: <NOARP> mtu 1480 qdisc noop
link/sit0.0.0.0 brd 0.0.0.0
########################################################
LVS+KeepalivedBackup
--------------------------------------
######################keepalived.conf####################
! Configuration File for keepalived
global_defs {
notification_email {
jqbash@gmail.com
}
notification_email_from root@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id Web/MySql-HA
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 80
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.5.253/24 dev eth0
}
}
virtual_server 192.168.5.253 80 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 50
protocol TCP
real_server 192.168.5.50 80 {
weight 100
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.5.60 80 {
weight 100
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
vrrp_instance VI_2 {
state MASTER
interface eth0
virtual_router_id 52
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.5.254/24 dev eth0
}
}
virtual_server 192.168.5.254 80 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 50
protocol TCP
real_server 192.168.5.50 80 {
weight 100
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.5.60 80 {
weight 100
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
#################################################################
[iyunv@localhost~]service keepalived start
[iyunv@localhost~]chkconfig keepalived on
[iyunv@localhost~]ip addr
1:lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue
link/loopback00:00:00:00:00:00 brd 00:00:00:00:00:00
inet127.0.0.1/8 scope host lo
inet6::1/128 scope host
valid_lftforever preferred_lft forever
2:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdiscpfifo_fast qlen 1000
link/ether00:24:1d:86:18:2c brd ff:ff:ff:ff:ff:ff
inet192.168.5.4/24 brd 192.168.5.255 scope global eth0
inet192.168.5.254/24 scope global secondary eth0
inet6fe80::224:1dff:fe86:182c/64 scope link
valid_lftforever preferred_lft forever
3:sit0: <NOARP> mtu 1480 qdisc noop
link/sit0.0.0.0 brd 0.0.0.0
|
|
|