Add zk cluster
parent
7e2eb2da3a
commit
106f4b027f
|
@ -0,0 +1,18 @@
|
|||
|
||||
download:
|
||||
docker pull yeasy/kafka:latest
|
||||
|
||||
start:
|
||||
docker stack deploy --compose-file docker-compose.yaml zk
|
||||
stop:
|
||||
docker stack rm zk
|
||||
|
||||
restart: stop start
|
||||
|
||||
zookeeper:
|
||||
docker exec -it zookeeper1 bash
|
||||
kafka:
|
||||
docker exec -it kafka1 bash
|
||||
|
||||
cli:
|
||||
docker exec -it cli bash
|
|
@ -0,0 +1,62 @@
|
|||
# Zookeeper
|
||||
|
||||
This project provides several useful Docker-Compose script to help quickly bootup a Zookeeper cluster.
|
||||
|
||||
Currently we support Zookeeper 3.5.6.*.
|
||||
|
||||
TBD
|
||||
|
||||
## Start
|
||||
|
||||
```bash
|
||||
$ docker-compose up -d
|
||||
```
|
||||
|
||||
## Test
|
||||
|
||||
Open a new shell to the cli container:
|
||||
|
||||
```bash
|
||||
$ docker exec -it cli bash
|
||||
```
|
||||
|
||||
In the container shell, create a new topic and wait for new msg (dir default to KAFKA_HOME=/opt/kafka/).
|
||||
|
||||
```bash
|
||||
# pwd
|
||||
/opt/kafka
|
||||
|
||||
# bash /tmp/topic_create.sh
|
||||
Create a topic test by connecting to zookeeper
|
||||
Created topic test
|
||||
bin/kafka-topics.sh --create --zookeeper zookeeper:2181 --replication-factor 1 --partitions 1 --topic test
|
||||
Created topic test.
|
||||
|
||||
# bash /tmp/topic_list.sh
|
||||
List all topics at zookeeper
|
||||
bin/kafka-topics.sh --list --zookeeper zookeeper:2181
|
||||
test
|
||||
|
||||
# export KAFKA_HOST=kafka1
|
||||
# bash /tmp/msg_recv.sh
|
||||
Recving msg to topic test by connecting to kafka1
|
||||
bin/kafka-console-consumer.sh --bootstrap-server kafka1:9092 --topic test --from-beginning
|
||||
```
|
||||
|
||||
Now open a new shell to the cli container.
|
||||
|
||||
```bash
|
||||
# export KAFKA_HOST=kafka2
|
||||
# bash /tmp/msg_send.sh
|
||||
Send msg to topic test by connecting to kafka2
|
||||
bin/kafka-console-producer.sh --broker-list kafka2:9092 --topic test
|
||||
>msg_hello
|
||||
```
|
||||
|
||||
Check the recving msg shell to get that msg.
|
||||
|
||||
## Stop
|
||||
|
||||
```bash
|
||||
$ docker-compose down
|
||||
```
|
|
@ -0,0 +1,56 @@
|
|||
# The minimal kafka service
|
||||
# github.com/yeasy/docker-compose-files
|
||||
|
||||
# * zk: zk node for kafka, 0, 1, 2
|
||||
# * kafka: kafka service, will default to connect to zookeeper
|
||||
# * cli: client to test kafka service
|
||||
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
zookeeper1:
|
||||
image: yeasy/kafka:latest
|
||||
container_name: zookeeper1
|
||||
hostname: zookeeper1
|
||||
ports:
|
||||
- "2182:2181" # zk connection port
|
||||
environment:
|
||||
- ZK_ID=1 # when bootup, will read this and update the /tmp/zookeeper/myid file
|
||||
healthcheck:
|
||||
disable: true
|
||||
command: bash -c 'bash /tmp/start_zk.sh'
|
||||
|
||||
zookeeper2:
|
||||
image: yeasy/kafka:latest
|
||||
container_name: zookeeper2
|
||||
hostname: zookeeper2
|
||||
ports:
|
||||
- "2183:2181" # zk connection port
|
||||
environment:
|
||||
- ZK_ID=2 # when bootup, will read this and update the /tmp/zookeeper/myid file
|
||||
healthcheck:
|
||||
disable: true
|
||||
command: bash -c 'bash /tmp/start_zk.sh'
|
||||
|
||||
zookeeper3:
|
||||
image: yeasy/kafka:latest
|
||||
container_name: zookeeper3
|
||||
hostname: zookeeper3
|
||||
ports:
|
||||
- "2181:2181" # zk connection port
|
||||
environment:
|
||||
- ZK_ID=3 # when bootup, will read this and update the /tmp/zookeeper/myid file
|
||||
healthcheck:
|
||||
disable: true
|
||||
command: bash -c 'bash /tmp/start_zk.sh'
|
||||
|
||||
cli: # used for testing kafka cmds, see /tmp/*.sh
|
||||
image: yeasy/kafka:latest
|
||||
container_name: cli
|
||||
hostname: cli
|
||||
environment:
|
||||
- ZK_HOST=zookeeper1 # zk host to connect to
|
||||
# bash /opt/zookeeper/bin/zkCli.sh -server ${ZK_HOST}:2181
|
||||
healthcheck:
|
||||
disable: true
|
||||
command: bash -c 'while true; do sleep 20200116; done'
|
Loading…
Reference in New Issue