美文网首页
Kafka单节点多broker配置

Kafka单节点多broker配置

作者: 喵星人ZC | 来源:发表于2020-04-27 23:18 被阅读0次

将Kafka的家目录中的config/server.properties复制两份


image.png

三文件分别配置如下
server.properties

broker.id=0
listeners=PLAINTEXT://localhost:9092
log.dirs=/home/hadoop/app/kafka_2.11-0.10.1.0/data/kafka-logs
zookeeper.connect=localhost:2181/kafka

server1.properties

broker.id=1
listeners=PLAINTEXT://localhost:9093
log.dirs=/home/hadoop/app/kafka_2.11-0.10.1.0/data/kafka1-logs
zookeeper.connect=localhost:2181/kafka

server2.properties

broker.id=2
listeners=PLAINTEXT://localhost:9094
log.dirs=/home/hadoop/app/kafka_2.11-0.10.1.0/data/kafka2-logs
zookeeper.connect=localhost:2181/kafka

启动Kafka

nohup kafka-server-start.sh /home/hadoop/app/kafka_2.11-0.10.1.0/config/server.properties > $KAFKA_HOME/logs/nohub-0.log 2>&1 &

nohup kafka-server-start.sh /home/hadoop/app/kafka_2.11-0.10.1.0/config/server1.properties > $KAFKA_HOME/logs/nohub-1.log 2>&1 &

nohup kafka-server-start.sh /home/hadoop/app/kafka_2.11-0.10.1.0/config/server2.properties > $KAFKA_HOME/logs/nohub-2.log 2>&1 &

创建3分区3副本的topic

kafka-topics.sh --create --zookeeper localhost:2181/kafka --replication-factor 3 --partitions 3 --topic offset_test

查看topic

 kafka-topics.sh --list --zookeeper localhost:2181/kafka

启动生产者

kafka-console-producer.sh --broker-list localhost:9092,localhost:9093,localhost:9094 --topic offset_test

启动消费者

kafka-console-consumer.sh --zookeeper localhost:2181/kafka --topic offset_test --from-beginning
或者
kafka-console-consumer.sh --bootstrap-server localhost:9092,localhost:9093,localhost:9094 --topic offset_test --from-beginning

查看topic描述

kafka-topics.sh --describe --zookeeper localhost:2181/kafka --topic offset_test
image.png

相关文章

网友评论

      本文标题:Kafka单节点多broker配置

      本文链接:https://www.haomeiwen.com/subject/ooipwhtx.html