docker 搭建kafka集群

搭建zookeeper:

docker run -d -p 2181:2181 -v /mysoft/zookeeper/data/:/data/ --name=zookeeper  --privileged xqkang/zookeeper:v1

46节点

sysuser@qj-pred-pub135:/qj/kafka1$ cat run.sh 
#!/bin/bash

zks="192.168.10.46:2181,192.168.10.150:2181,192.168.10.207:2181"
docker run -p 9092:9092 --name kafka1 --network host -d \
  -e KAFKA_BROKER_ID=1 \
  -e KAFKA_ZOOKEEPER_CONNECT=${zks} \
  -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.10.46:9092 \
  -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 \
  -v /qj/kafka/log:/kafka \
  --restart=always \
  xqkang/kafka:2.12-2.2.2

150节点

sysuser@qj-pred-pub99:/qj/kafka2$ cat run.sh 
#!/bin/bash

zks="192.168.10.46:2181,192.168.10.150:2181,192.168.10.207:2181"
docker run -p 9092:9092 --name kafka2 --network host -d \
  -e KAFKA_BROKER_ID=2 \
  -e KAFKA_ZOOKEEPER_CONNECT=${zks} \
  -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.10.150:9092 \
  -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 \
  -v /qj/kafka/log:/kafka \
  --restart=always \
  xqkang/kafka:2.12-2.2.2

207节点

sysuser@qj-pred-pub123:/qj/kafka3$ cat run.sh 
#!/bin/bash

zks="192.168.10.46:2181,192.168.10.150:2181,192.168.10.207:2181"
docker run -p 9092:9092 --name kafka2 --network host -d \
  -e KAFKA_BROKER_ID=3 \
  -e KAFKA_ZOOKEEPER_CONNECT=${zks} \
  -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.10.207:9092 \
  -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 \
  -v /qj/kafka/log:/kafka \
  --restart=always \
xqkang/kafka:2.12-2.2.2

创建topic和生产者:

docker exec -it kafka bash
cd /opt/kafka_2.12-2.2.2/bin/
./kafka-topics.sh --create --zookeeper 192.168.10.46:2181 --replication-factor 1 --partitions 8 --topic test
./kafka-console-producer.sh --broker-list localhost:9092 --topic test

创建消费者:

docker exec -it kafka bash
cd /opt/kafka_2.11-2.0.0/bin/
./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning

参考:https://www.jianshu.com/p/cec64efdf1e0

删除topic
查看复制打印?

[root@namenode1 kafka]# bin/kafka-run-class.sh kafka.admin.TopicCommand --delete --topic track_pc --zookeeper namenode1:2181,namenode2:2181,datanode1:2181 

你可能感兴趣的:(kafka)