赞
踩
由于只有一台机器,于是只能通过启动3个端口,进而启动3个broker
# server.properties
broker.id=0
listeners=PLAINTEXT://:9092
log.dirs=/usr/local/var/lib/kafka-logs
# server1.properties
broker.id=1
listeners=PLAINTEXT://:9093
log.dirs=/usr/local/var/lib/kafka-logs-1
# server2.properties
broker.id=2
listeners=PLAINTEXT://:9094
log.dirs=/usr/local/var/lib/kafka-logs-2
# 启动 zk
zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties &
# 启动 broker0
kafka-server-start /usr/local/etc/kafka/server.properties &
# 启动 broker1
kafka-server-start /usr/local/etc/kafka/server-1.properties &
# 启动 broker2
kafka-server-start /usr/local/etc/kafka/server-2.properties &
kafka-topics --create --zookeeper localhost:2181 --replication-factor 3 --partitions 1 --topic testCluster
kafka-topics --describe --zookeeper localhost:2181 --topic testCluster
$ kafka-topics --describe --zookeeper localhost:2181 --topic testCluster
Topic:testCluster PartitionCount:1 ReplicationFactor:3 Configs:
Topic: testCluster Partition: 0 Leader: 2 Replicas: 2,1,0 Isr: 2,1,0
PartitionCount:分区数量1
ReplicationFactor: 副本复制因子3,也就是有3个副本
Partition: 分区下标
Leader:分区leader 位于第二个broker上
Replicas:有3个副本2,1,0 ,从副本只进行数据的同步复制
Isr:In-Sync Replica 同步的副本,表明3个副本都是同步副本,也就是在broker奔溃的时候,能上位。
ps -ef | grep kafka
kill -9 进程号
$ kafka-topics --describe --zookeeper localhost:2181 --topic testCluster
Topic:testCluster PartitionCount:1 ReplicationFactor:3 Configs:
Topic: testCluster Partition: 0 Leader: 1 Replicas: 2,1,0 Isr: 1,0
对比上方可以知道,Leader目前变成了1,ISR也即是同步状态的副本,只有1跟0这俩副本。
[2020-07-23 19:48:20,126] WARN [Consumer clientId=consumer-1, groupId=console-consumer-29596] Connection to node 2 (localhost/127.0.0.1:9094) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
kafka-server-start /usr/local/etc/kafka/server-2.properties &
$ kafka-topics --describe --zookeeper localhost:2181 --topic testCluster
Topic:testCluster PartitionCount:1 ReplicationFactor:3 Configs:
Topic: testCluster Partition: 0 Leader: 1 Replicas: 2,1,0 Isr: 1,0,2
可以看到,重新启动后,Leader依旧还是1,ISR(In-Sync-Replica)同步副本已经出现了2,说明目前3个副本都是同步的。
从文件 /usr/local/etc/kafka/server.properties 内容中,可以看到,消息的保存路径是在:
log.dirs=/usr/local/var/lib/kafka-logs
kafka-console-producer --broker-list localhost:9092 --topic testCluster
kafka-console-consumer --bootstrap-server localhost:9092 --topic testCluster --from-beginning
下一章节:【Kafka】消费者组 Consumer Group(三)
上一章节:【Kafka】MacOS入门安装使用 (一)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。