.......
ZOOBIN="${BASH_SOURCE-$0}"
ZOOBIN="$(dirname "${ZOOBIN}")"
ZOOBINDIR="$(cd "${ZOOBIN}"; pwd)" //获得当前脚本文件所在路径 本例中 ZOOBINDIR 的值为 /usr/local/zookeeper/bin
if [ -e "$ZOOBIN/../libexec/zkEnv.sh" ]; then
. "$ZOOBINDIR/../libexec/zkEnv.sh"
else
. "$ZOOBINDIR/zkEnv.sh" //执行环境配置脚本
fi
打开 zkEnv.sh
ZOOBINDIR="${ZOOBINDIR:-/usr/bin}" //如果ZOOBINDIR 为空的话 那么默认指为 /usr/bin
ZOOKEEPER_PREFIX="${ZOOBINDIR}/.."
if [ "x$ZOOCFGDIR" = "x" ]
then
if [ -e "${ZOOKEEPER_PREFIX}/conf" ]; then //如果前面 ZOOKEEPER_PREFIX/conf 存在
ZOOCFGDIR="$ZOOBINDIR/../conf" //那么配置文件目录 就为该值 在本例中 为 /usr/local/zookeeper/conf
else
ZOOCFGDIR="$ZOOBINDIR/../etc/zookeeper"
fi
fi
if [ -f "${ZOOCFGDIR}/zookeeper-env.sh" ]; then
. "${ZOOCFGDIR}/zookeeper-env.sh"
fi
if [ "x$ZOOCFG" = "x" ]
then
ZOOCFG="zoo.cfg" //配置文件默认名称 zoo.cfg
fi
ZOOCFG="$ZOOCFGDIR/$ZOOCFG" //完整配置路径 /usr/local/zookeeper/conf/zoo.cfg
......
//后面代码主要是用来声明 classpath
回到zkServer.sh
.......
//看这段代码
if [ "x$2" != "x" ] //如果启动文件 输入了第2个参数 那么配置文件使用指定的文件名
then
ZOOCFG="$ZOOCFGDIR/$2"
fi
再往下面看
# if we give a more complicated path to the config, don't screw around in $ZOOCFGDIR
if [ "x$(dirname "$ZOOCFG")" != "x$ZOOCFGDIR" ]
then
ZOOCFG="$2"
fi
定义了pid 文件路径和 data路径
if [ -z "$ZOOPIDFILE" ]; then
ZOO_DATADIR="$(grep "^[[:space:]]*dataDir" "$ZOOCFG" | sed -e 's/.*=//')"
if [ ! -d "$ZOO_DATADIR" ]; then
mkdir -p "$ZOO_DATADIR"
fi
ZOOPIDFILE="$ZOO_DATADIR/zookeeper_server.pid"
else
# ensure it exists, otw stop will fail
mkdir -p "$(dirname "$ZOOPIDFILE")"
fi
3. 单机启动zookeeper服务
先回到步骤1 安装成功后 做以下操作
# 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.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/usr/local/zookeeper/data
# the port at which the clients will connect
clientPort=2181
启动 zookeeper 服务