summaryrefslogtreecommitdiff
path: root/bigdata-scripts_test3/roles/zookeeper
diff options
context:
space:
mode:
Diffstat (limited to 'bigdata-scripts_test3/roles/zookeeper')
-rwxr-xr-xbigdata-scripts_test3/roles/zookeeper/files/dae-zookeeper.sh22
-rw-r--r--bigdata-scripts_test3/roles/zookeeper/files/log4j.properties63
-rw-r--r--bigdata-scripts_test3/roles/zookeeper/files/restart_sum.log1
-rwxr-xr-xbigdata-scripts_test3/roles/zookeeper/files/zkEnv.sh116
-rwxr-xr-xbigdata-scripts_test3/roles/zookeeper/files/zkServer.sh225
-rwxr-xr-xbigdata-scripts_test3/roles/zookeeper/files/zklogdelete.sh20
-rw-r--r--bigdata-scripts_test3/roles/zookeeper/files/zookeeper-3.4.9.tar.gzbin0 -> 22724574 bytes
-rw-r--r--bigdata-scripts_test3/roles/zookeeper/tasks/main.yml91
-rwxr-xr-xbigdata-scripts_test3/roles/zookeeper/templates/keepzkalive.j211
-rwxr-xr-xbigdata-scripts_test3/roles/zookeeper/templates/set_zk_profile.sh.j26
-rwxr-xr-xbigdata-scripts_test3/roles/zookeeper/templates/zoo.cfg.j231
11 files changed, 586 insertions, 0 deletions
diff --git a/bigdata-scripts_test3/roles/zookeeper/files/dae-zookeeper.sh b/bigdata-scripts_test3/roles/zookeeper/files/dae-zookeeper.sh
new file mode 100755
index 0000000..24d3527
--- /dev/null
+++ b/bigdata-scripts_test3/roles/zookeeper/files/dae-zookeeper.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+#进程名称
+PRO_NAME=QuorumPeerMain
+#安装路径
+BASE_DIR=$1
+VERSION="zookeeper-3.4.9"
+source /etc/profile
+while true ; do
+ NUM=`$BASE_DIR/$VERSION/bin/zkServer.sh status | egrep 'leader|follower' | wc -l`
+ if [ "${NUM}" -lt "1" ];then
+ $BASE_DIR/$VERSION/bin/zkServer.sh start
+ OLD_NUM=`cat $BASE_DIR/$VERSION/logs/restart_sum.log`
+ RESTART_NUM=`expr $OLD_NUM + 1`
+ echo $RESTART_NUM > $BASE_DIR/$VERSION/logs/restart_sum.log
+ echo "`date "+%Y-%m-%d %H:%M:%S"` - zookeeper服务启动/异常重启 - 重启次数 -> $RESTART_NUM" >> $BASE_DIR/$VERSION/restart.log
+ #大于1,杀掉所有进程,重启
+ elif [ "${NUM}" -gt "1" ];then
+ killall-9 ${PRO_NAME}
+ fi
+ sleep 60
+done
diff --git a/bigdata-scripts_test3/roles/zookeeper/files/log4j.properties b/bigdata-scripts_test3/roles/zookeeper/files/log4j.properties
new file mode 100644
index 0000000..6f535ec
--- /dev/null
+++ b/bigdata-scripts_test3/roles/zookeeper/files/log4j.properties
@@ -0,0 +1,63 @@
+# Define some default values that can be overridden by system properties
+#zookeeper.root.logger=INFO, CONSOLE
+zookeeper.root.logger=INFO, ROLLINGFILE
+zookeeper.console.threshold=INFO
+zookeeper.log.dir=.
+zookeeper.log.file=zookeeper.log
+zookeeper.log.threshold=DEBUG
+zookeeper.tracelog.dir=.
+zookeeper.tracelog.file=zookeeper_trace.log
+
+#
+# ZooKeeper Logging Configuration
+#
+
+# Format is "<default threshold> (, <appender>)+
+
+# DEFAULT: console appender only
+log4j.rootLogger=${zookeeper.root.logger}
+
+# Example with rolling log file
+#log4j.rootLogger=DEBUG, CONSOLE, ROLLINGFILE
+
+# Example with rolling log file and tracing
+#log4j.rootLogger=TRACE, CONSOLE, ROLLINGFILE, TRACEFILE
+
+#
+# Log INFO level and above messages to the console
+#
+log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
+log4j.appender.CONSOLE.Threshold=${zookeeper.console.threshold}
+log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
+log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n
+
+#
+# Add ROLLINGFILE to rootLogger to get log file output
+# Log DEBUG level and above messages to a log file
+#log4j.appender.ROLLINGFILE=org.apache.log4j.RollingFileAppender
+log4j.appender.ROLLINGFILE=org.apache.log4j.DailyRollingFileAppender
+log4j.appender.ROLLINGFILE.Threshold=${zookeeper.log.threshold}
+log4j.appender.ROLLINGFILE.File=${zookeeper.log.dir}/${zookeeper.log.file}
+log4j.appender.ROLLINGFILE.DataPattern='.'yyyy-MM-dd-HH
+log4j.appender.ROLLINGFILE.layout=org.apache.log4j.PatternLayout
+log4j.appender.ROLLINGFILE.layout.ConversionPattern=[%d] %p %m (%c)%n
+
+# Max log file size of 10MB
+log4j.appender.ROLLINGFILE.MaxFileSize=10MB
+# uncomment the next line to limit number of backup files
+#log4j.appender.ROLLINGFILE.MaxBackupIndex=10
+
+log4j.appender.ROLLINGFILE.layout=org.apache.log4j.PatternLayout
+log4j.appender.ROLLINGFILE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n
+
+
+#
+# Add TRACEFILE to rootLogger to get log file output
+# Log DEBUG level and above messages to a log file
+log4j.appender.TRACEFILE=org.apache.log4j.FileAppender
+log4j.appender.TRACEFILE.Threshold=TRACE
+log4j.appender.TRACEFILE.File=${zookeeper.tracelog.dir}/${zookeeper.tracelog.file}
+
+log4j.appender.TRACEFILE.layout=org.apache.log4j.PatternLayout
+### Notice we are including log4j's NDC here (%x)
+log4j.appender.TRACEFILE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L][%x] - %m%n
diff --git a/bigdata-scripts_test3/roles/zookeeper/files/restart_sum.log b/bigdata-scripts_test3/roles/zookeeper/files/restart_sum.log
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/bigdata-scripts_test3/roles/zookeeper/files/restart_sum.log
@@ -0,0 +1 @@
+0
diff --git a/bigdata-scripts_test3/roles/zookeeper/files/zkEnv.sh b/bigdata-scripts_test3/roles/zookeeper/files/zkEnv.sh
new file mode 100755
index 0000000..d6918aa
--- /dev/null
+++ b/bigdata-scripts_test3/roles/zookeeper/files/zkEnv.sh
@@ -0,0 +1,116 @@
+#!/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.
+
+# This script should be sourced into other zookeeper
+# scripts to setup the env variables
+
+# We use ZOOCFGDIR if defined,
+# otherwise we use /etc/zookeeper
+# or the conf directory that is
+# a sibling of this script's directory
+
+ZOOBINDIR="${ZOOBINDIR:-/usr/bin}"
+ZOOKEEPER_PREFIX="${ZOOBINDIR}/.."
+
+if [ "x$ZOOCFGDIR" = "x" ]
+then
+ if [ -e "${ZOOKEEPER_PREFIX}/conf" ]; then
+ ZOOCFGDIR="$ZOOBINDIR/../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"
+fi
+
+ZOOCFG="$ZOOCFGDIR/$ZOOCFG"
+
+if [ -f "$ZOOCFGDIR/java.env" ]
+then
+ . "$ZOOCFGDIR/java.env"
+fi
+
+if [ "x${ZOO_LOG_DIR}" = "x" ]
+then
+ ZOO_LOG_DIR="${ZOOKEEPER_PREFIX}/logs/system"
+fi
+
+if [ "x${ZOO_LOG4J_PROP}" = "x" ]
+then
+ #ZOO_LOG4J_PROP="INFO,CONSOLE"
+ ZOO_LOG4J_PROP="INFO,ROLLINGFILE"
+fi
+
+if [ "$JAVA_HOME" != "" ]; then
+ JAVA="$JAVA_HOME/bin/java"
+else
+ JAVA=java
+fi
+
+#add the zoocfg dir to classpath
+CLASSPATH="$ZOOCFGDIR:$CLASSPATH"
+
+for i in "$ZOOBINDIR"/../src/java/lib/*.jar
+do
+ CLASSPATH="$i:$CLASSPATH"
+done
+
+#make it work in the binary package
+#(use array for LIBPATH to account for spaces within wildcard expansion)
+if [ -e "${ZOOKEEPER_PREFIX}"/share/zookeeper/zookeeper-*.jar ]; then
+ LIBPATH=("${ZOOKEEPER_PREFIX}"/share/zookeeper/*.jar)
+else
+ #release tarball format
+ for i in "$ZOOBINDIR"/../zookeeper-*.jar
+ do
+ CLASSPATH="$i:$CLASSPATH"
+ done
+ LIBPATH=("${ZOOBINDIR}"/../lib/*.jar)
+fi
+
+for i in "${LIBPATH[@]}"
+do
+ CLASSPATH="$i:$CLASSPATH"
+done
+
+#make it work for developers
+for d in "$ZOOBINDIR"/../build/lib/*.jar
+do
+ CLASSPATH="$d:$CLASSPATH"
+done
+
+#make it work for developers
+CLASSPATH="$ZOOBINDIR/../build/classes:$CLASSPATH"
+
+case "`uname`" in
+ CYGWIN*) cygwin=true ;;
+ *) cygwin=false ;;
+esac
+
+if $cygwin
+then
+ CLASSPATH=`cygpath -wp "$CLASSPATH"`
+fi
+
+#echo "CLASSPATH=$CLASSPATH"
diff --git a/bigdata-scripts_test3/roles/zookeeper/files/zkServer.sh b/bigdata-scripts_test3/roles/zookeeper/files/zkServer.sh
new file mode 100755
index 0000000..396aedd
--- /dev/null
+++ b/bigdata-scripts_test3/roles/zookeeper/files/zkServer.sh
@@ -0,0 +1,225 @@
+#!/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.
+
+#
+# If this scripted is run out of /usr/bin or some other system bin directory
+# it should be linked to and not copied. Things like java jar files are found
+# relative to the canonical path of this script.
+#
+
+
+
+# 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
+
+# See the following page for extensive details on setting
+# up the JVM to accept JMX remote management:
+# http://java.sun.com/javase/6/docs/technotes/guides/management/agent.html
+# by default we allow local JMX connections
+if [ "x$JMXLOCALONLY" = "x" ]
+then
+ JMXLOCALONLY=false
+fi
+
+if [ "x$JMXDISABLE" = "x" ] || [ "$JMXDISABLE" = 'false' ]
+then
+ echo "ZooKeeper JMX enabled by default" >&2
+ if [ "x$JMXPORT" = "x" ]
+ then
+ # 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
+ if [ "x$JMXAUTH" = "x" ]
+ then
+ JMXAUTH=false
+ fi
+ if [ "x$JMXSSL" = "x" ]
+ then
+ JMXSSL=false
+ fi
+ if [ "x$JMXLOG4J" = "x" ]
+ then
+ JMXLOG4J=true
+ fi
+ echo "ZooKeeper remote JMX Port set to $JMXPORT" >&2
+ echo "ZooKeeper remote JMX authenticate set to $JMXAUTH" >&2
+ echo "ZooKeeper remote JMX ssl set to $JMXSSL" >&2
+ echo "ZooKeeper remote JMX log4j set to $JMXLOG4J" >&2
+ ZOOMAIN="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=$JMXPORT -Dcom.sun.management.jmxremote.authenticate=$JMXAUTH -Dcom.sun.management.jmxremote.ssl=$JMXSSL -Dzookeeper.jmx.log4j.disable=$JMXLOG4J org.apache.zookeeper.server.quorum.QuorumPeerMain"
+ fi
+else
+ echo "JMX disabled by user request" >&2
+ ZOOMAIN="org.apache.zookeeper.server.quorum.QuorumPeerMain"
+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
+
+case "$OSTYPE" in
+*solaris*)
+ GREP=/usr/xpg4/bin/grep
+ ;;
+*)
+ GREP=grep
+ ;;
+esac
+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.log"
+
+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" "-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
+ case "$OSTYPE" in
+ *solaris*)
+ /bin/echo "${!}\\c" > "$ZOOPIDFILE"
+ ;;
+ *)
+ /bin/echo -n $! > "$ZOOPIDFILE"
+ ;;
+ esac
+ if [ $? -eq 0 ];
+ 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[@]}" "-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
diff --git a/bigdata-scripts_test3/roles/zookeeper/files/zklogdelete.sh b/bigdata-scripts_test3/roles/zookeeper/files/zklogdelete.sh
new file mode 100755
index 0000000..7551d41
--- /dev/null
+++ b/bigdata-scripts_test3/roles/zookeeper/files/zklogdelete.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+#只保留最近三天的日志,如需要多保留几天修改最后 -n days
+#将此脚本加载到系统定时任务中 /etc/crontab
+#脚本会读取环境变量,固需要配置环境变量。
+#. /etc/profile
+day=$(date +"%Y-%m-%d" -d "-3 days")
+
+zk=`jps | grep QuorumPeerMain | wc -l`
+if [[ $zk = "1" ]];then
+#echo $ZOOKEEPER_HOME/logs/system/*.$day*
+ rm -rf $ZOOKEEPER_HOME/logs/system/*.$day*
+fi
+
+kafka=`jps | grep Kafka | wc -l`
+if [[ $kafka = "1" ]];then
+#echo $KAFKA_HOME/logs/*.$day*
+ rm -rf $KAFKA_HOME/logs/*.$day*
+fi
+
diff --git a/bigdata-scripts_test3/roles/zookeeper/files/zookeeper-3.4.9.tar.gz b/bigdata-scripts_test3/roles/zookeeper/files/zookeeper-3.4.9.tar.gz
new file mode 100644
index 0000000..77bed6e
--- /dev/null
+++ b/bigdata-scripts_test3/roles/zookeeper/files/zookeeper-3.4.9.tar.gz
Binary files differ
diff --git a/bigdata-scripts_test3/roles/zookeeper/tasks/main.yml b/bigdata-scripts_test3/roles/zookeeper/tasks/main.yml
new file mode 100644
index 0000000..c338247
--- /dev/null
+++ b/bigdata-scripts_test3/roles/zookeeper/tasks/main.yml
@@ -0,0 +1,91 @@
+- name: "copy zookeeper install package to destination server"
+ copy:
+ src: "{{ role_path }}/files/{{ zookeeper.package_name }}"
+ dest: /tmp
+
+- name: "create zookeeper base_dir"
+ file:
+ path: '{{ zookeeper.base_dir }}'
+ state: touch
+
+- name: "install zookeeper"
+ unarchive:
+ src: "/tmp/{{ zookeeper.package_name }}"
+ dest: '{{ zookeeper.base_dir }}'
+ copy: no
+ mode: 0755
+
+- name: "copy any scripts"
+ copy:
+ src: '{{ item.src }}'
+ dest: '{{ item.dest }}'
+ mode: 0755
+ with_item:
+ - { src: '{{ role_path }}/files/dae-zookeeper.sh', dest: '{{ zookeeper.base_dir }}/{{ zookeeper.version }}/bin/' }
+ - { src: '{{ role_path }}/files/zkEnv.sh', dest: '{{ zookeeper.base_dir }}/{{ zookeeper.version }}/bin/' }
+ - { src: '{{ role_path }}/files/zklogdelete.sh', dest: '{{ zookeeper.base_dir }}/{{ zookeeper.version }}/bin/' }
+ - { src: '{{ role_path }}/files/zkServer.sh', dest: '{{ zookeeper.base_dir }}/{{ zookeeper.version }}/bin/' }
+
+- name: "copy log4j.properties"
+ copy:
+ src: "{{ role_path }}/files/log4j.properties"
+ dest: '{{ zookeeper.base_dir }}/{{ zookeeper.version }}/conf/'
+
+- name: "create zoo.cfg"
+ template:
+ src: "{{ role_path }}/templates/zoo.cfg.j2"
+ dest: '{{ zookeeper.base_dir }}/{{ zookeeper.version }}/conf/zoo.cfg'
+ mode: 0755
+
+- name: "create any dir"
+ file:
+ path: '{{ item.path }}'
+ state: '{{ item.state }}'
+ with_items:
+ - { path: '{{ zookeeper.base_dir }}/{{ zookeeper.version }}/data', state: directory }
+ - { path: '{{ zookeeper.base_dir }}/{{ zookeeper.version }}/logs', state: directory }
+ - { path: '{{ zookeeper.base_dir }}/{{ zookeeper.version }}/data/myid', state: touch }
+
+- name: "echo 0 > restart_sum.log"
+ shell: echo 0 > '{{ zookeeper.base_dir }}/{{ zookeeper.version }}/logs/restart_sum.log'
+
+- name: "judge zoo.cfg id and ip"
+ shell: grep ":2888:3888" {{ zookeeper.base_dir }}/{{ zookeeper.version }}/conf/zoo.cfg
+ register: return
+ ignore_errors: true
+
+- name: "traverse ip/port"
+ shell: echo "server.{{ item.0 }}={{ item.1 }}:2888:3888" >> {{ zookeeper.base_dir }}/{{ zookeeper.version }}/conf/zoo.cfg
+ with_together:
+ - '{{ zookeeper.idlist }}'
+ - '{{ zookeeper.iplist }}'
+ when: return.rc != 0
+
+- name: "traverse zookeeper myid"
+ shell: echo "{{ zk_myid }}" > {{ zookeeper.base_dir }}/{{ zookeeper.version }}/data/myid
+
+- name: "template keepzkalive"
+ template:
+ src: "{{ role_path }}/templates/keepzkalive.j2"
+ dest: /etc/init.d/keepzkalive
+
+- name: "start keepzkalive"
+ service:
+ name: keepzkalive
+ state: restarted
+ enabled: true
+
+- name: "template set_zk_profile.sh"
+ template:
+ src: "{{ role_path }}/templates/set_zk_profile.sh.j2"
+ dest: /tmp/set_zk_profile.sh
+ mode: 0755
+
+- name: "judge zookeeper enviroment"
+ shell: grep "#zookeeper" /etc/profile
+ register: return
+ ignore_errors: true
+
+- name: "set_zk_profile"
+ shell: /bin/bash /tmp/set_zk_profile.sh
+ when: return.rc != 0
diff --git a/bigdata-scripts_test3/roles/zookeeper/templates/keepzkalive.j2 b/bigdata-scripts_test3/roles/zookeeper/templates/keepzkalive.j2
new file mode 100755
index 0000000..7cb89a6
--- /dev/null
+++ b/bigdata-scripts_test3/roles/zookeeper/templates/keepzkalive.j2
@@ -0,0 +1,11 @@
+#!/bin/bash
+#
+# netconsole This loads the netconsole module with the configured parameters.
+#
+# chkconfig:123456 20 80
+# description: keepzkalive
+source /etc/profile
+PRO_NAME=keepzklive
+
+killall -9 dae-zookeeper.sh
+{{ zookeeper.base_dir }}/{{ zookeeper.version }}/bin/dae-zookeeper.sh {{ zookeeper.base_dir }} > /dev/null 2>&1 &
diff --git a/bigdata-scripts_test3/roles/zookeeper/templates/set_zk_profile.sh.j2 b/bigdata-scripts_test3/roles/zookeeper/templates/set_zk_profile.sh.j2
new file mode 100755
index 0000000..e5e950f
--- /dev/null
+++ b/bigdata-scripts_test3/roles/zookeeper/templates/set_zk_profile.sh.j2
@@ -0,0 +1,6 @@
+#!/bin/bash
+#
+echo -e ""##zookeeper"" >> /etc/profile
+echo -e "export ZOOKEEPER_HOME='{{ zookeeper.base_dir }}'/'{{ zookeeper.version }}'" >> /etc/profile
+echo -e "export PATH=\$ZOOKEEPER_HOME/bin:\$PATH" >> /etc/profile
+source /etc/profile
diff --git a/bigdata-scripts_test3/roles/zookeeper/templates/zoo.cfg.j2 b/bigdata-scripts_test3/roles/zookeeper/templates/zoo.cfg.j2
new file mode 100755
index 0000000..7db718c
--- /dev/null
+++ b/bigdata-scripts_test3/roles/zookeeper/templates/zoo.cfg.j2
@@ -0,0 +1,31 @@
+# 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={{ zookeeper.base_dir }}/{{ version }}/data
+# the port at which the clients will connect
+clientPort=2181
+# the maximum number of client connections.
+# increase this if you need to handle more clients
+#maxClientCnxns=60
+#
+# Be sure to read the maintenance section of the
+# administrator guide before turning on autopurge.
+#
+# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
+#
+# The number of snapshots to retain in dataDir
+#autopurge.snapRetainCount=3
+# Purge task interval in hours
+# Set to "0" to disable auto purge feature
+#autopurge.purgeInterval=1
+dataLogDir={{ zookeeper.base_dir }}/{{ zookeeper.version }}/log
+autopurge.purgeInterval=24
+