1、Maven环境搭建
下载Maven安装包,配置好环境变量以及其他配置


2、下载Zookeeper源码
- GitHub 上apache-zookeeper-3.5.6 源码分支是支持Maven构建的,通过Git命令下载源码并切换到相应分支:
git clone https://github.com/apache/zookeeper.git
git checkout branch-3.5.6
-
通过 IntelliJ IDEA的导入Maven项目功能,导入源码工程到IDE环境中并修改主pom.xml文件中的配置:把git-commit-id-plugin的version更改为3.0.1
03 更改git-commit-id-plugin.png
并重新Reimport 一下:
04 pom reimport.png
也或者通过Git bash 在源码根目录下,执行以下命令:
mvn install -Dmaven.skip.test=true
3、 启动Zookeeper
1. 服务端启动:
在源码conf目录下,复制zoo_sample.cfg文件为zoo.cfg,并修改以下配置:

运行主类 org.apache.zookeeper.server.ZooKeeperServerMain,【Program arguments】选项中配置zoo.cfg的完整路径,【VM options】选项中配置log4j.properties 的文件路径,【Use classpath of module】选项选择zookeeper

为了避免启动时抛出AdminServerException错误,需要把jetty-server的scope值更改为compile:

如果启动成功如下图所示:

2. 启动客户端:
客户端的启动类为org.apache.zookeeper.ZooKeeperMain,进行如下配置:
【VM options】选项中配置log4j.properties 的文件路径,
【Program arguments】选项中配置: -server 127.0.0.1:2181 get /watch

如果在启动过程中,报如下错误:java.lang.ClassNotFoundException: org.apache.commons.cli.ParseException
则需要修改pom.xml,并重新Reimport下:

客户端启动成功:

网友评论