简体   繁体   English

带有 3 个 springboot 应用程序的 Ha 代理

[英]Ha Proxy with 3 springboot applications

I have 3 spring boot applications, each running on a different port.我有 3 个 Spring Boot 应用程序,每个应用程序都在不同的端口上运行。 Can someone guide me how to set up Ha Proxy to demonstarte load balancing between the 3 applications (can make multiple instances).有人可以指导我如何设置 Ha Proxy 来演示 3 个应用程序之间的负载平衡(可以创建多个实例)。 Is there any feature in spring boot which integrates Ha Proxy? Spring Boot 中是否有集成了 Ha Proxy 的功能? What are the thing that I have to change in the config file of Ha Proxy?我必须在 Ha Proxy 的配置文件中更改哪些内容?

Actually, there are several ways one can achieve this.实际上,有几种方法可以实现这一目标。 But, I don't think there is anything in spring boot to integrate with HAProxy, because they two are different processes and they two work independently and nothing linked to each other as you might know what spring boot does.但是,我认为 spring boot 中没有任何东西可以与 HAProxy 集成,因为它们两个是不同的进程,并且它们两个独立工作,并且没有任何相互关联的东西,你可能知道 spring boot 是做什么的。 And HAProxy is a load balancer, and also a proxy server for TCP and HTTP process that are distributed across multiple servers. HAProxy 是一个负载均衡器,也是分布在多个服务器上的 TCP 和 HTTP 进程的代理服务器。

That explains the first part of your question.这解释了你问题的第一部分。

Now actually, how can you achieve this is entirely based on how you want to set this up.现在实际上,您如何实现这一点完全取决于您希望如何设置。

  1. Run individual applications as service like you did, and route traffic to each of them based on url.像您一样将单个应用程序作为服务运行,并根据 url 将流量路由到每个应用程序。

  2. Another deploying the individual applications on a single tomcat and taking the help of context path in your application properties you can route traffic from outside world to tomcat while tomcat takes care of everything.另一个在单个 tomcat 上部署单个应用程序并利用应用程序属性中的上下文路径的帮助,您可以将来自外部世界的流量路由到 tomcat,而 tomcat 负责一切。

And there might be other ways to do this, someone can add in the future to this answer.可能还有其他方法可以做到这一点,将来有人可以添加到这个答案中。 But either way you need to use a proxy server to do this, it could be either HAProxy, Nginx, or anything that fits the purpose.但无论哪种方式,您都需要使用代理服务器来执行此操作,它可以是 HAProxy、Nginx 或任何适合此目的的东西。

So, taking your approach let's assume you are running your applications on port 8081, 8082, 8083. Your HAProxy setting should look something like this.因此,采用您的方法,让我们假设您在端口 8081、8082、8083 上运行您的应用程序。您的 HAProxy 设置应该如下所示。

frontend www_http
    mode            http
    bind            *:80
    bind            *:443 ssl crt /etc/ssl/certs/mycompany.pem

    # passing on that browser is using https
    reqadd X-Forwarded-Proto:\ https
    # for Clickjacking
    rspadd X-Frame-Options:\ SAMEORIGIN

    # prevent browser from using non-secure
    rspadd Strict-Transport-Security:\ max-age=15768000
    redirect        scheme https code 301 if !{ ssl_fc }

    stats enable
    stats refresh 30s
    stats show-node
    stats realm Haproxy\ Statistics
    stats uri /haproxy?stats

    acl app1 hdr(host) -i app1.mycompany.com
    acl app2 hdr(host) -i app2.mycompany.com
    acl app3 hdr(host) -i app3.mycompany.com

    # Just incase if you are using path instead of subdomain. But it's commented.
    # acl app1 url_beg /app1
    # acl app2 url_beg /app2
    # acl app3 url_beg /app3

    use_backend app_1_backend if app1
    use_backend app_2_backend if app2
    use_backend app_3_backend if app3

# backend for app 1
backend app_1_backend
    timeout client  300000
    timeout server  300000
    redirect scheme https if !{ ssl_fc }
    server app-1 127.0.0.1:8081 check
    http-response set-header X-TS-Server-ID %s

# backend for app 2
backend app_2_backend
    timeout client  300000
    timeout server  300000
    redirect scheme https if !{ ssl_fc }
    server app-2 127.0.0.1:8082 check
    http-response set-header X-TS-Server-ID %s

# backend for app 3
backend app_3_backend
    timeout client  300000
    timeout server  300000
    redirect scheme https if !{ ssl_fc }
    server app-3 127.0.0.1:8083 check
    http-response set-header X-TS-Server-ID %s

This is some basic setup, but you can add your options and change everything as you like.这是一些基本设置,但您可以添加选项并根据需要更改所有内容。

Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 springboot/ tomcat / apache 反向代理,其中哪些应用程序正在设置响应 header - Springboot/ tomcat / apache reverse proxy , which of those applications is setting the reponse header Springboot:重定向和反向代理 - Springboot: redirect and reverse-proxy springboot和mediawiki如何配置代理? - How to configure proxy for springboot and mediawiki? Springboot:在同一服务器上部署多个应用程序 - Springboot: Deploying multiple applications on the same server springboot 应用程序的 Zipkin 依赖图有更好的替代方案吗? - Is there a better alternative to Zipkin dependency graph for springboot applications? 将会话管理集中到其他Springboot应用程序 - Centralize session management to other Springboot applications SpringApplicationBuilder 结合小型 SpringBoot 应用程序(模块化单体) - SpringApplicationBuilder to combine small SpringBoot applications (modular Monolith) 使用Nginx作为代理的Springboot应用程序在Heroku上部署 - Springboot application with nginx as proxy deploy on Heroku SpringBoot:为代理GET Request创建一个请求工厂 - SpringBoot: create a request factory for proxy GET Request 带有Maven的Springboot示例无法在代理后面编译 - Springboot examples with maven do not compile behind a proxy
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM