Dubbo多注册中心和Zookeeper服务的迁移

简介: Dubbo多注册中心的服务迁移,即将服务从一个地儿迁到另一个地儿,例如从A地迁到B地。

一、Dubbo多注册中心


1、 应用场景


例如阿里有些服务来不及在青岛部署,只在杭州部署,而青岛的其它应用需要引用此服务,就可以将服务同时注册到两个注册中心。


consumer.xml
<?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"  
    xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://code.alibabatech.com/schema/dubbohttp://code.alibabatech.com/schema/dubbo/dubbo.xsd">  
    <dubbo:application name="world"  />  
    <!-- 多注册中心配置 -->  
    <dubbo:registry id="hangzhouRegistry" address="10.20.141.150:9090" />  
    <dubbo:registry id="qingdaoRegistry" address="10.20.141.151:9010" default="false" />  
    <!-- 向多个注册中心注册 -->  
    <dubbo:service interface="com.alibaba.hello.api.HelloService" version="1.0.0" ref="helloService" registry="hangzhouRegistry,qingdaoRegistry" />  
</beans>


2、不同服务使用不同注册中心

 

比如:CRM有些服务是专门为国际站设计的,有些服务是专门为中文站设计的。


consumer.xml
<?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"  
    xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://code.alibabatech.com/schema/dubbohttp://code.alibabatech.com/schema/dubbo/dubbo.xsd">  
    <dubbo:application name="world"  />  
    <!-- 多注册中心配置 -->  
    <dubbo:registry id="chinaRegistry" address="10.20.141.150:9090" />  
    <dubbo:registry id="intlRegistry" address="10.20.154.177:9010" default="false" />  
    <!-- 向中文站注册中心注册 -->  
    <dubbo:service interface="com.alibaba.hello.api.HelloService" version="1.0.0" ref="helloService" registry="chinaRegistry" />  
    <!-- 向国际站注册中心注册 -->  
    <dubbo:service interface="com.alibaba.hello.api.DemoService" version="1.0.0" ref="demoService" registry="intlRegistry" />  
</beans>


3、多注册中心引用

 

比如:CRM需同时调用中文站和国际站的PC2服务,PC2在中文站和国际站均有部署,接口及版本号都一样,但连的数据库不一样。


consumer.xml
<?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"  
    xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://code.alibabatech.com/schema/dubbohttp://code.alibabatech.com/schema/dubbo/dubbo.xsd">  
    <dubbo:application name="world"  />  
    <!-- 多注册中心配置 -->  
    <dubbo:registry id="chinaRegistry" address="10.20.141.150:9090" />  
    <dubbo:registry id="intlRegistry" address="10.20.154.177:9010" default="false" />  
    <!-- 引用中文站服务 -->  
    <dubbo:reference id="chinaHelloService" interface="com.alibaba.hello.api.HelloService" version="1.0.0" registry="chinaRegistry" />  
    <!-- 引用国际站站服务 -->  
    <dubbo:reference id="intlHelloService" interface="com.alibaba.hello.api.HelloService" version="1.0.0" registry="intlRegistry" />  
</beans>  
consumer.xml如果只是测试环境临时需要连接两个不同注册中心,使用竖号分隔多个不同注册中心地址:
<?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"  
    xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://code.alibabatech.com/schema/dubbohttp://code.alibabatech.com/schema/dubbo/dubbo.xsd">  
    <dubbo:application name="world"  />  
    <!-- 多注册中心配置,竖号分隔表示同时连接多个不同注册中心,同一注册中心的多个集群地址用逗号分隔 -->  
    <dubbo:registry address="10.20.141.150:9090|10.20.154.177:9010" />  
    <!-- 引用服务 -->  
    <dubbo:reference id="helloService" interface="com.alibaba.hello.api.HelloService" version="1.0.0" />  
</beans>


二、Dubbo多注册中心的服务迁移


1、顾名思义,将服务从一个地儿迁到另一个地儿,例如从A地迁到B地。


2、如何实现多注册中心的服务迁移


步骤一


    添加B地的注册中心地址,AB两地的注册中心间用英文的|分割,(同一个服务集群的zk节点使用逗号分割)


    例如:

dubbo.registry.address=192.168.220.128:2181|192.168.221.129:2181,192.168.221.130:2181,192.168.221.131:2181 这就是两个注册中心配置sample

步骤二


    Jenkins重新构建服务,zk1本身就是含有全部服务的,现在构建是将服务部署到zk2集群中。这样就可实现A的zk和B地的zk两套注册中心享有两套相同的服务


步骤三


    把服务的消费端都构建一遍;


步骤四


    先取消服务消费者调用zk1的服务,具体实施就是去掉第一个zk的配置,然后构建消费者


步骤五

 

  把服务提供者的配置也取消;然后重新构建服务提供者。这样就完成了将zk1中的所有服务迁移到zk2中,且去除zk1中的所有服务。


微信图片_20220430221226.png

相关文章
|
负载均衡 Kubernetes 网络协议
注册中心如何选型?Eureka、Zookeeper、Nacos怎么选
这是小卷对分布式系统架构学习的第9篇文章,继续探讨注册中心的原理及选型。文章详细介绍了Eureka、Nacos的工作机制与特点,并对比了Eureka、Nacos、Consul和Zookeeper在一致性协议、健康检查、负载均衡等方面的差异。最后根据不同的应用场景给出了注册中心的选型建议,帮助读者理解如何选择最适合的注册中心。
1073 100
|
存储 缓存 负载均衡
如何设计一个注册中心?以Zookeeper为例
本文介绍了分布式系统中注册中心的设计与工作原理,重点讲解了Zookeeper作为注册中心的实现。注册中心需具备服务注册、注销、心跳检测、服务查询等功能,确保高可用性。Zookeeper通过层次命名空间和znode存储数据,支持服务注册与发现,并采用发布-订阅模式通知消费者服务变更。然而,Zookeeper存在选举期间不可用的问题,不太适合作为注册中心,因其CP模型优先保证一致性而非可用性。
630 78
|
存储 负载均衡 监控
dubbo学习一:zookeeper与dubbo的关系,下载安装启动zookeeper(解决启动中报错)
这篇文章是关于Apache Dubbo框架与Zookeeper的关系,以及如何下载、安装和启动Zookeeper的教程,包括解决启动过程中可能遇到的报错问题。
624 3
dubbo学习一:zookeeper与dubbo的关系,下载安装启动zookeeper(解决启动中报错)
|
Dubbo 应用服务中间件 Apache
Dubbo 应用切换 ZooKeeper 注册中心实例,流量无损迁移
如果 Dubbo 应用使用 ZooKeeper 作为注册中心,现在需要切换到新的 ZooKeeper 实例,如何做到流量无损?
217 4
|
监控 Dubbo Java
dubbo学习三:springboot整合dubbo+zookeeper,并使用dubbo管理界面监控服务是否注册到zookeeper上。
这篇文章详细介绍了如何将Spring Boot与Dubbo和Zookeeper整合,并通过Dubbo管理界面监控服务注册情况。
1111 0
dubbo学习三:springboot整合dubbo+zookeeper,并使用dubbo管理界面监控服务是否注册到zookeeper上。
|
3月前
|
消息中间件 分布式计算 资源调度
《聊聊分布式》ZooKeeper与ZAB协议:分布式协调的核心引擎
ZooKeeper是一个开源的分布式协调服务,基于ZAB协议实现数据一致性,提供分布式锁、配置管理、领导者选举等核心功能,具有高可用、强一致和简单易用的特点,广泛应用于Kafka、Hadoop等大型分布式系统中。
|
安全 应用服务中间件 API
微服务分布式系统架构之zookeeper与dubbo-2
微服务分布式系统架构之zookeeper与dubbo-2
|
负载均衡 Java 应用服务中间件
微服务分布式系统架构之zookeeper与dubbor-1
微服务分布式系统架构之zookeeper与dubbor-1
|
存储 负载均衡 Dubbo
分布式-Zookeeper(一)
分布式-Zookeeper(一)
|
存储 SpringCloudAlibaba Java
【SpringCloud Alibaba系列】一文全面解析Zookeeper安装、常用命令、JavaAPI操作、Watch事件监听、分布式锁、集群搭建、核心理论
一文全面解析Zookeeper安装、常用命令、JavaAPI操作、Watch事件监听、分布式锁、集群搭建、核心理论。
【SpringCloud Alibaba系列】一文全面解析Zookeeper安装、常用命令、JavaAPI操作、Watch事件监听、分布式锁、集群搭建、核心理论