0%

kafka集群docker部署

# node1
docker run -d --name kafka --net host --restart always \
  -e KAFKA_CFG_ZOOKEEPER_CONNECT=192.168.3.17:2181,192.168.3.19:2181,192.168.3.20:2181 \
  -e KAFKA_BROKER_ID=1 \
  -e KAFKA_CFG_LISTENERS=PLAINTEXT://192.168.3.17:9092 \
  -e KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://192.168.3.17:9092 \
  -e ALLOW_PLAINTEXT_LISTENER=yes \
  -e KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=true \
  -v /root/kafka:/bitnami/kafka \
  bitnami/kafka:2.8.0

# node2
docker run -d --name kafka --net host --restart always \
  -e KAFKA_CFG_ZOOKEEPER_CONNECT=192.168.3.17:2181,192.168.3.19:2181,192.168.3.20:2181 \
  -e KAFKA_BROKER_ID=2 \
  -e KAFKA_CFG_LISTENERS=PLAINTEXT://192.168.3.19:9092 \
  -e KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://192.168.3.19:9092 \
  -e ALLOW_PLAINTEXT_LISTENER=yes \
  -e KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=true \
  -v /root/kafka:/bitnami/kafka \
  bitnami/kafka:2.8.0

# node3
docker run -d --name kafka --net host --restart always \
  -e KAFKA_CFG_ZOOKEEPER_CONNECT=192.168.3.17:2181,192.168.3.19:2181,192.168.3.20:2181 \
  -e KAFKA_BROKER_ID=3 \
  -e KAFKA_CFG_LISTENERS=PLAINTEXT://192.168.3.20:9092 \
  -e KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://192.168.3.20:9092 \
  -e ALLOW_PLAINTEXT_LISTENER=yes \
  -e KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=true \
  -v /root/kafka:/bitnami/kafka \
  bitnami/kafka:2.8.0

# 2种ui
docker run -d -p 18080:8889 --name ui freakchicken/kafka-ui-lite
docker run -d -p 9000:9000 --name ui -e ZK_HOSTS=192.168.3.17:2181,192.168.3.19:2181,192.168.3.20:2181 solsson/kafka-manager

# 测试命令
./kafka-topics.sh --create --zookeeper 192.168.3.17:2181,192.168.3.19:2181,192.168.3.20:2181 --replication-factor 1 --partitions 1 --topic first_kafka

./kafka-console-producer.sh --broker-list 192.168.3.17:9092,192.168.3.19:9092,192.168.3.20:9092 --topic first_kafka

./kafka-console-consumer.sh --bootstrap-server 192.168.3.17:9092,192.168.3.19:9092,192.168.3.20:9092 --topic first_kafka --from-beginning

./kafka-topics.sh --describe --zookeeper 192.168.3.17:2181,192.168.3.19:2181,192.168.3.20:2181 --topic first_kafka

./kafka-topics.sh --list --zookeeper 192.168.3.17:2181,192.168.3.19:2181,192.168.3.20:2181

./kafka-topics.sh --delete --zookeeper 192.168.3.17:2181,192.168.3.19:2181,192.168.3.20:2181 --topic first_kafka