Saturday, May 07, 2016

AWS - How to Install Zookeeper and Exhibitor on a AWS Instance

Instance Type: t2.small
AMI: amzn-ami-hvm-2016.03.1.x86_64-gp2 (ami-f5f41398)
Java: java version "1.8.0_45"

The zookeeper I use is from "Cloudera's Distribution for Hadoop, Version 4", so download the repo into "/etc/yum.repos.d"
# cat /etc/yum.repos.d/cloudera-cdh4.repo
[cloudera-cdh4]
name=Cloudera's Distribution for Hadoop, Version 4
baseurl=http://archive.cloudera.com/cdh4/redhat/6/x86_64/cdh/4/
gpgkey = http://archive.cloudera.com/cdh4/redhat/6/x86_64/cdh/RPM-GPG-KEY-cloudera
gpgcheck = 1

Install exhibitor:
Following the links here to install (https://github.com/Netflix/exhibitor/wiki). I bundled everything (jar, exhibitor.sh into an rpm)

My exhibitor directory looks like:
rpm -qlp exhibitor-1.5.2.noarch.rpm
/etc/init.d/exhibitor
/opt/exhibitor
/opt/exhibitor/bin
/opt/exhibitor/bin/exhibitor.sh
/opt/exhibitor/lib
/opt/exhibitor/lib/activation-1.1.jar
/opt/exhibitor/lib/annotations-2.0.0.jar
/opt/exhibitor/lib/aws-java-sdk-1.3.22.jar
/opt/exhibitor/lib/commons-cli-1.2.jar
/opt/exhibitor/lib/commons-codec-1.4.jar
/opt/exhibitor/lib/commons-logging-1.1.1.jar
/opt/exhibitor/lib/curator-client-2.3.0.jar
/opt/exhibitor/lib/curator-framework-2.3.0.jar
/opt/exhibitor/lib/curator-recipes-2.3.0.jar
/opt/exhibitor/lib/exhibitor-core-1.5.2-SNAPSHOT.jar
/opt/exhibitor/lib/exhibitor-standalone-1.5.2-SNAPSHOT.jar
/opt/exhibitor/lib/guava-14.0.1.jar
/opt/exhibitor/lib/httpclient-4.1.jar
/opt/exhibitor/lib/httpcore-4.1.jar
/opt/exhibitor/lib/jackson-core-asl-1.8.9.jar
/opt/exhibitor/lib/jackson-mapper-asl-1.8.9.jar
/opt/exhibitor/lib/jaxb-api-2.2.3.jar
/opt/exhibitor/lib/jaxb-impl-2.2.4.jar
/opt/exhibitor/lib/jersey-bundle-1.9.1.jar
/opt/exhibitor/lib/jetty-6.1.22.jar
/opt/exhibitor/lib/jetty-util-6.1.22.jar
/opt/exhibitor/lib/jline-0.9.94.jar
/opt/exhibitor/lib/jsr166y-1.7.0.jar
/opt/exhibitor/lib/jsr311-api-1.1.1.jar
/opt/exhibitor/lib/log4j-1.2.17.jar
/opt/exhibitor/lib/lucene-core-3.6.0.jar
/opt/exhibitor/lib/netty-3.2.2.Final.jar
/opt/exhibitor/lib/servlet-api-2.5-20081211.jar
/opt/exhibitor/lib/servlet-api-2.5.jar
/opt/exhibitor/lib/servo-core-0.5.2.jar
/opt/exhibitor/lib/slf4j-api-1.7.0.jar
/opt/exhibitor/lib/slf4j-log4j12-1.7.0.jar
/opt/exhibitor/lib/stax-api-1.0-2.jar
/opt/exhibitor/lib/zookeeper-3.4.5.jar

My "exhibitor.conf" looks like:
# cat /etc/exhibitor/exhibitor.conf
/etc/exhibitor/exhibitor.conf
EXHIBITOR_HOME=/opt/exhibitor
EXHIBITOR_PID=/var/run/exhibitor.pid
EXHIBITOR_LOG_FILE=/opt/exhibitor/log/exhibitor.out
EXHIBITOR_USER="zookeeper"

EXHIBITOR_OPTS="-Xms128M -Xmx128M"
EXHIBITOR_ARGS="--nodemodification true -c s3 --s3credentials /etc/exhibitor/exhibitor-aws.properties --s3config zookeeper-conf:exhibitor-config --port 8080"

EXHIBITOR_ARGS="$EXHIBITOR_ARGS --s3backup true"


Note that I store all exhibitor configurations in S3, that's why you see the "--s3config", I also encourage you to do so (zookeeper-conf is the bucket name and exhibitor-config is the file name). If you do not use "--s3config", you can use "--fsconfigdir" in conjunction with "--fsconfigname". Below is an example of my "exhibitor-config" file:
com.netflix.exhibitor-rolling-hostnames=
com.netflix.exhibitor-rolling.zookeeper-data-directory=/var/lib/zookeeper
com.netflix.exhibitor-rolling.servers-spec=S\:1\:zookeeper1.tony.com,\nS\:2\:zookeeper2.tony.com,\nS\:3\:zookeeper3.tony.com\n
com.netflix.exhibitor.java-environment=ZOO_LOG_DIR\=/var/log/zookeeper\nSERVER_JVMFLAGS\="-Dcom.sun.management.jmxremote.ssl\=false -Dcom.sun.management.jmxremote.authenticate\=false -Dcom.sun.management.jmxremote.port\=9056 -Dcom.sun.management.jmxremote\=true -Xmx1G"
com.netflix.exhibitor.zookeeper-data-directory=/var/lib/zookeeper
com.netflix.exhibitor-rolling-hostnames-index=0
com.netflix.exhibitor-rolling.java-environment=ZOO_LOG_DIR\=/var/log/zookeeper\nSERVER_JVMFLAGS\="-Dcom.sun.management.jmxremote.ssl\=false -Dcom.sun.management.jmxremote.authenticate\=false -Dcom.sun.management.jmxremote.port\=9056 -Dcom.sun.management.jmxremote\=true -Xmx1G"
com.netflix.exhibitor-rolling.observer-threshold=0
com.netflix.exhibitor.servers-spec=S\:1\:zookeeper1.tony.com,\nS\:2\:zookeeper2.tony.com,\nS\:3\:zookeeper3.tony.com\n
com.netflix.exhibitor.cleanup-period-ms=43200000
com.netflix.exhibitor.zookeeper-install-directory=/usr/lib/zookeeper
com.netflix.exhibitor.check-ms=30000
com.netflix.exhibitor.zookeeper-log-directory=
com.netflix.exhibitor-rolling.auto-manage-instances=0
com.netflix.exhibitor-rolling.cleanup-period-ms=43200000
com.netflix.exhibitor-rolling.auto-manage-instances-settling-period-ms=0
com.netflix.exhibitor-rolling.check-ms=30000
com.netflix.exhibitor.log-index-directory=/var/lib/zookeeper
com.netflix.exhibitor-rolling.log-index-directory=/var/lib/zookeeper
com.netflix.exhibitor.backup-period-ms=30000
com.netflix.exhibitor-rolling.connect-port=2888
com.netflix.exhibitor-rolling.election-port=3888
com.netflix.exhibitor-rolling.backup-extra=throttle\=&bucket-name\=zookeeper-conf&key-prefix\=backup&max-retries\=&retry-sleep-ms\=
com.netflix.exhibitor.client-port=2181
com.netflix.exhibitor-rolling.zoo-cfg-extra=initLimit\=10&syncLimit\=5&tickTime\=2000
com.netflix.exhibitor-rolling.zookeeper-install-directory=/usr/lib/zookeeper
com.netflix.exhibitor.cleanup-max-files=3
com.netflix.exhibitor-rolling.backup-period-ms=30000
com.netflix.exhibitor-rolling.client-port=2181
com.netflix.exhibitor.backup-max-store-ms=604800000
com.netflix.exhibitor-rolling.cleanup-max-files=3
com.netflix.exhibitor-rolling.backup-max-store-ms=604800000
com.netflix.exhibitor.connect-port=2888
com.netflix.exhibitor.backup-extra=throttle\=&bucket-name\=zookeeper-conf&key-prefix\=backup&max-retries\=&retry-sleep-ms\=
com.netflix.exhibitor.log4j-properties=
com.netflix.exhibitor.observer-threshold=0
com.netflix.exhibitor.election-port=3888
com.netflix.exhibitor.zoo-cfg-extra=initLimit\=10&syncLimit\=5&tickTime\=2000
com.netflix.exhibitor-rolling.zookeeper-log-directory=
com.netflix.exhibitor.auto-manage-instances-settling-period-ms=0
com.netflix.exhibitor-rolling.log4j-properties=
com.netflix.exhibitor.auto-manage-instances=0

My exhibitor startup script looks like:
# cat /etc/init.d/exhibitor
/etc/init.d/exhibitor
#!/bin/bash
# /etc/init.d/exhibitor
# centos-compatible exhibitor startup script.
### BEGIN INIT INFO

# Provides:          exhibitor
# Required-Start:    $syslog $network
# Required-Stop:     $syslog $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start exhibitor.
# Description:       Controls exhibitor (ZooKeeper).
### END INIT INFO

# Source function library.
. /etc/init.d/functions

# Source java functions.
if [ -r /usr/share/java-utils/java-functions ]; then
  . /usr/share/java-utils/java-functions
else
  echo "Can't read Java functions library, aborting"
  exit 1
fi

# Source exhibitor configuration.
[ -f /etc/exhibitor/exhibitor.conf ] &&  . /etc/exhibitor/exhibitor.conf
set_jvm

JAVA_CMD=java

# CLASSPATH munging
CLASSPATH="${CLASSPATH}:$(build-classpath-directory ${EXHIBITOR_HOME}/lib 2>/dev/null)"

PARAMS="-cp $CLASSPATH $EXHIBITOR_OPTS com.netflix.exhibitor.application.ExhibitorMain $EXHIBITOR_ARGS"

case "$1" in
    start)
        echo -n "Starting Exhibitor ..."

        if [ ! -f $EXHIBITOR_LOG_FILE ]; then
            mkdir $(dirname $EXHIBITOR_LOG_FILE) > /dev/null 2>&1
            chown $EXHIBITOR_USER:$EXHIBITOR_USER $(dirname $EXHIBITOR_LOG_FILE) > /dev/null 2>&1
        fi

        # retrieving pid of the parent process
        /bin/su -l "$EXHIBITOR_USER" --shel=/bin/bash -c "$JAVA_CMD $PARAMS > $EXHIBITOR_LOG_FILE 2>&1 &"
        echo $(jps | grep ExhibitorMain | awk '{print $1}') > "$EXHIBITOR_PID"
        if [ $? == "0" ]; then
            success
        else
            failure
        fi
        echo
        ;;
    status)
        status -p "$EXHIBITOR_PID" exhibitor
        ;;
    stop)
        echo -n "Killing Exhibitor ..."
        killproc -p "$EXHIBITOR_PID" exhibitor
        echo
        ;;
    restart)
        $0 stop
        $0 start
        ;;
    *)
        echo "Usage: $0 {start|stop|status|restart}"
        exit 1
esac

Once you have exhibitor and zookeeper installed, start exhibotor, and in your browser, go to "http://zookeeper1.tony.com:8080/exhibitor/v1/ui/index.html". You should see the "Exhibitor for ZooKeeper". Enjoy!

If you have any questions, leave me a comment or email at tonylixu at gmail.com

No comments: