kafka集群安装

一、搭建三个节点的zookeeper集群:参考之前写的博客:https://www.cnblogs.com/yangxiaohui227/p/17535507.html

 我搭完后,zookeeper三个节点的ip地址是:192.168.233.11:2182,192.168.233.11:2183,192.168.233.11:2184

二、搭建三个节点的kafka集群:要做的是,改成自己的zookeeper的集群地址以及KAFKA_ADVERTISED_LISTENERS要改成自己的IP

docker run -d --name kafka0 -p 9092:9092 -e KAFKA_BROKER_ID=0 -e KAFKA_ZOOKEEPER_CONNECT=192.168.233.11:2182,192.168.233.11:2183,192.168.233.11:2184 -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.233.11:9092 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 -t wurstmeister/kafka
docker run -d --name kafka1 -p 9093:9093 -e KAFKA_BROKER_ID=1 -e KAFKA_ZOOKEEPER_CONNECT=192.168.233.11:2182,192.168.233.11:2183,192.168.233.11:2184 -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.233.11:9093 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9093 -t wurstmeister/kafka
docker run -d --name kafka2 -p 9094:9094 -e KAFKA_BROKER_ID=2 -e KAFKA_ZOOKEEPER_CONNECT= 192.168.233.11:2182,192.168.233.11:2183,192.168.233.11:2184 -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.233.11:9094 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9094 -t wurstmeister/kafka

 三、创建kafka可视化监控平台(需要修改成自己的zookeeper集群地址)

docker run -d --name kafka-manager  -p 9000:9000 -e ZK_HOSTS=192.168.233.11:2182,192.168.233.11:2183,192.168.233.11:2184 sheepkiller/kafka-manager

 四、登录监控平台:http://ip:9000

 

 第五:zookeeper监控平台: prettyZoo-win 下载地址:https://github.com/vran-dev/PrettyZoo/releases

 

 

 六、kafka官方中文文档: https://kafka.apachecn.org/documentation.html

七、操作命令 进入kafka容器

1.进入容器

docker exec -it kafka1 /bin/bash
cd opt/kafka

 2. 创建topic 3个分区 2个副本

bin/kafka-topics.sh --create --zookeeper 192.168.233.11:2182,192.168.233.11:2183,192.168.233.11:2184 --replication-factor 2 --partitions 3 --topic shop-topic

3. 创建消费者进行监听

 bin/kafka-console-consumer.sh --bootstrap-server 192.168.233.11:9092,192.168.233.11:9093,192.168.233.11:9094 --topic shop-topic   --group my-group    --from-beginning

4. 新窗口登录kafka2进行发送消息

bin/kafka-console-producer.sh --broker-list 192.168.233.11:9092,192.168.233.11:9093,192.168.233.11:9094 --topic shop-topic

 5. 查询消费者组当前消费到的offset

 bin/kafka-consumer-groups.sh --describe  --bootstrap-server 192.168.233.11:9092,192.168.233.11:9093,192.168.233.11:9094 --group my-group

 

posted @ 2023-07-12 11:18  yangxiaohui227  阅读(22)  评论(0编辑  收藏  举报