首页 > 其他分享 >Keepalived lvs

Keepalived lvs

时间:2022-08-20 11:23:12浏览次数:71  
标签:lvs weight ip Keepalived 192.168 priority 80 net

keepalived

选举策略

首先,每个节点有一个初始优先级,由配置文件中的priority配置项指定,MASTER 节点的 priority 应比 BAKCUP 高。运行过程中 keepalived 根据 vrrp_script 的 weight 设定,增加或减小节点优先级。规则如下:

  1. weight
    

    值为正时,脚本检测成功时”weight”值会加到”priority”上,检测失败时不加

    • 主失败: 主priority < 备priority+weight之和时会切换
    • 主成功: 主priority+weight之和 > 备priority+weight之和时,主依然为主,即不发生切换
  2. weight
    

    为负数时,脚本检测成功时”weight”不影响”priority”,检测失败时,Master节点的权值将是“priority“值与“weight”值之差

    • 主失败: 主priotity-abs(weight) < 备priority时会发生切换
    • 主成功: 主priority > 备priority 不切换
  3. 当两个节点的优先级相同时,以节点发送VRRP通告的 IP 作为比较对象,IP较大者为MASTER。

安装依赖

gcc-c++ openssl-devel libnl libnl-devel

部署文章:

https://zhuanlan.zhihu.com/p/143295216

keepalived.conf

! Configuration File for keepalived

global_defs {

   router_id 51               #唯一ID

}

vrrp_instance VI_1 {
    state MASTER            #备机为BACKUP
    interface ens33
    virtual_router_id 51    #id相同为在同一主备关系中
    priority 100            #优先级
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.0.123/24     #虚拟ip
    }
}

virtual_server 192.168.0.123 80 {      #虚拟ip
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 5
    protocol TCP

    sorry_server 192.168.0.123 80

    real_server 192.168.0.110 80 {       #后端真实ip
        weight 1
        TCP_CHECK {
            connect_timeout 10 
            retry 3       
            delay_before_retry 3 
            connect_port 80        
        }
    }

    real_server 192.168.0.120 80 {       #后端真实ip
        weight 1
        TCP_CHECK {
            connect_timeout 10 
            retry 3       
            delay_before_retry 3 
            connect_port 80        
        }
    }    
    
}
#安装ipvasadm
yum install -y ipvsadm

#监测连接保持状态
watch ipvsadm -L -n -c

#查看连接记录
ipvsadm -L --stats

真实服务端配置

ifconfig命令需要安装 net-tools

ifconfig lo:0 虚拟ip netmask 255.255.255.255 broadcast 虚拟ip
/sbin/route add -host 虚拟ip 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
sysctl -p

标签:lvs,weight,ip,Keepalived,192.168,priority,80,net
From: https://www.cnblogs.com/yy9knsg/p/16607371.html

相关文章