keepalived+lvs配置sorryserver

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了keepalived+lvs配置sorryserver相关的知识,希望对你有一定的参考价值。

keepalived+lvs配置sorryserver

当配置在lvs上的rs都无法访问到时,就需要有一台备用的服务器来提供报错页面,此服务器称为sorry_server。

配置sorry_server

准备主机4台

server hostname ip
keepalived s1 172.20.27.10
sorryserver web3 172.20.27.13
nginx web1 172.20.27.20
nginx web2 172.20.27.21

1.修改keepalived配置文件

virtual_server 172.20.27.100 80 
    delay_loop 6
    lb_algo wrr
    lb_kind DR
    protocol TCP
    sorry_server 172.20.27.13 80        #配置sorry_server的地址和端口
    real_server 172.20.27.20 80 
        weight 1
        HTTP_GET 
            url 
                path /monitor-page/index.html
                status_code 200
        
            nb_get_retry 3
            delay_before_retry 3
            connect_timeout 5
    

    real_server 172.20.27.21 80 
        weight 1
        HTTP_GET 
            url 
                path /monitor-page/index.html
                status_code 200
            
            nb_get_retry 3
            delay_before_retry 3
            connect_timeout 5
        
    

2.重启服务器查看lvs规则

#由于后端web1和web2服务没有启动,经过一段时间检测后,无法探测到主机就下线了,27.12的sorryserver上线提供服务
[[email protected] ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  172.20.27.100:80 wrr
  -> 172.20.27.20:80              Route   1      0          0         
  -> 172.20.27.21:80              Route   1      0          0         
[[email protected] ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  172.20.27.100:80 wrr
  -> 172.20.27.12:80              Route   1      0          0         

3.sorryserver上创建页面

[[email protected] ~]# echo ‘sorry!‘ > /var/www/html/index.html

4.在sorryserver上绑定vip地址

[[email protected] ~]# bash lvs_dr_rs.sh start
[[email protected] ~]# cat lvs_dr_rs.sh 
#!/bin/bash
vip=172.20.27.100
mask=‘255.255.255.255‘
dev=lo:1
case $1 in
start)
    echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
    echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
    echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
    echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
    ifconfig $dev $vip netmask $mask #broadcast $vip up
    #route add -host $vip dev $dev
    echo "The RS Server is Ready!"
    ;;
stop)
    ifconfig $dev down
    echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore
    echo 0 > /proc/sys/net/ipv4/conf/lo/arp_ignore
    echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce
    echo 0 > /proc/sys/net/ipv4/conf/lo/arp_announce
    echo "The RS Server is Canceled!"
    ;;
*)
    echo "Usage: $(basename $0) start|stop"
    exit 1
    ;;
esac

5.在客户端上测试访问

[[email protected] ~]# curl www.mylinuxops.com
sorry\!
#sorryserver开始提供服务

以上是关于keepalived+lvs配置sorryserver的主要内容,如果未能解决你的问题,请参考以下文章

LVS + Keepalived 配置详解

LVS+Keepalived高可用负载均衡架构原理及配置

LVS+Nginx(LVS + Keepalived + Nginx安装及配置)

RedHat 7配置keepalived+LVS实现高可用的Web负载均衡

LVS + Keepalived群集

Keepalived + LVS DR 配置 终版