keepalived主备模式

Posted

tags:

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

主节点ip:192.168.3.122,备节点ip:192.168.3.123

主节点配置如下:

! Configuration file for keepalived
global_defs {
   notification_email {
    admin@wf.com
        }
   notification_email_from admin@wf.com
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
#监控huawei-grpc
vrrp_script chk_nginx {
    script "/etc/keepalived/script/monitor_nginx.sh"
    interval 2
    weight 2
}

vrrp_instance VI_1 {
    state MASTER  #主从设置
    interface em1  #网卡名
    virtual_router_id 1
    mcast_src_ip 192.168.3.122 #本机ip
    priority 100  #从机小于主机
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass chtopnet
    }
    virtual_ipaddress {
        192.168.3.120  #VIP 的IP
    }
    #track_script {
    #chk_nginx
    #}

}

virtual_server 192.168.3.120 50051 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 50
    protocol TCP

    real_server 192.168.3.122 50051 {
        weight 3
        TCP_CHECK {
            connect_timeout 10
            retry 3
            delay_before_retry 3
            connect_port 50051
        }
    }
 real_server 192.168.3.123 50051 {
        weight 3
        TCP_CHECK {
            connect_timeout 10
            nb_get_retry 3
            delay_before_retry 3
            connect_port 50051
        }
    }
}

备节点配置如下:

! Configuration file for keepalived
global_defs {
   notification_email {
    admin@wf.com
        }
   notification_email_from admin@wf.com
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
#监控huawei-grpc
vrrp_script chk_nginx {
    script "/etc/keepalived/script/monitor_nginx.sh"
    interval 2
    weight 2
}

vrrp_instance VI_1 {
    state BACKUP  #主从设置
    interface em1  #网卡名
    virtual_router_id 1
    mcast_src_ip 192.168.3.123 #本机ip
    priority 50  #从机小于主机
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass chtopnet
    }
    virtual_ipaddress {
        192.168.3.120  #VIP 的IP
    }
    #track_script {
    #chk_nginx
    #}

}

virtual_server 192.168.3.120 50051 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 50
    protocol TCP

    real_server 192.168.3.122 50051 {
        weight 3
        TCP_CHECK {
            connect_timeout 10
            retry 3
            delay_before_retry 3
            connect_port 50051
        }
    }
 real_server 192.168.3.123 50051 {
        weight 3
        TCP_CHECK {
            connect_timeout 10
            nb_get_retry 3
            delay_before_retry 3
            connect_port 50051
        }
    }
}

以上是关于keepalived主备模式的主要内容,如果未能解决你的问题,请参考以下文章

5 keepalived高可用ipvs(主备模式)

nginx+keepalived实现主备模式高可用

Nginx + Keepalived(主备模式)实现负载均衡高可用浅析

实战:Keepalived 高可用LVS-主备模式

Ansible实现主备模式的高可用(Keepalived)

Linux搭建nginx+keepalived 高可用(主备+双主模式)