#!/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. # # Install Apache ZooKeeper. # # Note that ZooKeeper is not ready to run until its configuration file # (/etc/zookeeper/conf/zoo.cfg) and id file (/var/log/zookeeper/txlog/myid) # have both been written. See post-configure. # set -x set -e ZK_VERSION=${1:-3.3.0} ZOOKEEPER_HOME=/usr/local/zookeeper-$ZK_VERSION ZK_CONF_DIR=/etc/zookeeper/conf ZK_LOG_DIR=/var/log/zookeeper zk_tar_url=http://www.apache.org/dist/hadoop/zookeeper/zookeeper-$ZK_VERSION/zookeeper-$ZK_VERSION.tar.gz zk_tar_file=`basename $zk_tar_url` zk_tar_md5_file=`basename $zk_tar_url.md5` curl="curl --retry 3 --silent --show-error --fail" for i in `seq 1 3`; do $curl -O $zk_tar_url $curl -O $zk_tar_url.md5 if md5sum -c $zk_tar_md5_file; then break; else rm -f $zk_tar_file $zk_tar_md5_file fi done if [ ! -e $zk_tar_file ]; then echo "Failed to download $zk_tar_url. Aborting." exit 1 fi tar zxf $zk_tar_file -C /usr/local rm -f $zk_tar_file $zk_tar_md5_file echo "export ZOOKEEPER_HOME=$ZOOKEEPER_HOME" >> /etc/profile echo 'export PATH=$ZOOKEEPER_HOME/bin:$PATH' >> /etc/profile mkdir -p /mnt/zookeeper/logs ln -s /mnt/zookeeper/logs $ZK_LOG_DIR mkdir -p $ZK_LOG_DIR/txlog mkdir -p $ZK_CONF_DIR cp $ZOOKEEPER_HOME/conf/log4j.properties $ZK_CONF_DIR sed -i -e "s|log4j.rootLogger=INFO, CONSOLE|log4j.rootLogger=INFO, ROLLINGFILE|" \ -e "s|log4j.appender.ROLLINGFILE.File=zookeeper.log|log4j.appender.ROLLINGFILE.File=$ZK_LOG_DIR/zookeeper.log|" \ $ZK_CONF_DIR/log4j.properties # Ensure ZooKeeper starts on boot cat > /etc/rc.local < /dev/null 2>&1 & EOF