問題記錄:服務註冊中心用eureka換爲ZooKeeper...

#最最最重要的問題
版本問題
當Maven中有多個引用,包與包之間的引用衝突,包與使用的軟件之間的衝突

##細節問題
zooKeeper版本與引用的包的版本不對應
Q:
org.apache.zookeeper.KeeperException$UnimplementedException: KeeperErrorCode = Unimplemented for…

A:
spring-cloud-starter-zookeeper-discovery 2.0.0依賴的curator版本爲4.0.1;
Curator 4.0 has a hard dependency on ZooKeeper 3.5.x
If you are using ZooKeeper 3.5.x there’s nothing additional to do - just use Curator 4.0

參考: https://blog.csdn.net/forget_me_not1991/article/details/80902055


ZooKeeper中節點路徑是唯一的,該路徑下已有節點時,繼續往當前路徑上新建節點就會報這個錯
Q:
KeeperErrorCode = NoNode for …

A:
關閉ZooKeeper,將zoo.cfg裏的自己設定的dataDir和dataLogDir路徑下的version-2文件夾,然後重啓即可。


服務註冊中心使用ZooKeeper:服務節點無法註冊到zookeeper

Q: 服務註冊中心用eureka換爲ZooKeeper,zookeeper正常啓動且telnet檢測正常

按照教程:

添加

@EnableDiscoveryClient
<dependency>  
     <groupId>org.springframework.cloud</groupId>
     <artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
   </dependency>
spring:
  cloud:
    zookeeper:
      connect-string: localhost:2181
      discovery:
        //register: true
        //enabled: true
        root: /cloud  

註釋掉

@EnableEurekaClient
<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

啓動不報錯,但是服務節點無法註冊到zookeeper

A:
檢查依賴中有無spring-cloud-starter包:

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter</artifactId>
        </dependency>

注意
spring.cloud.zookeeper.discovery的register屬性:
默認爲true,設置爲false時,不去註冊

遺留問題:

  1. 不添加@EnableEurekaClient和@EnableDiscoveryClient都可以註冊成功
  2. zookeeper會報KeeperErrorCode = NoNode for …

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章