Zookeeper 3.5.8源码下载:
https://github.com/apache/zookeeper/tree/branch-3.5.8
环境介绍:
>java -version
java version "1.8.0_251"
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)
>mvn -version
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-18T02:33:14+08:00)
Maven home: D:\apache-maven-3.5.4\bin\..
Java version: 1.8.0_251, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk1.8.0_251\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
导入IDEA,进行编译
1.执行 mvn clean compile -DskipTests
2. 运行QuorumPeerMain
2.1 复制一份zoo_sample.cfg,取名zoo.cfg
2.2 运行
2.3 运行如果报包的错误:
找到zookeeper-contrib的POM文件,并引入maven,导入包,即可。
2.4 重新运行,即可。
"C:\Program Files\Java\jdk1.8.0_251\bin\java.exe" -Dlog4j.configuration=file:D:\IdeaProjects\zookeeper-branch-3.5.8\conf\log4j.properties "-javaagent:D:\Program Files\JetBrains\IntelliJ IDEA 2019.1\lib\idea_rt.jar=51936:D:\Program Files\JetBrains\IntelliJ IDEA 2019.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program ......org.apache.zookeeper.server.quorum.QuorumPeerMain D:\IdeaProjects\zookeeper-branch-3.5.8\conf\zoo.cfg
2020-12-12 16:02:35,717 [myid:] - INFO [main:[email protected]] - Reading configuration from: D:\IdeaProjects\zookeeper-branch-3.5.8\conf\zoo.cfg
2020-12-12 16:02:35,732 [myid:] - WARN [main:[email protected]] - \tmp\zookeeper is relative. Prepend .\ to indicate that you're sure!
2020-12-12 16:02:35,751 [myid:] - INFO [main:[email protected]] - clientPortAddress is 0.0.0.0:2181
2020-12-12 16:02:35,753 [myid:] - INFO [main:[email protected]] - secureClientPort is not set
......
3. 客户端运行
3.1 运行ZooKeeperMain
3.2 commons/cli/ParseException报错
java.lang.NoClassDefFoundError: org/apache/commons/cli/ParseException
at org.apache.zookeeper.ZooKeeperMain.<clinit>(ZooKeeperMain.java:106)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.cli.ParseException
找到ZooKeeperMain所在的项目的pom文件,注释掉commons-cli的scope
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<!-- <scope>provided</scope>-->
</dependency>
3.3 运行ZooKeeperMain,成功
Connecting to localhost:2181
log4j:WARN No appenders could be found for logger (org.apache.zookeeper.ZooKeeper).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Welcome to ZooKeeper!
JLine support is disabled
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
> ls /
[zookeeper]
4. zkCli连接报错
D:\IdeaProjects\zookeeper-branch-3.5.8\bin>zkCli
错误: 找不到或无法加载主类 org.apache.zookeeper.ZooKeeperMain
解决方案:待更新