spring cloud ribbon與提供者不在同一臺服務器訪問失敗的問題

最近這兩天一直有一個問題很困惑,那就是ribbon跟提供者以及eureka在同一臺服務器的時候訪問一切正常,而把ribbon放到其餘服務器的時候,雖然一樣註冊進了eureka,可是卻始終訪問失敗的問題。spring

這個時候提供者的資源文件以下服務器

spring.application.name=hello-service
eureka.client.service-url.defaultZone=http://peer1:1111/eureka/,http://peer2:1112/eureka

eureka的註冊信息以下app

通過思索,我發現實際上是http://HELLO-SERVICE/hello解析不了,由於註冊進去的其實只有主機名,也就是說只有相同主機才能解析。因此提供者的資源文件修改以下url

spring.application.name=hello-service
eureka.client.service-url.defaultZone=http://peer1:1111/eureka/,http://peer2:1112/eureka
eureka.instance.instance-id=${spring.cloud.client.ipAddress}:${server.port}
eureka.instance.prefer-ip-address=true
eureka.instance.hostname= ${spring.cloud.client.ipAddress}

此時eureka的註冊信息以下spa

由於hello-service已經轉換成了ip地址,此時用其餘服務器註冊的ribbon再來訪問該提供者時已經一切正常。server

相關文章
相關標籤/搜索