源码启动zookeeper
zookeeper源码下载地址:
//选择分支3.5.8
https://github.com/apache/zookeeper.git
源码导入idea后,org.apache.zookeeper.Version类会报错,需要建一个辅助类
//全局搜索org.apache.zookeeper.Version这个类就找到了
package org.apache.zookeeper.version;public interface Info {int MAJOR = 1;int MINOR = 0;int MICRO = 0;String QUALIFIER = null;int REVISION = -1;String REVISION_HASH = "1";String BUILD_DATE = "2020-10-15";
}
然后在根目录编译执行:
mvn clean install -DskipTests
本地编译一直报org.apache.commons.collections.ExtendedProperties这个错误,不知道怎么解决。所以上传到云服务器后执行编译命令
后来发现修改插件版本可以解决上面的问题:
<plugin><artifactId>maven-remote-resources-plugin</artifactId><version>1.6.0</version><dependencies><dependency><groupId>commons-collections</groupId><artifactId>commons-collections</artifactId><version>3.2.1</version></dependency><!-- https://mvnrepository.com/artifact/commons-lang/commons-lang --><dependency><groupId>commons-lang</groupId><artifactId>commons-lang</artifactId><version>2.6</version></dependency></dependencies>
</plugin>
从bin目录下的zkServer.sh或zkServer.cmd里找到启动主类
org.apache.zookeeper.server.quorum.QuorumPeerMain
注意:
1、将conf文件夹里的zoo_sample.cfg文件复制一份改名为zoo.cfg,将zoo.cfg文件位置配置到启动参数里
2、启动之前需要先将zookeeper-server项目里pom.xml文件里依赖的包(除了jline)的scope为provided这一行全部注释掉
3、将conf文件夹里的log4j.properties文件复制一份到zookeeper-server项目的 \target\classes 目录下,这样项目启动时才会打印日志