springcloud - eureka Server高可用集群

è¿éåå¾çæè¿°

项目结构:

代码配置:

application.properties:

# 每次启动一个备用注册中心只需要修改active即可
spring.profiles.active=peer3
# 不向注册中心注册自己 true是注册,false是不注册自己
eureka.client.register-with-eureka=true
# 不检索服务
eureka.client.fetch-registry=true

application-peer1.properties:

server.port=1111
eureka.instance.hostname=peer1
eureka.client.service-url.defaultZone=http://peer2:2222/eureka/,http://peer3:3333/eureka/
spring.application.name=eureka-server

application-peer2.properties:

server.port=2222
eureka.instance.hostname=peer2
eureka.client.service-url.defaultZone=http://peer1:1111/eureka/,http://peer3:3333/eureka/
spring.application.name=eureka-server

application-peer3.properties:

server.port=3333
eureka.instance.hostname=peer3
eureka.client.service-url.defaultZone=http://peer1:1111/eureka/,http://peer2:2222/eureka/
spring.application.name=eureka-server

IDEA设置多实例启动

配置Host

将Host文件配置

127.0.0.1 peer1
127.0.0.1 peer2
127.0.0.1 peer3

去掉Single instance only选项即可

  • 修改spring.profiles.active=peer1,启动系统
  • 修改spring.profiles.active=peer2,启动系统
  • 修改spring.profiles.active=peer3,启动系统

启动peer1和peer2的时候都会报错,不用管,启动peer3的时候就不会报错了

分别访问http://localhost:1111/ ,http://localhost:2222/http://localhost:3333/

启动一个client端注册到集群:

client端配置:

再次访问http://localhost:1111/ ,http://localhost:2222/http://localhost:3333/

猜你喜欢

转载自blog.csdn.net/qq_26857649/article/details/82663271