I recently studied zookeeper storm Kafka. By the way, I set up a local cluster and encountered a zookeeper log problem with the output path. I found that zookeeper sets log4j. properties cannot solve the Log Path problem. The solution is as follows:
1. Modify log4j. properties. This should be changed for everyone. I modified the red bold area, but it still does not take effect.
# Define some default values that can be overridden by system propertieszookeeper.root.logger=INFO,ROLLINGFILE zookeeper.console.threshold=INFOzookeeper.log.dir=.zookeeper.log.file=zookeeper-1.logzookeeper.log.threshold=DEBUGzookeeper.tracelog.dir=.zookeeper.tracelog.file=zookeeper_trace.log## ZooKeeper Logging Configuration## Format is "<default threshold> (, <appender>)+# DEFAULT: console appender onlylog4j.rootLogger=${zookeeper.root.logger}# Example with rolling log file#log4j.rootLogger=DEBUG, CONSOLE, ROLLINGFILE# Example with rolling log file and tracing#log4j.rootLogger=TRACE, CONSOLE, ROLLINGFILE, TRACEFILE## Log INFO level and above messages to the console#log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppenderlog4j.appender.CONSOLE.Threshold=${zookeeper.console.threshold}log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayoutlog4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n## Add ROLLINGFILE to rootLogger to get log file output# Log DEBUG level and above messages to a log filelog4j.appender.ROLLINGFILE=org.apache.log4j.DailyRollingFileAppenderlog4j.appender.ROLLINGFILE.Threshold=${zookeeper.log.threshold}log4j.appender.ROLLINGFILE.File=${zookeeper.log.dir}/${zookeeper.log.file}# Max log file size of 10MB#log4j.appender.ROLLINGFILE.MaxFileSize=10MB# uncomment the next line to limit number of backup files#log4j.appender.ROLLINGFILE.MaxBackupIndex=10log4j.appender.ROLLINGFILE.layout=org.apache.log4j.PatternLayoutlog4j.appender.ROLLINGFILE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n## Add TRACEFILE to rootLogger to get log file output# Log DEBUG level and above messages to a log filelog4j.appender.TRACEFILE=org.apache.log4j.FileAppenderlog4j.appender.TRACEFILE.Threshold=TRACElog4j.appender.TRACEFILE.File=${zookeeper.tracelog.dir}/${zookeeper.tracelog.file}log4j.appender.TRACEFILE.layout=org.apache.log4j.PatternLayout### Notice we are including log4j‘s NDC here (%x)log4j.appender.TRACEFILE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L][%x] - %m%n
2. You also need to change $ {zkhome}/bin/zkenv. Sh. Pay attention to the bold area in red. At this time, the log can be successfully output according to the directory you set.
#!/usr/bin/env bash# Licensed to the Apache Software Foundation (ASF) under one or more# contributor license agreements. See the NOTICE file distributed with# this work for additional information regarding copyright ownership.# The ASF licenses this file to You under the Apache License, Version 2.0# (the "License"); you may not use this file except in compliance with# the License. You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.# This script should be sourced into other zookeeper# scripts to setup the env variables# We use ZOOCFGDIR if defined,# otherwise we use /etc/zookeeper# or the conf directory that is# a sibling of this script‘s directoryZOOBINDIR="${ZOOBINDIR:-/usr/bin}"ZOOKEEPER_PREFIX="${ZOOBINDIR}/.."if [ "x$ZOOCFGDIR" = "x" ]then if [ -e "${ZOOKEEPER_PREFIX}/conf" ]; then ZOOCFGDIR="$ZOOBINDIR/../conf" else ZOOCFGDIR="$ZOOBINDIR/../etc/zookeeper" fifiif [ -f "${ZOOCFGDIR}/zookeeper-env.sh" ]; then . "${ZOOCFGDIR}/zookeeper-env.sh"fiif [ "x$ZOOCFG" = "x" ]then ZOOCFG="zoo.cfg"fiZOOCFG="$ZOOCFGDIR/$ZOOCFG"if [ -f "$ZOOCFGDIR/java.env" ]then . "$ZOOCFGDIR/java.env"fiif [ "x${ZOO_LOG_DIR}" = "x" ]then ZOO_LOG_DIR="/apps/logs/zookeeper"fiif [ "x${ZOO_LOG4J_PROP}" = "x" ]then ZOO_LOG4J_PROP="INFO,ROLLINGFILE"fiif [ "$JAVA_HOME" != "" ]; then JAVA="$JAVA_HOME/bin/java"else JAVA=javafi#add the zoocfg dir to classpathCLASSPATH="$ZOOCFGDIR:$CLASSPATH"for i in "$ZOOBINDIR"/../src/java/lib/*.jardo CLASSPATH="$i:$CLASSPATH"done#make it work in the binary package#(use array for LIBPATH to account for spaces within wildcard expansion)if [ -e "${ZOOKEEPER_PREFIX}"/share/zookeeper/zookeeper-*.jar ]; then LIBPATH=("${ZOOKEEPER_PREFIX}"/share/zookeeper/*.jar)else #release tarball format for i in "$ZOOBINDIR"/../zookeeper-*.jar do CLASSPATH="$i:$CLASSPATH" done LIBPATH=("${ZOOBINDIR}"/../lib/*.jar)fifor i in "${LIBPATH[@]}"do CLASSPATH="$i:$CLASSPATH"done#make it work for developersfor d in "$ZOOBINDIR"/../build/lib/*.jardo CLASSPATH="$d:$CLASSPATH"done#make it work for developersCLASSPATH="$ZOOBINDIR/../build/classes:$CLASSPATH"case "`uname`" in CYGWIN*) cygwin=true ;; *) cygwin=false ;;esacif $cygwinthen CLASSPATH=`cygpath -wp "$CLASSPATH"`fi#echo "CLASSPATH=$CLASSPATH"
3. What is lacking in the US is that the zookeeper. Out file still exists in the directory you set. Although its size is 0, it still makes me feel uncomfortable.
The reason is that zkserver. Sh will use nohup to start zookeeper. However, nohup will certainly output a log file to the directory you set,
The related code is as follows. You need to modify the logic here to remove zookeeper. Out,If you are not a Virgo, you can skip this step.
_ZOO_DAEMON_OUT="$ZOO_LOG_DIR/zookeeper.out"case $1 instart) echo -n "Starting zookeeper ... " if [ -f "$ZOOPIDFILE" ]; then if kill -0 `cat "$ZOOPIDFILE"` > /dev/null 2>&1; then echo $command already running as process `cat "$ZOOPIDFILE"`. exit 0 fi fi nohup "$JAVA" "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" -cp "$CLASSPATH" $JVMFLAGS $ZOOMAIN "$ZOOCFG" > "$_ZOO_DAEMON_OUT" 2>&1 < /dev/null &
So far, Zookeeper's log settings have ended. Thank you!
Zookeeper logs are output to the specified folder.