![Lvs Keepalive DR模式高可用配置 Lvs Keepalive DR模式高可用配置](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
Lvs Keepalive DR模式配置
一.环境
#DIP# eth0:192.168.233.145
#VIP# eth0:0 192.168.233.250/32
#RIP1:192.168.233.146
#RIP2:192.168.233.147
#VIP# 192.168.233.250/32
#DIP-Backup:eth0 192.168.233.150
二.安装
yum install -y ipvsadm gcc make openssl openssl-devel
curl -O http://www.keepalived.org/software/keepalived-1.2.12.tar.gz
tar zxvf keepalived-1.2..tar.gz
cd keepalived-1.2.
./configure --prefix=/usr/local/keepalived
make && make install
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
cp -rf /usr/local/keepalived/etc/keepalived /etc/
三.配置
这种方式,当出现故障,恢复后,自动会切回来,如果希望希望下次出故障转回需要配置nopreempt,并将两个都state都配置为BACKUP
Master:
[root@DIP ~]# more /etc/keepalived/keepalived.conf
! Configuration File for keepalived global_defs {
notification_email {
caoguo@admin.com
}
notification_email_from sns-lvs@gmail.com
smtp_server 127.0.0.1
# smtp_connect_timeout
router_id LVS_DEVEL
} # written by :netseek
# VIP1
vrrp_instance VI_1 {
state MASTER #备份服务器上将MASTER改为BACKUP
interface eth0
virtual_router_id
priority # 备份服务上将100改为99
advert_int
authentication {
auth_type PASS
auth_pass
}
virtual_ipaddress {
192.168.233.250
#(如果有多个VIP,继续换行填写.)
}
} virtual_server 192.168.233.250 {
delay_loop #(每隔10秒查询realserver状态)
lb_algo wrr #(lvs 算法)
lb_kind DR #(Direct Route)
persistence_timeout #(同一IP的连接60秒内被分配到同一台realserver)
protocol TCP #(用TCP协议检查realserver状态) real_server 192.168.233.146 {
weight #(权重)
TCP_CHECK {
connect_timeout #(10秒无响应超时)
nb_get_retry
delay_before_retry
connect_port
}
}
real_server 192.168.233.147 {
weight
TCP_CHECK {
connect_timeout
nb_get_retry
delay_before_retry
connect_port
}
}
}
Backup:
[root@DIP-slave ~]# more /etc/keepalived/keepalived.conf
! Configuration File for keepalived global_defs {
notification_email {
caoguo@admin.com
}
notification_email_from sns-lvs@gmail.com
smtp_server 127.0.0.1
# smtp_connect_timeout
router_id LVS_DEVEL
} # written by :netseek
# VIP1
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id
priority
advert_int
authentication {
auth_type PASS
auth_pass
}
virtual_ipaddress {
192.168.233.250
#(如果有多个VIP,继续换行填写.)
}
} virtual_server 192.168.233.250 {
delay_loop
lb_algo wrr
lb_kind DR
persistence_timeout
protocol TCP real_server 192.168.233.146 {
weight #(权重)
TCP_CHECK {
connect_timeout #(10秒无响应超时)
nb_get_retry
delay_before_retry
connect_port
}
}
real_server 192.168.233.147 {
weight
TCP_CHECK {
connect_timeout
nb_get_retry
delay_before_retry
connect_port
}
}
}
四.启动
/etc/init.d/keepalived start
chkconfig keepalived on
五.检查
[root@DIP ~]# ip address show
: lo: <LOOPBACK,UP,LOWER_UP> mtu qdisc noqueue state UNKNOWN
link/loopback ::::: brd :::::
inet 127.0.0.1/ scope host lo
inet6 ::/ scope host
valid_lft forever preferred_lft forever
: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu qdisc pfifo_fast state UP qlen
link/ether :0c:::: brd ff:ff:ff:ff:ff:ff
inet 192.168.233.145/ brd 192.168.233.255 scope global eth0
inet 192.168.233.250/ scope global eth0
inet6 fe80::20c:29ff:fe29:/ scope link
valid_lft forever preferred_lft forever
[root@DIP ~]# ipvsadm -L -n
IP Virtual Server version 1.2. (size=)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.233.250: wrr persistent
-> 192.168.233.146: Route
-> 192.168.233.147: Route