springcloud —— 搭建高可用注册中心

##用途
在实际生产环境下单点的注册中心是存在缺陷的,当该节点宕机后,依赖他服务的微服务将出现故障,所以就需要一个高可用的注册中心来弥补这种缺陷。Eureka通过“伙伴”机制实现高可用。每一台Eureka都需要在配置中指定另一个Eureka的地址作为伙伴,Eureka启动时会向自己的伙伴节点获取当前已经存在的注册列表, 这样在向Eureka集群中新加机器时就不需要担心注册列表不完整的问题。
##项目架构
这里写图片描述

##配置文件
###总配置application.properties

spring.profiles.active=slave

##使用ip地址的形式定义注册中心的地址
eureka.instance.prefer-ip-address=true
#禁用自我保护模式
eureka.server.enable-self-preservation=false

###eureka server 启用安全验证
security.user.name=admin
security.user.password=123456
security.basic.enabled=true

#不向注册中心注册自己
#eureka.client.register-with-eureka=false
#注册中心的职责就是去维护服务实例,不需要去检索服务
#eureka.client.fetch-registry=false

##服务续约任务的调用间隔时间默认为30s
#eureka.instance.lease-renewal-interval-in-seconds=3
###定义服务失效的时间默认是90s
#eureka.instance.lease-expiration-duration-in-seconds=540

###注册中心1的配置application-slave.properties

spring.application.name=springcloud-eureka-server
server.port=8766

eureka.instance.instance-id=${spring.cloud.client.ipAddress}:${server.port}
eureka.instance.hostname=${spring.cloud.client.ipAddress}
eureka.client.serviceUrl.defaultZone=http://${security.user.name}:${security.user.password}@localhost:8765/eureka/
eureka.instance.status-page-url-path=/

###注册中心2的配置application-master.properties

spring.application.name=springcloud-eureka-server
server.port=8765

eureka.instance.instance-id=${spring.cloud.client.ipAddress}:${server.port}
eureka.instance.hostname=${spring.cloud.client.ipAddress}
eureka.client.serviceUrl.defaultZone=http://${security.user.name}:${security.user.password}@localhost:8766/eureka/
eureka.instance.status-page-url-path=/

##启动
首先先启动第一个服务,此时把总配置application.properties中的active设置成为slave。然后启动启动类,此时会报错,不过没关系。再启动第二个。

spring.profiles.active=slave
#spring.profiles.active=master

启动第二个服务的时候,此时把总配置application.properties中的active设置成为master。然后启动启动类。

#spring.profiles.active=slave
spring.profiles.active=master

此时就实现了高可用的注册中心了。
这里写图片描述

这里写图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值