keepalived与lv负载均衡及高可用

一、主服务器配置

1、下载安装keepalived

yum install -y keepalived

2、编写/etc/keepalive/keepalive

global_defs {
    router_id LVS_DEVEL  每个keepalived软件id号
}
vrrp_instance VI_1 {
    state MASTER #MASTER BACKUP
    interface eth0 
    virtual_router_id 51 #虚拟路由ID,主备一样
    priority 101 优先级
    advert_int 1 心跳间隔,切换到备服务器
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.0.0.2/24 dev eth0 label eth0:0
    }
}
virtual_server 10.0.0.2 80 {
    delay_loop 6  过duojiu多久检查web服务器是否运行
    lb_algo rr
    lb_kind DR
    nat_mask 255.255.255.0
    persistence_timeout 50 会话保持时间
    protocol TCP
    real_server 10.0.0.7 80 {
        weight 1
        HTTP_GET {
            url {
                path /
                status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server 10.0.0.8 80 {
        weight 1
        HTTP_GET {
            url {
                path /
                status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_re
        }

    }
}

二、备服务器配置

1、下载安装keepalived

yum install -y keepalived

2、编写/etc/keepalive/keepalive

global_defs {
    router_id LVS_DEVEL
}
vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.0.0.2/24 dev eth0 label eth0:0
    }
}
virtual_server 10.0.0.2 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    nat_mask 255.255.255.0
    persistence_timeout 50
    protocol TCP
    real_server 10.0.0.7 80 {
        weight 1
        HTTP_GET {
            url {
                path /
                status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server 10.0.0.8 80 {
        weight 1
        HTTP_GET {
            url {
                path /
                status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_re
        }

    }
}

猜你喜欢

转载自blog.csdn.net/zsycsnd/article/details/81219495
今日推荐