我正在使用 Docker 启动一个 kafka 代理集群(例如,5 个代理,每个容器一个代理)。Kafka 版本 2.12-0.11.0.0,Zookeeper 3.4.10。
场景:
- 使用以下配置启动第一个代理
动物园.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/opt/zookeeper/data
clientPort=2181
maxClientCnxns=10
minSessionTimeout=4000
maxSessionTimeout=1000000
server.1=0.0.0.0:2888:3888
服务器属性
broker.id=1
listeners=PLAINTEXT://:9092
advertised.listeners=PLAINTEXT://broker1_IP:broker1_PORT
num.network.threads=3
num.io.threads=8
socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
log.dirs=/tmp/kafka-logs
num.partitions=1
num.recovery.threads.per.data.dir=1
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1
log.retention.hours=168
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
zookeeper.connect=127.0.0.1:2181
zookeeper.session.timeout.ms=6000
zookeeper.connection.timeout.ms=1000000
group.initial.rebalance.delay.ms=0
生产者属性
bootstrap.servers=localhost:9092
compression.type=none
消费者属性
zookeeper.connect=127.0.0.1:2181
zookeeper.session.timeout.ms=6000
zookeeper.connection.timeout.ms=1000000
group.id=test-consumer-group
Zookeeper 以独立模式启动,然后启动 kafka
创建主题
/opt/kafka/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic my-test-topic1
- 发送消息
echo "test_kafka1" | /opt/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic my-test-topic1
- 检查消息
/opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --from-beginning --topic my-test-topic1 --max-messages 1
收到消息
- 描述主题
/opt/kafka/bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic my-test-topic1
Topic:my-test-topic1 PartitionCount:1 ReplicationFactor:1 Configs:
Topic: my-test-topic1 Partition: 0 Leader: 1 Replicas: 1 Isr: 1
- 开始休息 4 个经纪人
zoo.cfg从第 1 到第 5 的每个经纪人(只有 0.0.0.0:2888:3888 位置不同)
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/opt/zookeeper/data
clientPort=2181
maxClientCnxns=10
minSessionTimeout=4000
maxSessionTimeout=1000000
server.1=0.0.0.0:2888:3888
server.2=broker2_IP:broker2_2888:broker2_3888
server.3=broker3_IP:broker3_2888:broker3_3888
server.4=broker4_IP:broker4_2888:broker4_3888
server.5=broker5_IP:broker5_2888:broker5_3888
从第 1 个到第 5 个代理上的server.properties(broker.id 是唯一的,broker_IP:broker_PORT 对于 ech 代理不同)
broker.id=N
listeners=PLAINTEXT://:9092
advertised.listeners=PLAINTEXT://broker_IP:broker_PORT
num.network.threads=3
num.io.threads=8
socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
log.dirs=/tmp/kafka-logs
num.partitions=1
num.recovery.threads.per.data.dir=1
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1
log.retention.hours=168
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
zookeeper.connect=127.0.0.1:2181
zookeeper.session.timeout.ms=6000
zookeeper.connection.timeout.ms=1000000
group.initial.rebalance.delay.ms=0
从第 1 到第 5 的每个经纪人的producer.properties
bootstrap.servers=localhost:9092
compression.type=none
从第 1 到第 5 的每个经纪人的consumer.properties
zookeeper.connect=127.0.0.1:2181
zookeeper.session.timeout.ms=6000
zookeeper.connection.timeout.ms=1000000
group.id=test-consumer-group
重启每个broker上的zookeeper使zoo.cfg生效
动物园管理员聚集成集群
话题转移到经纪人 5
/opt/kafka/bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic my-test-topic1
Topic:my-test-topic1 PartitionCount:1 ReplicationFactor:1 Configs:
Topic: my-test-topic1 Partition: 0 Leader: 5 Replicas: 5 Isr: 5
这是正常行为吗?还是应该留在经纪人 1 上?
- 检查每个代理上的消息
/opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --from-beginning --topic my-test-topic1 --max-messages 1
消息丢失(topic停留在broker 1时消息不丢失,为浮动情况)