Skip to content

Instantly share code, notes, and snippets.

@manios
Last active August 29, 2015 14:20
Show Gist options
  • Save manios/e4fbd700e0d8999f5e17 to your computer and use it in GitHub Desktop.
Save manios/e4fbd700e0d8999f5e17 to your computer and use it in GitHub Desktop.
Zookeeper configuration files which help to create a Zookeeper ensemble for SolrCloud
ZOO_LOG_DIR=/var/log/zookeeper1
ZOO_LOG4J_PROP=INFO,ROLLINGFILE
# Define some default values that can be overridden by system properties
zookeeper.root.logger=INFO, ROLLINGFILE
zookeeper.console.threshold=INFO
zookeeper.log.dir=/var/log/zookeeper1
zookeeper.log.file=zookeeper.log
zookeeper.log.threshold=DEBUG
zookeeper.tracelog.dir=/var/log/zookeeper1
zookeeper.tracelog.file=zookeeper_trace.log
#
# ZooKeeper Logging Configuration
#
# Format is "<default threshold> (, <appender>)+
# DEFAULT: console appender only
log4j.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.ConsoleAppender
log4j.appender.CONSOLE.Threshold=${zookeeper.console.threshold}
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.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 file
log4j.appender.ROLLINGFILE=org.apache.log4j.RollingFileAppender
log4j.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=10
log4j.appender.ROLLINGFILE.layout=org.apache.log4j.PatternLayout
log4j.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 file
log4j.appender.TRACEFILE=org.apache.log4j.FileAppender
log4j.appender.TRACEFILE.Threshold=TRACE
log4j.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
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# Choose appropriately for your environment
dataDir=/opt/zookeeper1/data
# the port at which the clients will connect
clientPort=2181
# the directory where transaction log is stored.
# this parameter provides dedicated log device for ZooKeeper
dataLogDir=/var/log/zookeeper1
# Max client connections (default 10)
maxClientCnxns=1000
# ZooKeeper server and its port no.
# ZooKeeper ensemble should know about every other machine in the ensemble
# specify server id by creating 'myid' file in the dataDir
# use hostname instead of IP address for convenient maintenance
server.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890
#! /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.
### BEGIN INIT INFO
# Provides: zookeeper1
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Apache ZooKeeper server
### END INIT INFO
# downloaded by
# https://svn.apache.org/repos/asf/zookeeper/trunk/src/packages/deb/init.d/zookeeper
# and modified according to installation
set -e
# /etc/init.d/zookeeper: start and stop the Apache ZooKeeper daemon
umask 022
. /opt/zookeeper1/bin/zkEnv.sh
. /lib/lsb/init-functions
ZOOPIDDIR=/opt/zookeeper1/data
ZOOPIDFILE=${ZOOPIDDIR}/zookeeper_server.pid
check_privsep_dir() {
# Create the PrivSep empty dir if necessary
if [ ! -d ${ZOOPIDDIR} ]; then
echo Insied privsep
mkdir -p ${ZOOPIDDIR}
chmod 0775 ${ZOOPIDDIR}
fi
}
# Are we running from init?
run_by_init() {
([ "$previous" ] && [ "$runlevel" ]) || [ "$runlevel" = S ]
}
check_for_no_start() {
# forget it if we're trying to start, and /etc/zookeeper/zookeeper_not_to_be_run exists
if [ -e /etc/zookeeper/zookeeper_not_to_be_run ]; then
if [ "$1" = log_end_msg ]; then
log_end_msg 0
fi
if ! run_by_init; then
log_action_msg "Apache ZooKeeper server not in use (/etc/zookeeper/zookeeper_not_to_be_run)"
fi
exit 0
fi
}
export PATH="${PATH:+$PATH:}/usr/sbin:/usr/bin:/opt/zookeeper1"
case "$1" in
start)
check_for_no_start
check_privsep_dir
log_daemon_msg "Starting Apache ZooKeeper server" "zookeeper"
#if start-stop-daemon --start --quiet --oknodo --pidfile ${ZOOPIDFILE} -c zookeeper -x ${ZOOKEEPER_PREFIX}/bin/zkServer.sh start; then
if start-stop-daemon --start --quiet --oknodo --pidfile ${ZOOPIDFILE} -x ${ZOOKEEPER_PREFIX}/bin/zkServer.sh start; then
log_end_msg 0
else
log_end_msg 1
fi
;;
stop)
log_daemon_msg "Stopping Apache ZooKeeper server" "zookeeper"
if start-stop-daemon --stop --quiet --oknodo --pidfile ${ZOOPIDFILE}; then
log_end_msg 0
else
log_end_msg 1
fi
;;
restart)
check_privsep_dir
log_daemon_msg "Restarting Apache ZooKeeper server" "zookeeper"
start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile ${ZOOPIDFILE}
check_for_no_start log_end_msg
#if start-stop-daemon --start --quiet --oknodo --pidfile ${ZOOPIDFILE} -c zookeeper -x ${ZOOKEEPER_PREFIX}/bin/zkServer.sh start; then
if start-stop-daemon --start --quiet --oknodo --pidfile ${ZOOPIDFILE} -x ${ZOOKEEPER_PREFIX}/bin/zkServer.sh start; then
log_end_msg 0
else
log_end_msg 1
fi
;;
try-restart)
check_privsep_dir
log_daemon_msg "Restarting Apache ZooKeeper server" "zookeeper"
set +e
start-stop-daemon --stop --quiet --retry 30 --pidfile ${ZOOPIDFILE}
RET="$?"
set -e
case $RET in
0)
# old daemon stopped
check_for_no_start log_end_msg
#if start-stop-daemon --start --quiet --oknodo --pidfile ${ZOOPIDFILE} -c zookeeper -x ${ZOOKEEPER_PREFIX}/bin/zkServer.sh start; then
if start-stop-daemon --start --quiet --oknodo --pidfile ${ZOOPIDFILE} -x ${ZOOKEEPER_PREFIX}/bin/zkServer.sh start; then
log_end_msg 0
else
log_end_msg 1
fi
;;
1)
# daemon not running
log_progress_msg "(not running)"
log_end_msg 0
;;
*)
# failed to stop
log_progress_msg "(failed to stop)"
log_end_msg 1
;;
esac
;;
status)
status_of_proc -p ${ZOOPIDFILE} ${JAVA_HOME}/bin/java zookeeper && exit 0 || exit $?
;;
*)
log_action_msg "Usage: /etc/init.d/zookeeper {start|stop|restart|try-restart|status}"
exit 1
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment