#!/bin/bash
# automatic install zookeeper
echo "========= Start to install zookeeper =============="
function install_zk(){
if [ -f "./zookeeper-3.4.12.tar.gz" ];then
echo "Start installing zookeeper"
mkdir -p /opt/ops/zookeeper/zkdata
mkdir -p /opt/ops/zookeeper/datalogs
mkdir -p /opt/ops/zookeeper/log4j
zkrootpath=/opt/ops/zookeeper
zkhome=$zkrootpath/zookeeper-3.4.
zklog=$zkrootpath/log4j
tar -zxf zookeeper-3.4..tar.gz -C $zkrootpath
mv $zkhome/conf/zoo_sample.cfg $zkhome/conf/zoo.cfg
# Modify the normal log output path
sed -i "s@zookeeper.log.dir=.@zookeeper.log.dir=$zklog@g" $zkhome/conf/log4j.properties
sed -i "s@ZOO_LOG_DIR=.*@ZOO_LOG_DIR=\"$zklog\"@g" $zkhome/bin/zkEnv.sh
sed -i "s@ZOO_LOG4J_PROP=.*@ZOO_LOG4J_PROP=\"INFO,ROLLINGFILE\"@g" $zkhome/bin/zkEnv.sh
# Modify the data Log Output Path
sed -i "s@dataDir=/tmp/zookeeper@dataDir=$zkrootpath/zkdata@g" $zkhome/conf/zoo.cfg
localip=$(/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:")
cat >> $zkhome/conf/zoo.cfg << EOF
dataLogDir=$zkrootpath/datalogs
server.=$localip::
EOF
echo > $zkrootpath/zkdata/myid
else
echo "Failed to install zookeeper"
echo "Missing 'zookeeper-3.4.12.tar.gz' file in statistical catalogue"
fi
}
if [ -d "/opt/ops/zookeeper" ];then
echo "Zookeeper has been installed "
else
install_zk
fi
echo "========= End installation of zookeeper ==========="