翻看了不少网上的教程 千篇一律 经过个人实践 总结了几个要点:
# eureka server 高可用 配置 要点 eureka.instance.prefer-ip-address 不建议设置为true # eureka.client.registerWithEureka、 eureka.client.fetchRegistry 都要设置为true 默认值都为true # eureka.instance.appname =spring.application.name # 重要 defaultZone 高可用 不要使用ip 应该使用相应的域名DNS来配置 也就是 eureka.instance.hostname 指定DNS
样例配置 采用 3个实例集群 8761->8762->8763->8761 application.yml 如下:
运行指定配置文件 例如在springboot 可执行jar 执行
java -jar discovery-server-1.0-SNAPSHOT.jar --spring.profiles.active=master
--- server: port: 8761 spring: profiles: master application: name: DISCOVERY-SERVER eureka: environment: prod instance: # 此处配置域名 hostname: peer1 appname: DISCOVERY-SERVER client: healthcheck: enabled: true # 向服务注册中心注册 registerWithEureka: true # 检索服务 fetchRegistry: true serviceUrl: defaultZone: http://${eureka.instance.hostname}:8762/eureka/ server: enable-self-preservation: true --- server: port: 8762 spring: profiles: cluster1 application: name: DISCOVERY-SERVER eureka: environment: prod instance: # 此处配置域名 hostname: peer2 appname: DISCOVERY-SERVER client: healthcheck: enabled: true # 向服务注册中心注册 registerWithEureka: true # 检索服务 fetchRegistry: true serviceUrl: defaultZone: http://${eureka.instance.hostname}:8763/eureka/ server: enable-self-preservation: true --- server: port: 8763 spring: profiles: cluster2 application: name: DISCOVERY-SERVER eureka: environment: prod instance: # 此处配置域名 hostname: peer1 appname: DISCOVERY-SERVER client: healthcheck: enabled: true # 向服务注册中心注册 registerWithEureka: true # 检索服务 fetchRegistry: true serviceUrl: defaultZone: http://${eureka.instance.hostname}:8761/eureka/ server: enable-self-preservation: true