gpt4 book ai didi

java - 如何使用 Envoy 作为 Java Web 服务的负载均衡器?

转载 作者:行者123 更新时间:2023-11-30 10:06:08 24 4
gpt4 key购买 nike

我正在尝试将 Envoy 设置为 Java 应用程序的负载平衡器。以下是我尝试实现的设置。

enter image description here

我关注了Envoy Tutorial得到一些想法并找到了代码。在那里,他们使用前端特使容器作为单个前端服务,在许多后端容器之间分配流量。但是对于我的工作,我不需要这样的前端容器。所以我修改了代码,以下是我创建的文件。

服务特使.yaml

static_resources:
listeners:
- address:
socket_address:
address: 0.0.0.0
port_value: 80
filter_chains:
- filters:
- name: envoy.http_connection_manager
config:
codec_type: auto
stat_prefix: ingress_http
route_config:
name: local_route
virtual_hosts:
- name: service
domains:
- "*"
routes:
- match:
prefix: "/service"
route:
cluster: local_service
http_filters:
- name: envoy.router
config: {}
clusters:
- name: local_service
connect_timeout: 0.25s
type: strict_dns
lb_policy: round_robin
hosts:
- socket_address:
address: 127.0.0.1
port_value: 9000
admin:
access_log_path: "/dev/null"
address:
socket_address:
address: 0.0.0.0
port_value: 8081

Dockerfile 服务

FROM envoyproxy/envoy-alpine:latest
FROM java:8

ADD gs-actuator-service-0.1.0.jar gs-actuator-service-0.1.0.jar

ADD ./start_service.sh /usr/local/bin/start_service.sh
RUN chmod u+x /usr/local/bin/start_service.sh
ENTRYPOINT /usr/local/bin/start_service.sh

启动服务.sh

#!/bin/sh

java -jar gs-actuator-service-0.1.0.jar &
envoy -c /etc/service-envoy.yaml --service-cluster service${SERVICE_NAME}

docker-compose.yml

version: '2'
services:

service1:
build:
context: .
dockerfile: Dockerfile-service
volumes:
- ./service-envoy.yaml:/etc/service-envoy.yaml
networks:
envoymesh:
aliases:
- service1
environment:
- SERVICE_NAME=1
expose:
- "80"

networks:
envoymesh: {}

gs-actuator-service-0.1.0.jar 是包含网络服务的 jar 文件。在本地运行时,可以使用

调用
localhost:9000/prime?number=10

当我运行时

sudo docker-compose up --build

它给出以下输出,最后有一行错误。

Building service1
Step 1/6 : FROM envoyproxy/envoy-alpine:latest
---> 44b4a2e0acd8
Step 2/6 : FROM java:8
---> d23bdf5b1b1b
Step 3/6 : ADD gs-actuator-service-0.1.0.jar gs-actuator-service-0.1.0.jar
---> fee1f402b547
Step 4/6 : ADD ./start_service.sh /usr/local/bin/start_service.sh
---> 52c2cc17c4dd
Step 5/6 : RUN chmod u+x /usr/local/bin/start_service.sh
---> Running in 95ee0537c3d1
Removing intermediate container 95ee0537c3d1
---> d8e9bdb2f95e
Step 6/6 : ENTRYPOINT /usr/local/bin/start_service.sh
---> Running in 27b20f261c0f
Removing intermediate container 27b20f261c0f
---> 26080be0b5ea
Successfully built 26080be0b5ea
Successfully tagged frontproxy_service1:latest
Recreating frontproxy_service1_1 ...
Recreating frontproxy_service1_1 ... done
Attaching to frontproxy_service1_1
service1_1 | /usr/local/bin/start_service.sh: 3:
/usr/local/bin/start_service.sh: envoy: not found
frontproxy_service1_1 exited with code 127

谁能指出我哪里错了?

谢谢

最佳答案

你在 Windows 上吗?如果是,请使用 Notepad++ 检查所有文件,然后在右下角可以将 CR LF 更改为 LF。在所有文件中更改它,保存它并尝试再次运行它。

关于java - 如何使用 Envoy 作为 Java Web 服务的负载均衡器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54813690/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com