Skip to content

Instantly share code, notes, and snippets.

@vbratkev
Forked from smuthali/zookeeper.hcl
Created May 31, 2019 11:54
Show Gist options
  • Save vbratkev/3065e3113afb07cc1ab915561d047b3d to your computer and use it in GitHub Desktop.
Save vbratkev/3065e3113afb07cc1ab915561d047b3d to your computer and use it in GitHub Desktop.
# Zookeeper
job "zookeeper" {
# Specify Region
region = "uswest-fremont"
# Specify Datacenter
datacenters = [ "fremont-dc1"]
# Specify job type
type = "service"
# Run tasks in serial or parallel (1 for serial)
update {
max_parallel = 1
}
# define group
group "zk-docker" {
# define the number of times the tasks need to be executed
count = 3
# define job constraints
constraint {
attribute = "${attr.kernel.name}"
value = "linux"
}
constraint {
attribute = "${meta.zk_host_key}"
value = "zookeeper"
}
# specify the number of attemtps to run the job within the specified interval
restart {
attempts = 10
interval = "5m"
delay = "25s"
mode = "delay"
}
task "zk-config-dir" {
driver = "exec"
config {
command = "mkdir"
args = [ "-p", "/opt/zookeeper/config" ]
}
}
task "zk-data-dir" {
driver = "exec"
config {
command = "mkdir"
args = [ "-p", "/opt/zookeeper/datadir" ]
}
}
task "zookeeper" {
driver = "docker"
template {
source = "/etc/nomad.d/jobs/zookeeper/templates/zoo.tpl"
destination = "/opt/zookeeper/config/zoo.cfg"
change_mode = "noop"
}
config {
image = "<REDACTED>"
labels {
group = "zk-docker"
}
auth {
username = "<REDACTED>"
password = "<REDACTED>"
}
port_map {
zoo_port = 2181
zoo_peer1 = 2888
zoo_peer2 = 3888
}
volumes = [
"/opt/zookeeper/config:/opt/zookeeper/conf",
"/opt/zookeeper/datadir:/tmp/zookeeper"
]
}
resources {
cpu = 100
memory = 128
network {
mbits = 10
port "zoo_port" {}
port "zoo_peer1" {}
port "zoo_peer2" {}
}
}
service {
tags = ["zookeeper"]
check {
type = "script"
name = "zookeeper_docker_check"
command = "/etc/consul.d/config/zk_check.sh"
interval = "60s"
timeout = "5s"
}
}
}
}
}
And the consul template looks something like this
# 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=/tmp/zookeeper
# 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=4
{{range $i, $services := service "zookeeper"}}
server.{{ $i | add 1 }}={{.Address}}:2888:38888
{{ end }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment