In the past two days, there has been a problem that is very confusing, that is, when the ribbon, the provider and eureka are on the same server, everything is normal, but when the ribbon is placed on other servers, although it is also registered in eureka, it always accesses Failed question.
At this time, the resource file of the provider is as follows
spring.application.name=hello-service
eureka.client.service-url.defaultZone=http://peer1:1111/eureka/,http://peer2:1112/eureka
The registration information of eureka is as follows
After thinking about it, I found that http://HELLO-SERVICE/hello cannot be resolved, because only the host name is registered, which means that only the same host can be resolved. So the provider's resource file is modified as follows
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}
At this time, the registration information of eureka is as follows
Because hello-service has been converted into an IP address, everything is normal when accessing the provider with the ribbon registered by other servers.