文件名称 | 说明 |
dockfile | docker镜像构建描述文件 |
start | ews镜像启动脚本 |
check | ews镜像健康检查脚本 |
制作zookeeper镜像的dockfile如下:
1 2 3 4 5 6 7 8 9 10 | from registry.acs.aliyun.com/open/java7: 3.0 . 0 COPY zookeeper- 3.4 . 6 .tar.gz /acs/user/zookeeper- 3.4 . 6 .tar.gz RUN cd /acs/user && tar xzf zookeeper- 3.4 . 6 .tar.gz && \ rm -fr zookeeper- 3.4 . 6 .tar.gz && mv zookeeper- 3.4 . 6 zookeeper && \ echo "export PATH=$PATH:/acs/user/jdk/bin:/acs/user/zookeeper/bin/" >> /root/.bash_profile echo "export PATH=$PATH:/acs/user/jdk/bin:/acs/user/zookeeper/bin/" >> /acs/user/.bash_profile COPY zoo.cfg /acs/user/zookeeper/conf/zoo.cfg COPY zkServer.sh /acs/user/zookeeper/bin/zkServer.sh COPY start /acs/bin/start COPY check /acs/bin/check |
start脚本如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #!/bin/bash env_file=/acs/conf/env.properties if [ -f $env_file ];then zoo_cfg_file=`cat $env_file |grep -w zk.cfg.file |sed "s/^zk.cfg.file=//" ` if [ "$zoo_cfg_file" != "" ]; then wget -O /acs/user/zookeeper/conf/zoo.cfg $zoo_cfg_file fi fi echo "################################### Start Zookeeper ###################################" if [ ! -d "/acs/log" ];then mkdir -p /acs/log fi if [ ! -d "/acs/data" ];then mkdir -p /acs/data fi sh /acs/user/zookeeper/bin/zkServer.sh start-foreground & if [ $? != 0 ]; then echo "Start zookeeper failed" exit 1 fi echo "Start zookeeper success" exit 0 |
check脚本如下
1 2 3 4 5 6 7 | #!/bin/bash if [ "`ps aux|grep zookeeper|grep -v grep|wc -l`" -eq 0 ];then echo "failed" exit 1 fi echo "success" exit 0 |
zoo.cfg文件如下
1 2 3 4 5 6 | tickTime= 2000 initLimit= 10 syncLimit= 5 dataDir=/acs/data/zookeeper dataLogDir=/acs/log/ clientPort= 2181 |
zkServer.sh文件如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | if [ "x$JMXLOCALONLY" = "x" ] then JMXLOCALONLY= false fi if [ "x$JMXDISABLE" = "x" ] then echo "JMX enabled by default" >& 2 # for some reason these two options are necessary on jdk6 on Ubuntu # accord to the docs they are not necessary, but otw jconsole cannot # do a local attach ZOOMAIN= "-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=$JMXLOCALONLY org.apache.zookeeper.server.quorum.QuorumPeerMain" else echo "JMX disabled by user request" >& 2 ZOOMAIN= "org.apache.zookeeper.server.quorum.QuorumPeerMain" fi # use POSTIX interface , symlink is followed automatically ZOOBIN= "${BASH_SOURCE-$0}" ZOOBIN= "$(dirname " ${ZOOBIN} ")" ZOOBINDIR= "$(cd " ${ZOOBIN} "; pwd)" if [ -e "$ZOOBIN/../libexec/zkEnv.sh" ]; then . "$ZOOBINDIR/../libexec/zkEnv.sh" else . "$ZOOBINDIR/zkEnv.sh" fi if [ "x$SERVER_JVMFLAGS" != "x" ] then JVMFLAGS= "$SERVER_JVMFLAGS $JVMFLAGS" fi if [ "x$2" != "x" ] 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 if $cygwin then ZOOCFG=`cygpath -wp "$ZOOCFG" ` # cygwin has a "kill" in the shell itself, gets confused KILL=/bin/kill else KILL=kill fi echo "Using config: $ZOOCFG" >& 2 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 if [ ! -w "$ZOO_LOG_DIR" ] ; then mkdir -p "$ZOO_LOG_DIR" fi _ZOO_DAEMON_OUT= "$ZOO_LOG_DIR/zookeeper.out" case $ 1 in start) echo -n "Starting zookeeper ... " if [ -f "$ZOOPIDFILE" ]; then if kill - 0 `cat "$ZOOPIDFILE" ` > /dev/ null 2 >& 1 ; then echo $command already running as process `cat "$ZOOPIDFILE" `. exit 0 fi fi nohup "$JAVA" "-Duser.timezone=Asia/Shanghai" "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" \ -cp "$CLASSPATH" $JVMFLAGS $ZOOMAIN "$ZOOCFG" > "$_ZOO_DAEMON_OUT" 2 >& 1 < /dev/ null & if [ $? -eq 0 ] then if /bin/echo -n $! > "$ZOOPIDFILE" then sleep 1 echo STARTED else echo FAILED TO WRITE PID exit 1 fi else echo SERVER DID NOT START exit 1 fi ;; start-foreground) ZOO_CMD=(exec "$JAVA" ) if [ "${ZOO_NOEXEC}" != "" ]; then ZOO_CMD=( "$JAVA" ) fi "${ZOO_CMD[@]}" "-Duser.timezone=Asia/Shanghai" "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" \ -cp "$CLASSPATH" $JVMFLAGS $ZOOMAIN "$ZOOCFG" ;; print-cmd) echo "\"$JAVA\" -Dzookeeper.log.dir=\"${ZOO_LOG_DIR}\" -Dzookeeper.root.logger=\"${ZOO_LOG4J_PROP}\" -cp \"$CLASSPATH\" $JVMFLAGS $ZOOMAIN \"$ZOOCFG\" > \"$_ZOO_DAEMON_OUT\" 2>&1 < /dev/null" ;; stop) echo -n "Stopping zookeeper ... " if [ ! -f "$ZOOPIDFILE" ] then echo "no zookeeper to stop (could not find file $ZOOPIDFILE)" else $KILL - 9 $(cat "$ZOOPIDFILE" ) rm "$ZOOPIDFILE" echo STOPPED fi exit 0 ;; upgrade) shift echo "upgrading the servers to 3.*" "$JAVA" "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" \ -cp "$CLASSPATH" $JVMFLAGS org.apache.zookeeper.server.upgrade.UpgradeMain ${@} echo "Upgrading ... " ;; restart) shift "$0" stop ${@} sleep 3 "$0" start ${@} ;; status) # -q is necessary on some versions of linux where nc returns too quickly, and no stat result is output clientPortAddress=`grep "^[[:space:]]*clientPortAddress[^[:alpha:]]" "$ZOOCFG" | sed -e 's/.*=//' ` if ! [ $clientPortAddress ] then clientPortAddress= "localhost" fi clientPort=`grep "^[[:space:]]*clientPort[^[:alpha:]]" "$ZOOCFG" | sed -e 's/.*=//' ` STAT=` "$JAVA" "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" \ -cp "$CLASSPATH" $JVMFLAGS org.apache.zookeeper.client.FourLetterWordMain \ $clientPortAddress $clientPort srvr 2 > /dev/ null \ | grep Mode` if [ "x$STAT" = "x" ] then echo "Error contacting service. It is probably not running." exit 1 else echo $STAT exit 0 fi ;; *) echo "Usage: $0 {start|start-foreground|stop|restart|status|upgrade|print-cmd}" >& 2 esac<br><br> |