spring Cloud服务注册中心Eureka集群
spring Cloud服务注册中心Eureka集群配置:
在application.yml文件加以下配置:
server: port: 8761 tomcat: uri-encoding: UTF-8 eureka: instance: hostname: localhost prefer-ip-address: true # 优先使用IP地址方式进行注册服务 appname: ${spring.application.name} leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 server: enableSelfPreservation: false evictionIntervalTimerInMs: 4000 client: register-with-eureka: true fetch-registry: true service-url: defaultZone: http://localhost:8762/eureka,//localhost:8763/eureka
application-node1.yml文件加以下配置:
server: port: 8762 tomcat: uri-encoding: UTF-8 eureka: instance: hostname: localhost prefer-ip-address: true # 优先使用IP地址方式进行注册服务 appname: ${spring.application.name} leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 server: enableSelfPreservation: false evictionIntervalTimerInMs: 4000 client: register-with-eureka: true fetch-registry: true service-url: defaultZone: http://localhost:8761/eureka,//localhost:8763/eureka
application-node2.yml文件加以下配置:
server: port: 8763 tomcat: uri-encoding: UTF-8 eureka: instance: hostname: localhost prefer-ip-address: true # 优先使用IP地址方式进行注册服务 appname: ${spring.application.name} leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 server: enableSelfPreservation: false evictionIntervalTimerInMs: 4000 client: register-with-eureka: true fetch-registry: true service-url: defaultZone: http://localhost:8761/eureka,//localhost:8762/eureka
bootstrap.yml配置应用名称:
spring:
application:
name: spring-cloud-eureka
配置java启动类node1、node2
启动EurekaApplication、node1、node2启动类,访问//localhost:8761/、//localhost:8762/、//localhost:8763/成功则说明Eureka集群配置成功。
Eureka集群示例项目代码github地址://github.com/yuanzipeng/spring-cloud-eureka cluster分支