在我的zookeeper / conf / log4j.properties文件中,我将zookeeper.log.dir设置为$ HOME / zklogs
当我使用zkServer.sh时,它不使用该目录。相反,它使用$ {ZOO_LOG_DIR},当我回应它时,它出现在"。"
我不明白如何解决这个问题,我在任何地方都看不到$ {ZOO_LOG_DIR}。我不确定它是如何设置为"。"一点都不我也不知道如何在没有zkServer.sh的情况下启动zookeeper。我在linux上也很吵,在这个问题上有点迷失......
有人知道如何解决这个问题,以便它使用conf目录中我的log4j.properties文件中设置的目录吗?
***更新,我在我的zookeeper安装的bin目录中的zkEnv.sh中找到了。有代码:
if["x${ZOO_LOG_DIR}" = "x" ]
then
ZOO_LOG_DIR="."
fi
我不确定第一行发生了什么,但必须在这里出现问题。我希望它从我的log4j.properties文件中查看zookeeper.log.dir。任何人都可以告诉我这是否属实?我不想在这里艰难地走这条路......
答案 0 :(得分:38)
我想添加如何解决此问题/自定义我的环境。
这里有2种日志记录机制:
bin / zkServer.sh使用:
"最终" setup conf / log4j.properties中的默认值由zookeeper bash脚本的组合设置:
打开日志追加器CONSOLE的效果是日志现在转到stdout。因为bin / zkServer.sh将stdout和stderr重定向到zookeeper.out,所以log4j日志最终会出现在zookeeper.out中。关闭ROLLINGFILE的效果是没有创建zookeeper.log文件。
不会轮换zookeeper.out日志。 zookeeper.log日志设置为旋转,可以设置为使旧日志过期。
我希望日志滚动并过期。我要做的第一件事是更改conf / log4j.properties以导致旧日志的到期/删除。我通过在conf / log4j.properties中设置log4j.appender.ROLLINGFILE.MaxBackupIndex来做到这一点。我要做的第二件事是设置日志目录,日志记录级别和追加者。
我有一个每分钟运行一次的bash脚本。如果它看到zookeeper没有运行,它会运行:
bin/zkServer.sh start
我将其更改为指定bin / zkServer.sh期望的环境变量。
sudo ZOO_LOG_DIR=/opt/zookeeper-3.4.6/logs ZOO_LOG4J_PROP='INFO,ROLLINGFILE' /opt/zookeeper-3.4.6/bin/zkServer.sh start
关闭日志追加器CONSOLE的效果是log4j日志现在不再以zookeeper.out结尾。打开ROLLINGFILE的效果是zookeeper.log文件被创建,旋转和过期。
BTW,conf / log4j.properties显然已经在我的类路径中了。在这方面我不得不做任何改变。
这一链条对我的理解做出了重大贡献: https://groups.google.com/forum/#!msg/nosql-databases/aebIvNnT0xY/doky1X9-WfwJ
答案 1 :(得分:6)
zkServer.sh
从zkEnv.sh
获取环境变量
env文件设置一个类路径,如果它位于预期的位置,则包含log4j文件。
ZOOXFGDIR=ZOOBINDIR/../conf
我将一些回声放入zkServer.sh以追踪正在发生的事情。
我发现正确设置了classpath,但是没有设置logdir和log4j_prop。所以我将它们添加到zkEnv.sh
。现在,日志似乎显示在预期的位置。
ZOO_LOG_DIR="/var/log/zookeeper"
ZOO_LOG4J_PROP="INFO,ROLLINGFILE"
答案 2 :(得分:2)
据我所知,zkEnv.sh zookeeper / conf文件夹已经在classpath中。那里有两个问题:
即使你确实指定了ZOO_LOG_DIR,ZK仍然无法找到你的log4j.properties文件,因为zkEnv.sh指定了这样的CLASSPATH:
$CLASSPATH="$ZOOCFGDIR:$CLASSPATH"
如果$ CLASSPATH环境变量不为空,这可以正常工作,但是当它为空时,它只会留下一个尾随冒号,这会搞砸你的类路径。 我将上面的行改为:
#add the zoocfg dir to classpath
if [ "x${CLASSPATH}" = "x" ]
then
CLASSPATH="$ZOOCFGDIR"
else
CLASSPATH="$ZOOCFGDIR:$CLASSPATH"
fi
并且还为ZK传递了ZOO_LOG_DIR环境,因为zkServer.sh在启动ZK时生成-Dzookeeper.log.dir VM参数。这是为我启动ZooKeeper的命令,使其读取/opt/zookeeper/conf/log4j.properties并将日志文件保存在/ opt / zimbra / log中:
ZOO_LOG_DIR=/opt/zimbra/log /opt/zookeeper/bin/zkServer.sh start
答案 3 :(得分:1)
我相信我的问题的答案是我需要将log4j.properties文件移动到我的类路径中,然后只有当我调用zkServer.sh时zkEnv.sh将读取我在log4j.properties中设置的值。我相信我只是不明白如何正确使用log4j。
答案 4 :(得分:1)
通过ZOO_LOG_DIR环境变量更改文件日志目录的另一个选项是创建自己的zk-server-1 / conf / zookeeper-env.sh。
阅读zookeeper-3.4.6 dist bash脚本(t.i。zkEnv.sh),他们会找到zookeeper-env.sh文件(如果存在)。这是它(我创建的)内容:
export ZOO_HOME=$ZOOKEEPER_PREFIX
echo $ZOO_HOME
export ZOO_LOG_DIR=$ZOO_HOME/logs
我习惯拥有 PRODUCTNAME _HOME变量,该变量指向zookeeper的顶级安装目录。这个顶级目录似乎被zookeeper dist命名为$ ZOOKEEPER_PREFIX,我将其与$ ZOO_HOME联系并将其用于ZOO_LOG_DIR环境变量。
在这篇文章的最后,我假设了bash脚本调试信息 - 帮助我调查使用哪个环境或局部变量加上值。
正如我所看到的,/ home / joma / dev / programme / zk-local-feel / zk-server-1 / bin / .. / dir是在CLASSPATH上,因此log4j.properties文件符合条件通过java的log4j框架的类加载器来加载资源(这是log4j实现AFAIR的方式)。
joma@kopernikus-u:~/dev/programme/zk-local-ensemble$ bash -x zk-server-1/bin/zkServer.sh start
+ '[' x = x ']'
+ JMXLOCALONLY=false
+ '[' x = x ']'
+ echo 'JMX enabled by default'
JMX enabled by default
+ ZOOMAIN='-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain'
+ ZOOBIN=zk-server-1/bin/zkServer.sh
++ dirname zk-server-1/bin/zkServer.sh
+ ZOOBIN=zk-server-1/bin
++ cd zk-server-1/bin
++ pwd
+ ZOOBINDIR=/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin
+ '[' -e zk-server-1/bin/../libexec/zkEnv.sh ']'
+ . /home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/zkEnv.sh
++ ZOOBINDIR=/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin
++ ZOOKEEPER_PREFIX=/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/..
++ '[' x = x ']'
++ '[' -e /home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../conf ']'
++ ZOOCFGDIR=/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../conf
++ '[' -f /home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../conf/zookeeper-env.sh ']'
++ . /home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../conf/zookeeper-env.sh
+++ export ZOO_HOME=/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/..
+++ ZOO_HOME=/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/..
+++ echo /home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/..
/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/..
+++ export ZOO_LOG_DIR=/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../logs
+++ ZOO_LOG_DIR=/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../logs
++ '[' x = x ']'
++ ZOOCFG=zoo.cfg
++ ZOOCFG=/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../conf/zoo.cfg
++ '[' -f /home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../conf/java.env ']'
++ '[' x/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../logs = x ']'
++ '[' x = x ']'
++ ZOO_LOG4J_PROP=INFO,CONSOLE
++ '[' /home/joma/entwicklung/programme/jdk1.7.0_51 '!=' '' ']'
++ JAVA=/home/joma/entwicklung/programme/jdk1.7.0_51/bin/java
++ CLASSPATH=/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../conf:
++ for i in '"$ZOOBINDIR"/../src/java/lib/*.jar'
++ CLASSPATH='/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../src/java/lib/*.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../conf:'
++ '[' -e '/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../share/zookeeper/zookeeper-*.jar' ']'
++ for i in '"$ZOOBINDIR"/../zookeeper-*.jar'
++ CLASSPATH='/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../zookeeper-3.4.6.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../src/java/lib/*.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../conf:'
++ LIBPATH=("${ZOOBINDIR}"/../lib/*.jar)
++ for i in '"${LIBPATH[@]}"'
++ CLASSPATH='/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/jline-0.9.94.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../zookeeper-3.4.6.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../src/java/lib/*.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../conf:'
++ for i in '"${LIBPATH[@]}"'
++ CLASSPATH='/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/log4j-1.2.16.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/jline-0.9.94.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../zookeeper-3.4.6.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../src/java/lib/*.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../conf:'
++ for i in '"${LIBPATH[@]}"'
++ CLASSPATH='/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/netty-3.7.0.Final.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/log4j-1.2.16.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/jline-0.9.94.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../zookeeper-3.4.6.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../src/java/lib/*.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../conf:'
++ for i in '"${LIBPATH[@]}"'
++ CLASSPATH='/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/slf4j-api-1.6.1.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/netty-3.7.0.Final.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/log4j-1.2.16.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/jline-0.9.94.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../zookeeper-3.4.6.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../src/java/lib/*.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../conf:'
++ for i in '"${LIBPATH[@]}"'
++ CLASSPATH='/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/slf4j-api-1.6.1.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/netty-3.7.0.Final.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/log4j-1.2.16.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/jline-0.9.94.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../zookeeper-3.4.6.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../src/java/lib/*.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../conf:'
++ for d in '"$ZOOBINDIR"/../build/lib/*.jar'
++ CLASSPATH='/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../build/lib/*.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/slf4j-api-1.6.1.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/netty-3.7.0.Final.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/log4j-1.2.16.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/jline-0.9.94.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../zookeeper-3.4.6.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../src/java/lib/*.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../conf:'
++ CLASSPATH='/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../build/classes:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../build/lib/*.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/slf4j-api-1.6.1.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/netty-3.7.0.Final.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/log4j-1.2.16.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/jline-0.9.94.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../zookeeper-3.4.6.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../src/java/lib/*.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../conf:'
++ case "`uname`" in
+++ uname
++ cygwin=false
++ false
+ '[' x '!=' x ']'
+ '[' x '!=' x ']'
++ dirname /home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../conf/zoo.cfg
+ '[' x/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../conf '!=' x/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../conf ']'
+ false
+ KILL=kill
+ echo 'Using config: /home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../conf/zoo.cfg'
Using config: /home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../conf/zoo.cfg
+ '[' -z '' ']'
++ grep '^[[:space:]]*dataDir' /home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../conf/zoo.cfg
++ sed -e 's/.*=//'
+ ZOO_DATADIR=/home/joma/dev/programme/zk-local-ensemble/data/zk1
+ '[' '!' -d /home/joma/dev/programme/zk-local-ensemble/data/zk1 ']'
+ ZOOPIDFILE=/home/joma/dev/programme/zk-local-ensemble/data/zk1/zookeeper_server.pid
+ '[' '!' -w /home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../logs ']'
+ _ZOO_DAEMON_OUT=/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../logs/zookeeper.out
+ case $1 in
+ echo -n 'Starting zookeeper ... '
Starting zookeeper ... + '[' -f /home/joma/dev/programme/zk-local-ensemble/data/zk1/zookeeper_server.pid ']'
+ '[' 0 -eq 0 ']'
+ /bin/echo -n 24744
+ nohup /home/joma/entwicklung/programme/jdk1.7.0_51/bin/java -Dzookeeper.log.dir=/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../logs -Dzookeeper.root.logger=INFO,CONSOLE -cp '/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../build/classes:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../build/lib/*.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/slf4j-api-1.6.1.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/netty-3.7.0.Final.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/log4j-1.2.16.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../lib/jline-0.9.94.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../zookeeper-3.4.6.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../src/java/lib/*.jar:/home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../conf:' -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /home/joma/dev/programme/zk-local-ensemble/zk-server-1/bin/../conf/zoo.cfg
+ sleep 1
+ echo STARTED
STARTED
答案 5 :(得分:0)
也许不是寻求的答案,但对于conf目录中的zookeeper-3.4.11,您可以在log4j.properties文件中设置适当的级别和配置