改造背景:
许多公司微服务项目已经在使用zookeeper,为了方便服务管理,替换为zookeeper比较利于运维团队管理统一的注册中心。
解决:
按照本文如下五步对apollo配置中心改造,即可实现apollo注册中心替换为zookeeper。
注:保留原有组件之间调用关系,只是简单将原有去Eureka注册发现服务换为了Zookeeper,原有metaservice模块继续用作apollo内部组件服务注册发现,有时间可以自行将各个模块作为zk客户端改造下代码(只需将ServiceController类下放到各个模块查找服务即可)。
本文仅为zk服务端运维能监控和管理apollo组件。
1、最外层pom.xml改造
去除spring-cloud-starter-netflix-eureka-client
相关依赖
添加zk相关依赖,让三个组件均注册到zk:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zookeeper-all</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.10</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</d