By default, Eureka uses hostname for service registration and display of service information, so how do we configure it if we use an IP address? The answer is eureka.instance.prefer-ip-address=true
.
Purpose: We are configured eureka.instance.prefer-ip-address=true
to ensure that Eureka Server hostname use IP addresses when registering with each other while using IP addresses as eureka.client.service-url.defaultZone
configuration values.
Eureka Server Cluster Configuration:
Debug:TrueSpring: Application: Name:Eureka-serverLogging: Level : Com.netflix.eureka: ' off ' Com.netflix.discovery: ' off '---Spring: Profiles:Manager1Server: Port:8100Eureka: instance: prefer-ip-address:True#以IP地址注册到服务中心, registering each other with an IP address #ip-address:192.168.1.1 #强制指定IP地址, the default is to get the IP address of the machine Client: Service-url: Defaultzone:http://192.168.1.2:8100/eureka/,http://192.168.1.3:8100/eureka/---Spring: Profiles:Manager2Server: Port:8100Eureka: instance: prefer-ip-address:TrueClient: Service-url: Defaultzone:http://192.168.1.1:8100/eureka/,http://192.168.1.3:8100/eureka/---Spring: Profiles:Manager3Server: Port:8100Eureka: instance: prefer-ip-address:TrueClient: Service-url: Defaultzone:http://192.168.1.1:8100/eureka/,http://192.168.1.2:8100/eureka/
Eureka Client Configuration:
debug: truespring: application: name: eureka-clientserver: port: 8110eureka: instance: prefer-ip-address:#以IP地址注册到服务中心 #instance-id: http://192.168.1.4:8110 #服务中心的信息显示(如果IP地址不显示的话,进行配置) client: service-url: defaultZone: http://192.168.1.1:8100/eureka/,http://192.168.1.2:8100/eureka/,http://192.168.1.3:8100/eureka/
Implementation effect (for reference only, does not contain Eureka Server Mutual registration IP addresses):
It is important to note that the above tests are not tested and are theoretically feasible.
Resources:
- Eureka Service Registration Process detailed IPAddress (Detailed eureka.instance.prefer-ip-address = True and eureka.instance.prefer-ip-address)
- Eureka Service Registration List Display IP problem research
- Can I Force Eureka registrations to use an IP address instead of a hostname?
- Spring-cloud-netflix
Spring Cloud Eureka using IP addresses for service registration