kafka集群搭建

已有zookeeper集群,zookeeper地址:192.168.220.127:2181,192.168.220.123:2181,192.168.220.206:2181

在docker上下载kafka wurstmeister/kafka:latest
服务器
192.168.220.123 kafka01
192.168.220.127 kafka02
192.168.220.206 kafka03

KAFKA_BROKER_ID分别为1、2、3,指定各自的ip。
如:
docker run –restart=always -d -ti –name kafka03
–hostname 192.168.220.123
-e KAFKA_HOST_NAME=localhost
-e KAFKA_PORT=9092
-e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092
-e KAFKA_ADVERTISED_PORT=9092 -e KAFKA_DEFAULT_REPLICATION_FACTOR=2
-e KAFKA_ADVERTISED_HOST_NAME=192.168.220.123
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.220.123:9092
-e KAFKA_BROKER_ID=1
-e KAFKA_ZOOKEEPER_CONNECT=”192.168.220.127:2181,192.168.220.123:2181,192.168.220.206:2181″
-p 9092:9092
-t wurstmeister/kafka:latest

测试kafka集群
./kafka-topics.sh --create --zookeeper 192.168.220.127:2181,192.168.220.123:2181,192.168.220.206:2181 --replication-factor 2 --partitions 2 --topic testlixr2
Created topic “testlixr2”.
./kafka-topics.sh --describe --zookeeper 192.168.220.127:2181,192.168.220.123:2181,192.168.220.206:2181 --topic testlixr2

Topic:testlixr2 PartitionCount:2 ReplicationFactor:2 Configs:
Topic: testlixr2 Partition: 0 Leader: 2 Replicas: 2,3 Isr: 2,3
Topic: testlixr2 Partition: 1 Leader: 3 Replicas: 3,2 Isr: 3,2

./kafka-console-producer.sh --broker-list 192.168.220.127:9092 --topic testlixr2
输入测试数据
testkafka

在另外服务器上

./kafka-console-consumer.sh --zookeeper 192.168.220.127:2181,192.168.220.123:2181 --topic testlixr2 --from-beginning
会看到 testkafka

现在看到的配置很简单,但得到这个配置的过程不简单,几乎是每个配置项都出错过,但因为知道集群就这么些配置,一个个试下来,总归是OK啦,给自己一个鼓励。

    原文作者:灼灼2015
    原文地址: https://www.jianshu.com/p/93f33dfefdb2
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞