Eureka整合Spring Cloud Config Native 模式,实现在线扩容

前言:

spring cloud eureka的高可用之在线扩容,只要结合上一节Config Bus热刷新,便轻松实现。先奉上源码

实现步骤:

1. 一个eureka server 和一个eureka client

  1. 启动good-config-server模块,更改配置文件

eureka-client.yml的配置设置如下

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/ # one eureka server

eureka-server-peer1.yml配置如下

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/ # one eureka server
  1. 执行curl -X POST http://localhost:8888/actuator/bus-refresh使上面更改生效
  2. 启动good-eureka-server,profile=peer1
  3. 启动good-eureka-client
  4. 验证:
good-spring-cloud git:(master)curl -i http://127.0.0.1:8761/query/eureka-server      
{"defaultZone":"http://localhost:8761/eureka/"}
good-spring-cloud git:(master)curl -i http://127.0.0.1:8081/query/eureka-server
{"defaultZone":"http://localhost:8761/eureka/"}

2. 添加第二个eureka server

  1. 更改配置文件

eureka-client.yml的配置设置如下

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/,http://localhost:8762/eureka/ # two eureka server

eureka-server-peer1.yml配置如下

server:
  port: 8761
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8762/eureka/ # two eureka server

eureka-server-peer2.yml配置如下

server:
  port: 8762
eureka:
  client:
    serviceUrl:
	      defaultZone: http://localhost:8761/eureka/ # two eureka server
  1. 执行curl -X POST http://localhost:8888/actuator/bus-refresh使上面更改生效
  2. 启动good-eureka-server,profile=peer2,这里面peer1不用动
  3. 验证:
➜  good-spring-cloud git:(master)curl -i http://127.0.0.1:8081/query/eureka-server       
{"defaultZone":"http://localhost:8761/eureka/,http://localhost:8762/eureka/"}%
➜  good-spring-cloud git:(master)curl -i http://127.0.0.1:8761/query/eureka-server
{"defaultZone":"http://localhost:8762/eureka/"}%
➜  good-spring-cloud git:(master)curl -i http://127.0.0.1:8762/query/eureka-server
{"defaultZone":"http://localhost:8761/eureka/"}%         

2. 添加第三个eureka server

  1. 更改配置文件
    eureka-client.yml的配置设置如下
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/,http://localhost:8762/eureka/,http://localhost:8763/eureka/ # three eureka server

eureka-server-peer1.yml配置如下

server:
  port: 8761
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8762/eureka/,http://localhost:8763/eureka/ # three eureka server

eureka-server-peer2.yml配置如下

server:
  port: 8762
eureka:
  client:
    serviceUrl:
	      defaultZone: http://localhost:8761/eureka/,http://localhost:8763/eureka/ # three eureka server

eureka-server-peer3.yml配置如下

server:
  port: 8763
eureka:
  client:
    serviceUrl:
	      defaultZone: http://localhost:8761/eureka/,http://localhost:8762/eureka/ # three eureka server
  1. 执行curl -X POST http://localhost:8888/actuator/bus-refresh使上面更改生效
  2. 启动good-eureka-server,profile=peer3,这里面peer1,peer2不用动
  3. 验证:
➜  good-spring-cloud git:(master) curl http://127.0.0.1:8081/query/eureka-server       
{"defaultZone":"http://localhost:8761/eureka/,http://localhost:8762/eureka/,http://localhost:8763/eureka/"}%
➜  good-spring-cloud git:(master) curl http://127.0.0.1:8761/query/eureka-server       
{"defaultZone":"http://localhost:8762/eureka/,http://localhost:8763/eureka/"}%
➜  good-spring-cloud git:(master) curl -i http://127.0.0.1:8762/query/eureka-server       
{"defaultZone":"http://localhost:8761/eureka/,http://localhost:8763/eureka/"}%
➜  good-spring-cloud git:(master) curl -i http://127.0.0.1:8763/query/eureka-server
{"defaultZone":"http://localhost:8761/eureka/,http://localhost:8762/eureka/"}%

结束语

通过学习提高工作效率和质量,在学习中留点记录,方便日后回忆,记录之处过于随意,如有错误或不当之处,还请客官指正,相互学习!
参考书籍:重新定义springcloud实战

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值