Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot HaProxy具有用于spring boot应用程序的负载平衡器_Spring Boot_Docker_Docker Compose_Haproxy - Fatal编程技术网

Spring boot HaProxy具有用于spring boot应用程序的负载平衡器

Spring boot HaProxy具有用于spring boot应用程序的负载平衡器,spring-boot,docker,docker-compose,haproxy,Spring Boot,Docker,Docker Compose,Haproxy,我已经将haproxy配置为两个容器化spring引导应用程序的负载平衡器 下面是docker compose文件配置示例 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:

我已经将haproxy配置为两个容器化spring引导应用程序的负载平衡器

下面是docker compose文件配置示例

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:


Docker文件

FROM haproxy:2.1.4
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg

HA配置文件

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日志进行调试后,注意到以下错误

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属性(暂时评论)仍然存在同样的问题


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

请尝试以下配置。
haproxy.cfg中几乎没有变化

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
docker compose.yaml

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

FROM haproxy
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
haproxy.cfg

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原木

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


现在开始工作了。我应该使用内部端口而不是外部端口吗?你有什么理由解释HAProxy的工作原理-服务名称:containerPort。由于外部端口是供您直接访问服务的,但在代理之后,请求会从同一端口发出。如果您想查看教程,请查看此处