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分支