单机版zookeeper的启动类为org.apache.zookeeper.server.ZooKeeperMain.java
1 启动参数
ZooKeeper启动参数有两种配置方式:
方式1:main方法中传入四个参数,其中前两参数必填,后两个参数可选。分别为:对客户端暴露的端口clientPortAddress, 存放事务记录、内存树快照记录的dataDir, 用于指定seesion检查时间间隔的tickTime, 控制最大客户端连接数的maxClientCnxns。
方式2:给出启动参数配置文件路径,当args启动参数只有一个时,ZooKeeperServerMain 中main方法,会认为传入了配置文件路径,默认情况下该参数是传conf目录中的zoo.cfg。
protected void initializeAndRun(String[] args)
throws ConfigException, IOException, AdminServerException
{
try {
ManagedUtil.registerLog4jMBeans();
} catch (JMException e) {
LOG.warn("Unable to register log4j JMX control", e);
}
ServerConfig config = new ServerConfig();
if (args.length == 1) {
config.parse(args[0]);///对应方式2,传入配置文件地址
} else {
config.parse(args);///对应方式1,传入启动参数
}
runFromConfig(conf