Skip to content

Commit

Permalink
Upgrade to zk 3.5.7
Browse files Browse the repository at this point in the history
  • Loading branch information
hlwanghl committed Mar 1, 2020
1 parent 44fbfa2 commit 4b4a593
Show file tree
Hide file tree
Showing 18 changed files with 137 additions and 119 deletions.
3 changes: 2 additions & 1 deletion ansible/group_vars/all.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
zk_version: 3.4.14
zk_version: 3.5.7
zkrest_version: 3.4.14
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
dumpFlags="-XX:HeapDumpPath=/data/zookeeper/dump/dump.hprof"
{{- if eq "true" (getv "/env/zkAdminEnabled" "false") }}
pushd /opt/zookeeper/current
jarFiles="$(echo -n lib/slf4j-api*):zookeeper-$ZK_VERSION.jar"
jarFiles="$(echo -n lib/slf4j-api*):lib/zookeeper-$ZK_VERSION.jar"
authFlags="-Dzookeeper.DigestAuthenticationProvider.superDigest=$(java -cp $jarFiles \
org.apache.zookeeper.server.auth.DigestAuthenticationProvider \
"{{ getv "/env/zkAdminUsername" "" }}:{{ getv "/env/zkAdminPassword" "" }}" | awk -F'->' '{print $2}')"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,16 @@
firstJoiningNode="${joiningNodes%% *}"

flush /opt/app/conf/zookeeper/zoo.cfg << ZOO_CONF_EOF
tickTime={{getv "/env/tickTime" "2000"}}
initLimit={{getv "/env/initLimit" "10"}}
syncLimit={{getv "/env/syncLimit" "5"}}
tickTime={{ getv "/env/tickTime" "2000" }}
initLimit={{ getv "/env/initLimit" "10" }}
syncLimit={{ getv "/env/syncLimit" "5" }}
dataDir=/data/zookeeper
clientPort={{getv "/cluster/endpoints/client/port" "2181"}}
maxClientCnxns={{getv "/env/maxClientCnxns" "1000"}}
autopurge.snapRetainCount={{getv "/env/autopurge.snapRetainCount" "3"}}
autopurge.purgeInterval={{getv "/env/autopurge.purgeInterval" "0"}}
clientPort={{ getv "/cluster/endpoints/client/port" "2181" }}
maxClientCnxns={{ getv "/env/maxClientCnxns" "1000" }}
autopurge.snapRetainCount={{ getv "/env/autopurge.snapRetainCount" "3" }}
autopurge.purgeInterval={{ getv "/env/autopurge.purgeInterval" "1" }}
4lw.commands.whitelist=mntr,{{ getv "/env/4lw.commands.whitelist" "" }}
admin.enableServer={{ getv "/env/admin.server.enabled" "true" }}
tcpKeepAlive={{ getv "/env/tcpKeepAlive" "false" }}

{{- range $allNodes }}
{{- if not ($joiningNodes | filter .) }}
server.{{ if $usingGsid }}{{ getv (printf "/hosts/%s/gsid" .) }}{{ else }}{{ getv (printf "/hosts/%s/sid" .) }}{{ end }}={{ getv (printf "/hosts/%s/ip" .) }}:2888:3888
{{- end }}
{{- end }}

{{- $mySid := getv "/host/sid" }}
{{- range $joiningNodes }}
{{- $sid := getv (printf "/adding-hosts/%s/sid" .) }}
{{- if le $sid $mySid }}
server.{{ if $usingGsid }}{{ getv (printf "/adding-hosts/%s/gsid" .) }}{{ else }}{{ $sid }}{{ end }}={{ getv (printf "/adding-hosts/%s/ip" .) }}:2888:3888
{{- end }}
{{- end }}

{{- if $joiningNodes }}
{{- if and (not ($joiningNodes | filter (getv "/host/instance_id"))) (eq (sub (len $allNodes) (len $joiningNodes)) 1) }}
server.${firstJoiningNode%%/*}=${firstJoiningNode##*/}:2888:3888
{{- end }}
{{- end }}
standaloneEnabled=false
reconfigEnabled=false
dynamicConfigFile=/opt/app/conf/zookeeper/zoo.dynamic.cfg
ZOO_CONF_EOF
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
firstJoiningNode="${joiningNodes%% *}"

flush /opt/app/conf/zookeeper/zoo.dynamic.cfg << ZOO_DYNAMIC_CONF_EOF
{{- range $allNodes }}
{{- if not ($joiningNodes | filter .) }}
server.{{ if $usingGsid }}{{ getv (printf "/hosts/%s/gsid" .) }}{{ else }}{{ getv (printf "/hosts/%s/sid" .) }}{{ end }}={{ getv (printf "/hosts/%s/ip" .) }}:2888:3888
{{- end }}
{{- end }}

{{- $mySid := getv "/host/sid" }}
{{- range $joiningNodes }}
{{- $sid := getv (printf "/adding-hosts/%s/sid" .) }}
{{- if le $sid $mySid }}
server.{{ if $usingGsid }}{{ getv (printf "/adding-hosts/%s/gsid" .) }}{{ else }}{{ $sid }}{{ end }}={{ getv (printf "/adding-hosts/%s/ip" .) }}:2888:3888
{{- end }}
{{- end }}

{{- if $joiningNodes }}
{{- if and (not ($joiningNodes | filter (getv "/host/instance_id"))) (eq (sub (len $allNodes) (len $joiningNodes)) 1) }}
server.${firstJoiningNode%%/*}=${firstJoiningNode##*/}:2888:3888
{{- end }}
{{- end }}
ZOO_DYNAMIC_CONF_EOF
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NODE_CTL="zookeeper"
13 changes: 10 additions & 3 deletions ansible/roles/zookeeper/files/opt/app/bin/node/zookeeper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ initNode() {
chown -R zookeeper.svc /data/{zookeeper,zkrest}
local htmlFile=/data/index.html; [ -e "$htmlFile" ] || ln -s /opt/app/conf/caddy/index.html $htmlFile
_initNode

if [ "$IS_UPGRADING" == "true" ]; then
# Fix "java.io.IOException: No snapshot found, but there are log entries. Something is broken!".
# See https://issues.apache.org/jira/browse/ZOOKEEPER-3056 for details.
local snapFile=/data/zookeeper/version-2/snapshot.0
[ -e $snapFile ] || sudo -u zookeeper cp /opt/app/conf/zookeeper/snapshot.0 $snapFile
fi
}

start() {
Expand All @@ -34,13 +41,13 @@ reconfigure() {
}

checkFullyStarted() {
local ip=${1:-$MY_IP} mode=${2:-"(leader|follower|standalone)"}
local ip=${1:-$MY_IP} mode=${2:-"(leader|follower)"}
retrieveMode $ip | egrep -q "^$mode$" || return $EC_START_ERR
}

retrieveMode() {
local ip=${1:-$MY_IP}
echo mntr | nc -q2 -w2 $ip 2181 | egrep "^zk_server_state\s(leader|follower|standalone)$" | cut -f2 || {
echo mntr | nc -q2 -w2 $ip 2181 | egrep "^zk_server_state\s(leader|follower)$" | cut -f2 || {
log "ERROR Failed to retrieve mode of $ip."
return $EC_RETRIEVE_MODE_ERR
}
Expand Down Expand Up @@ -93,7 +100,7 @@ restore() {

checkSvc() {
if [ "$1" == "zookeeper" ]; then
retrieveMode | egrep -q '^(leader|follower|standalone)$' || return $EC_UNKNOWN_MODE
retrieveMode | egrep -q '^(leader|follower)$' || return $EC_UNKNOWN_MODE
fi
_checkSvc $@
}
Expand Down
Empty file.
8 changes: 0 additions & 8 deletions ansible/roles/zookeeper/files/opt/app/conf/zkrest/keys/README

This file was deleted.

Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
# Copyright 2012 The Apache Software Foundation
#
# 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.

# Define some default values that can be overridden by system properties
zookeeper.root.logger=INFO, CONSOLE, ROLLINGFILE
zookeeper.root.logger=INFO, ROLLINGFILE

zookeeper.console.threshold=INFO

zookeeper.log.dir=/data/zookeeper/logs
zookeeper.log.file=zookeeper.log
zookeeper.log.threshold=INFO
zookeeper.tracelog.dir=/data/zookeeper/logs
zookeeper.tracelog.file=zookeeper_trace.log

#
# ZooKeeper Logging Configuration
#
zookeeper.log.maxfilesize=1MB
zookeeper.log.maxbackupindex=50

# Format is "<default threshold> (, <appender>)+
zookeeper.tracelog.dir=${zookeeper.log.dir}
zookeeper.tracelog.file=zookeeper_trace.log

# 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
# console
# Add "console" to rootlogger above if you want to use this
#
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Threshold=${zookeeper.console.threshold}
Expand All @@ -32,29 +43,24 @@ log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-

#
# 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.Threshold=${zookeeper.log.threshold}
log4j.appender.ROLLINGFILE.File=${zookeeper.log.dir}/${zookeeper.log.file}

# Max log file size of 10MB
log4j.appender.ROLLINGFILE.MaxFileSize=1MB
# uncomment the next line to limit number of backup files
log4j.appender.ROLLINGFILE.MaxBackupIndex=50

log4j.appender.ROLLINGFILE.MaxFileSize=${zookeeper.log.maxfilesize}
log4j.appender.ROLLINGFILE.MaxBackupIndex=${zookeeper.log.maxbackupindex}
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
# Log TRACE level and above messages to a log file
#
log4j.appender.TRACEFILE=org.apache.log4j.RollingFileAppender
log4j.appender.TRACEFILE.Threshold=TRACE
log4j.appender.TRACEFILE.File=${zookeeper.tracelog.dir}/${zookeeper.tracelog.file}
log4j.appender.TRACEFILE.MaxFileSize=1MB
log4j.appender.TRACEFILE.MaxBackupIndex=50

log4j.appender.TRACEFILE.MaxFileSize=${zookeeper.log.maxfilesize}
log4j.appender.TRACEFILE.MaxBackupIndex=${zookeeper.log.maxbackupindex}
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
Binary file not shown.
Empty file.

This file was deleted.

45 changes: 33 additions & 12 deletions ansible/roles/zookeeper/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
---
- name: set vars
set_fact:
zk_version: 3.5.7
zkrest_version: 3.4.14

- name: add the service group
group:
name: svc
Expand All @@ -21,30 +26,35 @@
opts:
pkg_name: zookeeper
pkg_version: "{{ zk_version }}"
pkg_url: https://mirror.bit.edu.cn/apache/zookeeper/zookeeper-{{ zk_version }}/zookeeper-{{ zk_version }}.tar.gz
pkg_url: https://mirror.bit.edu.cn/apache/zookeeper/zookeeper-{{ zk_version }}/apache-zookeeper-{{ zk_version }}-bin.tar.gz
pkg_type: .tgz
extracts: true
bin_path: bin
creates: bin/zkServer.sh

- name: set up zkrest dir
file:
path: /opt/zkrest
state: directory

- name: set up zkrest files
file:
src: /opt/zookeeper/current/zookeeper-contrib/zookeeper-contrib-rest
dest: /opt/zkrest/current
state: link
- name: install zkrest
include_role:
name: install-1.0.0
vars:
opts:
pkg_name: zkrest
pkg_version: "{{ zkrest_version }}"
pkg_url: https://mirror.bit.edu.cn/apache/zookeeper/zookeeper-{{ zkrest_version }}/zookeeper-{{ zkrest_version }}.tar.gz
pkg_type: .tgz
extracts: true
extra_opts:
- --strip-components=3
- zookeeper-{{ zkrest_version }}/zookeeper-contrib/zookeeper-contrib-rest
creates: zookeeper-{{ zkrest_version }}-rest.jar

- name: link necessary zk jar files to bootstrap zkrest
file:
src: /opt/zookeeper/current/{{ file_path }}
src: /opt/zookeeper/current/lib/{{ file_path }}
dest: /opt/zkrest/current/{{ file_path }}
state: link
loop:
- zookeeper-{{ zk_version }}.jar
- zookeeper-jute-{{ zk_version }}.jar
loop_control:
loop_var: file_path

Expand Down Expand Up @@ -74,6 +84,17 @@
mode: preserve
directory_mode: u=rwx,g=rx,o=

- name: allow zk change conf files at runtime
file:
path: /opt/app/conf/zookeeper/{{ path }}
owner: zookeeper
group: svc
loop:
- zoo.cfg
- zoo.dynamic.cfg
loop_control:
loop_var: path

- name: set up zk env
copy:
dest: /opt/app/bin/envs/confd.env
Expand Down
7 changes: 4 additions & 3 deletions app/cluster.json.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"nodes": [{
"container": {
"type": "kvm",
"zone": "pek3a",
"image": "img-bdt5kork"
"zone": "pek3",
"image": "img-nd557r5e"
},
"count": {{cluster.zk_node.count}},
"cpu": {{cluster.zk_node.cpu}},
Expand Down Expand Up @@ -80,7 +80,7 @@
"unit": "",
"value_type": "str",
"statistics_type": "latest",
"enums": ["L", "F", "S"]
"enums": ["L", "F"]
},
"min": {
"unit": "ms",
Expand Down Expand Up @@ -144,6 +144,7 @@
"zkAdminEnabled": {{env.admin_enabled}},
"zkAdminUsername": {{env.admin_username}},
"zkAdminPassword": {{env.admin_password}},
"admin.server.enabled": {{env.admin.server.enabled}},
"web.console.enabled": {{env.web.console.enabled}},
"web.console.username": {{env.web.console.username}},
"web.console.password": {{env.web.console.password}},
Expand Down
11 changes: 10 additions & 1 deletion app/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
"conf",
"cons",
"crst",
"dirs",
"dump",
"envi",
"gtmk",
Expand All @@ -185,7 +186,7 @@
"wchs"
],
"multichoice": true,
"default": "conf,cons,crst,dump,envi,gtmk,isro,ruok,srst,srvr,stat,stmk,wchc,wchp,wchs",
"default": "srvr",
"required": "no"
}, {
"key": "tcpKeepAlive",
Expand All @@ -195,6 +196,14 @@
"changeable": true,
"default": false,
"required": "no"
}, {
"key": "admin.server.enabled",
"label": "Enable AdminServer",
"description": "The AdminServer is an embedded Jetty server that provides an HTTP interface to the four letter word commands",
"type": "boolean",
"changeable": true,
"default": true,
"required": "no"
}, {
"key": "web.console.enabled",
"label": "Enable Web Console",
Expand Down
Loading

0 comments on commit 4b4a593

Please sign in to comment.