Why does zookeeper not use my log4j.properties file log directory

后端 未结 6 387
醉话见心
醉话见心 2020-12-13 13:41

In my zookeeper/conf/log4j.properties file I set the zookeeper.log.dir to $HOME/zklogs

When I use zkServer.sh it does not use that directory. Instead it uses the ${Z

6条回答
  •  别那么骄傲
    2020-12-13 14:20

    As far as I can see from zkEnv.sh zookeeper/conf folder is already in the classpath. There are two problems there:

    1. zkServer.sh adds "-Dzookeeper.log.dir=." to ZK launch command unless you specify ZOO_LOG_DIR environment variable
    2. even if you do specify ZOO_LOG_DIR, ZK may still be unable to find your log4j.properties file, because zkEnv.sh specifies CLASSPATH like this:

      $CLASSPATH="$ZOOCFGDIR:$CLASSPATH"

    this works fine if your $CLASSPATH environment variable is not empty, however when it is empty, it just leaves a trailing colon, which screws up your classpath. I changed the lines above to this:

    #add the zoocfg dir to classpath
    if [ "x${CLASSPATH}" = "x" ]
    then
        CLASSPATH="$ZOOCFGDIR"
    else
        CLASSPATH="$ZOOCFGDIR:$CLASSPATH"
    fi
    

    and also passed ZOO_LOG_DIR environment for ZK, because zkServer.sh generates -Dzookeeper.log.dir VM argument when starting up ZK. Here is the command that starts ZooKeeper for me, makes it read /opt/zookeeper/conf/log4j.properties and keep log files in /opt/zimbra/log:

    ZOO_LOG_DIR=/opt/zimbra/log /opt/zookeeper/bin/zkServer.sh start
    

提交回复
热议问题