47°

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,http://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,http://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,http://localhost:8762/eureka

bootstrap.yml配置应用名称:

spring:
  application:
    name: spring-cloud-eureka

 

配置java启动类node1、node2

 

 

 

启动EurekaApplication、node1、node2启动类,访问http://localhost:8761/http://localhost:8762/http://localhost:8763/成功则说明Eureka集群配置成功。

Eureka集群示例项目代码github地址:https://github.com/yuanzipeng/spring-cloud-eureka cluster分支

 

本文转载自博客园,原文链接:https://www.cnblogs.com/yuanzipeng/p/13054508.html

全部评论: 0

    我有话说: