keepalive 和 haproxy 高可用配置

NodeA

vi /etc/keepalived/keepalived.conf
systemctl enable keepalived && systemctl start keepalived && systemctl status keepalived

! Configuration File for keepalived

global_defs {
   notification_email {
     13802883042@139.com
   }
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id NodeA
}

vrrp_script chk {
#    script "/apps/sh/#app#_check.sh"
    interval 2
    weight -1
}

vrrp_instance VI_1 {
    state MASTER
    # 修改网卡
    interface ens192
    virtual_router_id 186
    # 优先级
    priority 100
    advert_int 1
    smtp alert

    track_interface {
        ens192
    }
#    track_script {
#        chk
#    }
    authentication {
        auth_type PASS
        auth_pass kePw@019
    }
    virtual_ipaddress {
        192.168.40.114/24 dev ens192 label ens192:1
    }
}

vi /etc/haproxy/haproxy.cfg
systemctl enable haproxy && systemctl restart haproxy && systemctl status haproxy

global
        chroot        /var/lib/haproxy
        log           127.0.0.1 local2
        maxconn       65536
        user          haproxy
        group         haproxy
        nbproc        1
        ulimit-n      231097
        pidfile       /var/run/haproxy.pid
        daemon

defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        option  forwardfor
        option  redispatch
        retries 3
        maxconn 65535
        timeout connect 5s
        timeout client 30s
        timeout server 30s
        timeout check   1s
        timeout http-request    10s
        timeout http-keep-alive 10s

listen Stats
        bind *:10000
        mode  http
        stats enable
        stats uri /stats
        stats show-node
        stats show-legends
        stats auth admin:Admin@139

frontend http_web
        bind 0.0.0.0:30432
        mode http
        log global
        option httplog
        option httpclose
        default_backend vip_1_servers

backend vip_1_servers
        balance leastconn
        http-request set-header Host cdn.service.com
        server nodeA   192.168.40.11:80  maxconn 10000  check inter 3000 fall 3 rise 5
        server nodeB   192.168.40.15:80  check inter 3000 fall 3 rise 5

NodeB

vi /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
   notification_email {
     13802883042@139.com
   }
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id NodeB
}

vrrp_script chk {
#    script "/apps/sh/#app#_check.sh"
    interval 2
    weight -1
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens192
    virtual_router_id 186
    priority 98
    advert_int 1
    smtp alert

    track_interface {
        ens192
    }
#    track_script {
#        chk
#    }
    authentication {
        auth_type PASS
        auth_pass kePw@019
    }
    virtual_ipaddress {
        192.168.40.114/24 dev ens192 label ens192:1
    }
}

vi /etc/haproxy/haproxy.cfg

global
        chroot        /var/lib/haproxy
        log           127.0.0.1 local2
        maxconn       65536
        user          haproxy
        group         haproxy
        nbproc        1
        ulimit-n      231097
        pidfile       /var/run/haproxy.pid
        daemon

defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        option  forwardfor
    option  redispatch
        retries 3
        maxconn 65535
        timeout connect 5s
        timeout client 30s
        timeout server 30s
        timeout check   1s
        timeout http-request    10s
        timeout http-keep-alive 10s

listen Stats
        bind *:10000
        mode  http
        stats enable
        stats uri /stats
        stats show-node
        stats show-legends
        stats auth admin:Admin@139

frontend http_web
        bind 0.0.0.0:30432
        mode http
        log global
        option httplog
        option httpclose
        default_backend vip_1_servers

backend vip_1_servers
        balance leastconn
        http-request set-header Host cdn.service.com
        server nodeA   192.168.40.11:80  maxconn 10000  check inter 3000 fall 3 rise 5
        server nodeB   192.168.40.15:80  check inter 3000 fall 3 rise 5
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
keepalive和nginx都与高可用相关。keepalive是一个用于维持TCP连接的工具,它可以确保在网络中的连接保持活跃,从而提高服务的可用性和可靠性。而nginx是一个高性能的Web服务器和反向代理服务器,它可以处理大量的并发连接并分发请求到不同的后端服务器,从而提供高可用性和负载均衡。在高可用的部署中,我们可以将nginx和keepalive结合使用,通过配置keepalive来监控后端服务器的健康状态,并使用nginx来实现负载均衡和故障转移,以保证系统的高可用性。引用中的命令systemctl enable nginx keepalived用于启用nginx和keepalived服务,使其在系统启动时自动运行。引用中的命令systemctl enable kubelet用于启用kubelet服务,kubelet是Kubernetes集群中的一个核心组件,它负责管理节点上的容器和Pod。而引用中的命令vim /etc/nginx/nginx.conf用于编辑nginx的配置文件,通过配置nginx的参数和指令可以实现高可用性的设置,例如配置反向代理、负载均衡和健康检查等。因此,通过结合keepalive和nginx的使用,我们可以实现高可用的部署和管理。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [keepalive+nginx高可用K8S集群部署](https://blog.csdn.net/fzqdyyd/article/details/127340860)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值