docker部署kafka

文章目录

  • 1.创建docker 网卡(docker0 172.17.0.1)
    • 1.部署节点1
    • 2.部署节点2
    • 3.部署节点3
    • 4.查看效果
  • 2.部署kafka集群
    • 1.部署节点1
    • 2.部署节点2
    • 3.部署节点3
    • 4.查看效果


1.创建docker 网卡(docker0 172.17.0.1)

docker network create kafka-zk --subnet 172.18.0.1/16

1.部署节点1

docker run \
-d \
--name kafka-zk01 \
-p 2181:2181 \
-p 2888:2881 \
-p 3888:3888 \
--network=kafka-zk \
--restart=always \
--hostname=zook1 \
--ip=172.18.0.2 \
-v /home/config/ess/kafka-zk/zk1/conf:/opt/zookeeper-3.4.13/conf \
-v /home/config/ess/kafka-zk/zk1/data:/opt/zookeeper-3.4.13/data \
-e ZOO_MY_ID=1 \
-e ZOO_SERVERS="server.1=zook1:2888:3888;2181 server.2=zook2:2888:3888;2181 server.3=zook3:2888:3888;2181" \
zookeeper:latest

2.部署节点2

docker run \
-d \
--name kafka-zk02 \
-p 2182:2181 \
-p 2889:2881 \
-p 3889:3888 \
--network=kafka-zk \
--restart=always \
--hostname=zook2 \
--ip=172.18.0.3 \
-v /home/config/ess/kafka-zk/zk2/conf:/opt/zookeeper-3.4.13/conf \
-v /home/config/ess/kafka-zk/zk2/data:/opt/zookeeper-3.4.13/data \
-e ZOO_MY_ID=2 \
-e ZOO_SERVERS="server.1=zook1:2888:3888;2181 server.2=zook2:2888:3888;2181 server.3=zook3:2888:3888;2181" \
zookeeper:latest

3.部署节点3

docker run \
-d \
--name kafka-zk03 \
-p 2183:2181 \
-p 2890:2881 \
-p 3890:3888 \
--network=kafka-zk \
--restart=always \
--hostname=zook3 \
--ip=172.18.0.4 \
-v /home/config/ess/kafka-zk/zk3/conf:/opt/zookeeper-3.4.13/conf \
-v /home/config/ess/kafka-zk/zk3/data:/opt/zookeeper-3.4.13/data \
-e ZOO_MY_ID=3 \
-e ZOO_SERVERS="server.1=zook1:2888:3888;2181 server.2=zook2:2888:3888;2181 server.3=zook3:2888:3888;2181" \
zookeeper:latest

4.查看效果

[root@VM-24-3-centos ~]# docker exec -it kafka-zk01 /bin/sh
# cd bin
# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower

2.部署kafka集群

1.部署节点1

docker run \
-d \
--name kafka-01 \
--network=kafka-zk \
--restart=always \
--hostname=kafka-01 \
--ip=172.18.0.5 \
-p 9093:9093 \
-p 9193:9193 \
-e KAFKA_BROKER_ID=1 \
-e KAFKA_ZOOKEEPER_CONNECT="172.18.0.2:2181,172.18.0.3:2181,172.18.0.4:2181" \
-e SKAFKA_ADVERTISED_LISTENERS=INSIDE://kafka-01:9093,OUTSIDE://localhost:9193 \
-e KAFKA_LISTENERS=INSIDE://:9093,OUTSIDE://:9193 \
-e KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT \
-e KAFKA_INTER_BROKER_LISTENER_NAME=INSIDE \
-e KAFKA_HEAP_OPTS="-Xmx256M -Xms256M" \
-e ALLOW_PLAINTEXT_LISTENER='yes' \
#-e JMX_PORT=9999 \
-t wurstmeister/kafka:latest

2.部署节点2

docker run \
-d \
--name kafka-02 \
--network=kafka-zk \
--restart=always \
--hostname=kafka-02 \
--ip=172.18.0.6 \
-p 9094:9093 \
-p 9194:9193 \
-e KAFKA_BROKER_ID=2 \
-e KAFKA_ZOOKEEPER_CONNECT="172.18.0.2:2181,172.18.0.3:2181,172.18.0.4:2181" \
-e SKAFKA_ADVERTISED_LISTENERS=INSIDE://kafka-02:9093,OUTSIDE://localhost:9193 \
-e KAFKA_LISTENERS=INSIDE://:9093,OUTSIDE://:9193 \
-e KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT \
-e KAFKA_INTER_BROKER_LISTENER_NAME=INSIDE \
-e KAFKA_HEAP_OPTS="-Xmx256M -Xms256M" \
-e ALLOW_PLAINTEXT_LISTENER='yes' \
#-e JMX_PORT=9999 \
-t wurstmeister/kafka:latest

3.部署节点3

docker run \
-d \
--name kafka-03 \
--network=kafka-zk \
--restart=always \
--hostname=kafka-03 \
--ip=172.18.0.7 \
-p 9095:9093 \
-p 9195:9193 \
-e KAFKA_BROKER_ID=3 \
-e KAFKA_ZOOKEEPER_CONNECT="172.18.0.2:2181,172.18.0.3:2181,172.18.0.4:2181" \
-e SKAFKA_ADVERTISED_LISTENERS=INSIDE://kafka-03:9093,OUTSIDE://localhost:9193 \
-e KAFKA_LISTENERS=INSIDE://:9093,OUTSIDE://:9193 \
-e KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT \
-e KAFKA_INTER_BROKER_LISTENER_NAME=INSIDE \
-e KAFKA_HEAP_OPTS="-Xmx256M -Xms256M" \
-e ALLOW_PLAINTEXT_LISTENER='yes' \
#-e JMX_PORT=9999 \
-t wurstmeister/kafka:latest

4.查看效果

进入容器在Broker 1上创建一个副本为3、分区为5的topic用于测试

kafka-topics.sh --create --zookeeper 172.18.0.2:2181 --replication-factor 3 --partitions 5 --topic TestTopic

切换其他kafka broker查看TestTopic详情
在这里插入图片描述

你可能感兴趣的:(go,go)