首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >HaProxy有用于spring引导应用程序的负载平衡器。

HaProxy有用于spring引导应用程序的负载平衡器。
EN

Stack Overflow用户
提问于 2020-05-24 19:05:45
回答 1查看 1.1K关注 0票数 1

我已经将have配置为两个容器弹簧引导应用程序的负载均衡器。

下面是示例停靠程序编写文件的配置

代码语言:javascript
复制
version: '3.3'

services:
  wechat-1:
    image: xxxxxx/wechat-social-connector:2.0.0
    container_name: wechat-1
    ports:
     - 81:8000
    networks:
     - web 
    #depends_on:
     #- wechat-2

  wechat-2:
    image: xxxxxxxxx/wechat-social-connector:2.0.0
    container_name: wechat-2
    ports:
     - 82:8000
    networks:
     - web

  haproxy:
    build: ./haproxy
    container_name: haproxy
    ports:
     - 80:80
    networks:
     - web
    #depends_on:
     #- wechat-1


networks:
 web:

码头文件

代码语言:javascript
复制
FROM haproxy:2.1.4
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg

HA配置文件

代码语言:javascript
复制
global
    debug
    daemon
    maxconn 2000

defaults
    mode http
    timeout connect 5000ms
    timeout client  50000ms
    timeout server  50000ms

frontend http-in
    bind *:80
    default_backend servers

backend servers
    mode http
    option httpchk
    balance roundrobin
    server wechat-1 wechat-1:81 check
    server wechat-2 wechat-2:82 check

当我试图使用端口号80访问我的端点时,我总是使服务不可用。

从haproxy日志调试后,注意到以下错误

代码语言:javascript
复制
Creating haproxy  ... done
Creating wechat-2 ... done
Creating wechat-1 ... done
Attaching to wechat-2, wechat-1, haproxy
haproxy     | Available polling systems :
haproxy     |       epoll : pref=300,  test result OK
haproxy     |        poll : pref=200,  test result OK
haproxy     |      select : pref=150,  test result FAILED
haproxy     | Total: 3 (2 usable), will use epoll.
haproxy     | 
haproxy     | Available filters :
haproxy     |   [SPOE] spoe
haproxy     |   [CACHE] cache
haproxy     |   [FCGI] fcgi-app
haproxy     |   [TRACE] trace
haproxy     |   [COMP] compression
haproxy     | Using epoll() as the polling mechanism.
haproxy     | [NOTICE] 144/185524 (1) : New worker #1 (8) forked
haproxy     | [WARNING] 144/185524 (8) : Server servers/wechat-1 is DOWN, reason: Layer4 connection problem, info: "Connection refused", check duration: 0ms. 1 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
haproxy     | [WARNING] 144/185525 (8) : Server servers/wechat-2 is DOWN, reason: Layer4 connection problem, info: "Connection refused", check duration: 0ms. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
haproxy     | [ALERT] 144/185525 (8) : backend 'servers' has no server available!

从日志中我了解到,当haproxy无法连接其他两个容器时,这两个容器运行得很完美,没有任何问题。我厌倦了使用depends_on属性(评论时间),但问题仍然存在。

有人能帮我解决这个问题吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-24 20:42:44

请尝试下面的配置。haproxy.cfg中的几个变化

docker-compose.yaml

代码语言:javascript
复制
version: '3.3'

services:
  wechat-1:
    image: nginx
    container_name: wechat-1
    ports:
     - 81:80
    networks:
     - web
    depends_on:
     - wechat-2

  wechat-2:
    image: nginx
    container_name: wechat-2
    ports:
     - 82:80
    networks:
     - web

  haproxy:
    build: ./haproxy
    container_name: haproxy
    ports:
     - 80:80
    networks:
     - web
    depends_on:
     - wechat-1

networks:
 web:

Dockerfile

代码语言:javascript
复制
FROM haproxy
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg

haproxy.cfg

代码语言:javascript
复制
global
    debug
    daemon
    maxconn 2000

defaults
    mode http
    timeout connect 5000ms
    timeout client  50000ms
    timeout server  50000ms

frontend http-in
    bind *:80
    default_backend servers

backend servers
    mode http
    option forwardfor
    balance roundrobin
    server wechat-1 wechat-1:80 check
    server wechat-2 wechat-2:80 check

HAPROXY原木

代码语言:javascript
复制
Attaching to wechat-2, wechat-1, haproxy
haproxy     | Using epoll() as the polling mechanism.
haproxy     | Available polling systems :
haproxy     |       epoll : pref=300,  test result OK
haproxy     |        poll : pref=200,  test result OK
haproxy     |      select : pref=150,  test result FAILED
haproxy     | Total: 3 (2 usable), will use epoll.
haproxy     | 
haproxy     | Available filters :
haproxy     |   [SPOE] spoe
haproxy     |   [CACHE] cache
haproxy     |   [FCGI] fcgi-app
haproxy     |   [TRACE] trace
haproxy     |   [COMP] compression
haproxy     | [NOTICE] 144/204217 (1) : New worker #1 (6) forked
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61991049

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档