我正在使用Docker启动一个kafka经纪人集群(例如,5个经纪人,每个集装箱一个经纪人)。 Kafka版本2.12-0.11.0.0,Zookeeper 3.4.10。
情景:
zoo.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
server.properties
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
producer.properties
bootstrap.servers=localhost:9092
compression.type=none
consumer.properties
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
zoo.cfg (只有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
在每个代理上重新启动zookeeper以使zoo.cfg
Zookeepers聚集到群集
主题已移至经纪人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
消息丢失(当主题停留在代理1上时,消息不会丢失,所以 这是浮动的情况)
答案 0 :(得分:0)
你有没有尝试将滴答时间提高到6000?根据Hadoop的设置,他们默认使用此设置,说明2000毫秒设置太低。我认为这同样适用。我现在正在处理一个非常相似的卡夫卡问题。
答案 1 :(得分:0)
在Kafka文档中,config description和config example都建议指定代理zookeeper.connect
中的所有Zookeeper服务器。同样在生产中,期望您运行一个单独的Zookeeper集群和一个单独的Kafka集群,而不是在一个docker容器中共同运行Kafka和ZK。
我想这样的事情可能会发生:
我不确定从单节点Zookeeper转移到复制设置的正确方法是什么,并且无法在文档中找到它。也许您最初必须为第一个ZK分配更多weight
,以便确保它成为领导者并在其他ZK节点上强制其主题配置。
您创建了JIRA问题吗?得到了开发人员的任何回应?