本文介绍一下zookeeper-3.9.0源码下载、编译及本地启动。
git clone https://gitee.com/apache/zookeeper.git
cd zookeeper
git checkout release-3.9.0
git checkout -b release-3.9.0
该文件介绍了编译zookeeper需要的环境和命令。
mvn clean install -DskipTests
zookeeper-assembly/target/apache-zookeeper-3.9.0-bin.tar.gz
包目录结构:
/bin
- 可执行文件及脚本/conf
- 配置文件/lib
- zookeeper包及依赖的包/docs
- 文档To also build the C client, you need to activate the full-build
profile:
mvn clean -Pfull-build
mvn install -Pfull-build -DskipTests
需要在linux平台编译,windows平台会出错。
发布包的启动方式在上一篇文章已经介绍,此处介绍一下使用java命令启动zookeeper服务。
进入zookeeper-server/target目录:
$ ll
drwxr-xr-x 1 xuguofeng 197121 0 Aug 16 00:14 lib/
-rw-r--r-- 1 xuguofeng 197121 1359096 Aug 16 00:14 zookeeper-3.9.0.jar
在zookeeper-server/target下创建conf目录,创建zoo.cfg配置文件:
tickTime=2000
initLimit=10
syncLimit=5
dataDir=data
clientPort=2181
java \
-Dzookeeper.datadir.autocreate=true \
-Dzookeeper.log.dir=./logs \
-Dzookeeper.log.file=zookeeper.log \
-XX:+HeapDumpOnOutOfMemoryError \
-Xmx1000m -Xms1000m \
-cp zookeeper-3.9.0.jar;./lib/*;./conf \
org.apache.zookeeper.server.quorum.QuorumPeerMain ./conf/zoo.cfg
如果是linux平台,则使用如下命令:
nohup java \
-Dzookeeper.datadir.autocreate=true \
-Dzookeeper.log.dir=./logs \
-Dzookeeper.log.file=zookeeper.log \
-XX:+HeapDumpOnOutOfMemoryError \
-XX:OnOutOfMemoryError='kill -9 %p' \
-Xmx1000m -Xms1000m \
-Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:./lib \
-cp ./conf:zookeeper-3.9.0.jar \
org.apache.zookeeper.server.quorum.QuorumPeerMain ./conf/zoo.cfg > ./logs/zookeeper.out 2>&1 < /dev/null &
java \
-Dzookeeper.datadir.autocreate=true \
-Dzookeeper.log.dir=./logs \
-Dzookeeper.log.file=zookeeper.log \
-Dzookeeper.log.threshold=INFO \
-Xmx256m -Xms256m \
-cp zookeeper-3.9.0.jar;./lib/*;./conf \
org.apache.zookeeper.ZooKeeperMain
在工作目录下创建tmp/conf目录:
把conf/logback.xml拷贝到tmp/conf目录下
在tmp/conf目录下创建zoo.cfg配置文件
tickTime=2000
initLimit=10
syncLimit=5
dataDir=./tmp/data
clientPort=2181
VM Option:
-Dzookeeper.datadir.autocreate=true -Dzookeeper.log.dir=./tmp/logs -Dzookeeper.log.file=zookeeper.log -Xmx1000m -Xms1000m
Program Arguments:
./tmp/conf/zoo.cfg
把./tmp/conf目录添加到classpath中。
如果直接启动,可能出现类找不到的问题,在pom.xml中找到对应的依赖,将provided注释掉即可。