0

我需要有关通过 Spring Boot 和 Zuul 配置功能区(负载平衡)的帮助。您可以在下面找到我的配置。

最初我会分享我当前的架构以及我想要达到的目标:

  • 我有一个带网关的节点(Spring Boot + zuul + Ribbon)
  • 我有另外两个节点将部署我的可扩展服务

祖尔配置:

zuul.routes.outlets.path=/outlets/**
zuul.routes.outlets.serviceId=outlets

outlets.ribbon.listOfServers=http://11.11.111.125:8092,http://11.11.111.126:8093
ribbon.eureka.enabled=false

只要你看到没有什么特别的。我的可扩展服务具有以下配置:

@SpringBootApplication
@PropertySource
@RibbonClient(name = "outlets", configuration = RibbonClientConfiguration.class)
public class OutletsApplication {

    public static void main(String[] args) {
        SpringApplication.run(OutletsApplication.class, args);
    }
}

@Configuration
public class RibbonClientConfiguration {

    @Bean
    public IClientConfig config() {
        return new DefaultClientConfigImpl();
    }

    @Bean
    public IPing ribbonPing(IClientConfig config) {
        return new PingUrl();
    }
}

据我了解,这是一个非常常见的配置。

如果我直接向http://11.11.111.125:8092/outletsor提出请求http://11.11.111.126:8093/outlets,一切正常。

但是当我向网关发出请求时,我收到 404。我在日志中可以看到:

Matching pattern:/outlets/**
Returning cached instance of singleton bean 'ribbonRestClient'
Zone aware logic disabled or there is only one zone
outlets using LB returned Server: 11.11.111.126:8093 for request /
RestClient sending new Request(GET: ) http://11.11.111.126:8093/
Get connection: {}->http://11.11.111.126:8093, timeout = 2000
[{}->http://11.11.111.126:8093] total kept alive: 2, total issued: 0, total allocated: 2 out of 200
Getting free connection [{}->http://11.11.111.126:8093][null]
Stale connection check
CookieSpec selected: ignoreCookies
Auth cache not set in the context
Target auth state: UNCHALLENGED
Proxy auth state: UNCHALLENGED
Attempt 1 to execute request
Sending request: GET / HTTP/1.1
 >> "GET / HTTP/1.1[\r][\n]"
 >> "accept-language: ru,en-US;q=0.8,en;q=0.6[\r][\n]"
 >> "x-forwarded-host: localhost:8080[\r][\n]"
 >> "x-forwarded-proto: http[\r][\n]"
 >> "x-forwarded-prefix: /outlets[\r][\n]"
 >> "upgrade-insecure-requests: 1[\r][\n]"
 >> "Accept-Encoding: gzip[\r][\n]"
 >> "accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8[\r][\n]"
 >> "user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36[\r][\n]"
 >> "Netflix.NFHttpClient.Version: 1.0[\r][\n]"
 >> "X-netflix-httpclientname: outlets[\r][\n]"
 >> "Host: 11.11.111.126:8093[\r][\n]"
 >> "Connection: Keep-Alive[\r][\n]"
 >> "[\r][\n]"
>> GET / HTTP/1.1
>> accept-language: ru,en-US;q=0.8,en;q=0.6
>> x-forwarded-host: localhost:8080
>> x-forwarded-proto: http
>> x-forwarded-prefix: /outlets
>> upgrade-insecure-requests: 1
>> Accept-Encoding: gzip
>> accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
>> user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36
>> Netflix.NFHttpClient.Version: 1.0
>> X-netflix-httpclientname: outlets
>> Host: 11.11.111.126:8093
>> Connection: Keep-Alive
 << "HTTP/1.1 404 Not Found[\r][\n]"
 << "Server: Apache-Coyote/1.1[\r][\n]"
 << "Content-Type: text/html;charset=UTF-8[\r][\n]"
 << "Content-Language: ru[\r][\n]"
 << "Content-Length: 306[\r][\n]"
 << "Date: Mon, 04 Apr 2016 21:47:16 GMT[\r][\n]"
 << "[\r][\n]"
 Receiving response: HTTP/1.1 404 Not Found
 << HTTP/1.1 404 Not Found
 << Server: Apache-Coyote/1.1
 << Content-Type: text/html;charset=UTF-8
 << Content-Language: ru
 << Content-Length: 306
 << Date: Mon, 04 Apr 2016 21:47:16 GMT
 Connection can be kept alive indefinitely
 << "<html><body><h1>Whitelabel Error Page</h1><p>This application has no explicit mapping for /error, so you are seeing this as a fallback.</p><div id='created'>Mon Apr 04 21:47:16 UTC 2016</div><div>There was an unexpected error (type=Not Found, status=404).</div><div>No message available</div></body></html>"

据我所知,服务请求不包含路径/出口。或者可能是我的功能区客户端配置错误?

而且我不知道如何解决它。

任何人都可以帮助我吗?

4

0 回答 0