我能夠在一臺linux機器上本地獲得一個簡單的單節點Kafka(kafka_2.11-0.8.2.1),但是當我嘗試運行一名製作人遠程我收到一些令人困惑的錯誤。Kafka QuickStart,advertised.host.name給出了kafka.common.LeaderNotAvailableException
我按照http://kafka.apache.org/documentation.html#quickstart的快速入門指南。我停止了kafka進程,並刪除了/ tmp中的所有動物園管理員karma文件。我在本地網絡10.0.0.0/24 NAT-ED與外部的IP地址,所以我修改server.properties
告訴飼養員如何播放我的外部地址,按https://medium.com/@thedude_rog/running-kafka-in-a-hybrid-cloud-environment-17a8f3cfc284:
advertised.host.name=MY.EXTERNAL.IP
然後我跑這樣的:
$ bin/zookeeper-server-start.sh config/zookeeper.properties
--> ...
$ export KAFKA_HEAP_OPTS="-Xmx256M -Xms128M" # small test server!
$ bin/kafka-server-start.sh config/server.properties
--> ...
我打開了防火牆,我在遠程機器上生產,並創造了一個新的話題,並加以驗證:
$ bin/kafka-topics.sh --create --zookeeper MY.EXTERNAL.IP:2181 --replication-factor 1 --partitions 1 --topic test123
--> Created topic "test123".
$ bin/kafka-topics.sh --list --zookeeper MY.EXTERNAL.IP:2181
--> test123
但是,製片人我飛奔克遠程給我錯誤:
$ bin/kafka-console-producer.sh --broker-list MY.EXTERNAL.IP:9092 --topic test123
--> [2015-06-16 14:41:19,757] WARN Property topic is not valid (kafka.utils.VerifiableProperties)
My Test Message
--> [2015-06-16 14:42:43,347] WARN Error while fetching metadata [{TopicMetadata for topic test123 ->
無分區的元數據爲主題test123由於kafka.common.LeaderNotAvailableException}]爲主題[test123]:類kafka.common.LeaderNotAvailableException(kafka.producer.BrokerPartitionInfo) - >(反覆幾次)
(我禁用了整個防火牆,以確保沒有問題)
在卡瑪 - 啓動標準輸出錯誤重複:[2015-06-16 20:42:42,768] INFO Closing socket connection to /MY.EXTERNAL.IP. (kafka.network.Processor)
而controller.log給我這個,好幾次:
java.nio.channels.ClosedChannelException
at kafka.network.BlockingChannel.send(BlockingChannel.scala:100)
at kafka.controller.RequestSendThread.liftedTree1$1(ControllerChannelManager.scala:132)
at kafka.controller.RequestSendThread.doWork(ControllerChannelManager.scala:131)
at kafka.utils.ShutdownableThread.run(ShutdownableThread.scala:60)
[2015-06-16 20:44:08,128] INFO [Controller-0-to-broker-0-send-thread], Controller 0 connected to id:0,host:MY.EXTERNAL.IP,port:9092 for sending state change requests (kafka.controller.RequestSendThread)
[2015-06-16 20:44:08,428] WARN [Controller-0-to-broker-0-send-thread], Controller 0 epoch 1 fails to send request Name:LeaderAndIsrRequest;Version:0;Controller:0;ControllerEpoch:1;CorrelationId:7;ClientId:id_0-host_null-port_9092;Leaders:id:0,host:MY.EXTERNAL.IP,port:9092;PartitionState:(test123,0) -> (LeaderAndIsrInfo:(Leader:0,ISR:0,LeaderEpoch:0,ControllerEpoch:1),ReplicationFactor:1),AllReplicas:0) to broker id:0,host:MY.EXTERNAL.IP,port:9092. Reconnecting to broker. (kafka.controller.RequestSendThread)
運行,這似乎表明,處於0的領先者:
$ ./bin/kafka-topics.sh --zookeeper MY.EXTERNAL.IP:2181 --describe --topic test123
--> Topic:test123 PartitionCount:1 ReplicationFactor:1 Configs:
Topic: test123 Partition: 0 Leader: 0 Replicas: 0 Isr: 0
我重新這個測試我的server.log指示有0的領先者:
...
[2015-06-16 21:58:04,498] INFO 0 successfully elected as leader (kafka.server.ZookeeperLeaderElector)
[2015-06-16 21:58:04,642] INFO Registered broker 0 at path /brokers/ids/0 with address MY.EXTERNAL.IP:9092. (kafka.utils.ZkUtils$)
[2015-06-16 21:58:04,670] INFO [Kafka Server 0], started (kafka.server.KafkaServer)
[2015-06-16 21:58:04,736] INFO New leader is 0 (kafka.server.ZookeeperLeaderElector$LeaderChangeListener)
我看到在日誌這個錯誤,當我從生產者發送消息:
[2015-06-16 22:18:24,584] ERROR [KafkaApi-0] error when handling request Name: TopicMetadataRequest; Version: 0; CorrelationId: 7; ClientId: console-producer; Topics: test123 (kafka.server.KafkaApis)
kafka.admin.AdminOperationException: replication factor: 1 larger than available brokers: 0
at kafka.admin.AdminUtils$.assignReplicasToBrokers(AdminUtils.scala:70)
我認爲這意味着經紀人不能出於某種原因?我很困惑這意味着什麼......
我以前有過這個。我們在我們的主題上設置了複製因子3,並且有3個經紀人,但是我們的一個經紀人沒有工作,因爲我們不小心給了它與其他經紀人相同的經紀人ID。我們更改了經紀人ID並重新啓動,這解決了問題。 –
@JonHunter這很奇怪,因爲我只有一個經紀人和一個主題。我在昨晚的EC2上設置了相同的方式,看看它是否與我的託管設置有關,但我也有同樣的錯誤。 – mikebridge
您可以嘗試更改您的經紀人ID。我之前沒有使用過0的代理ID(即使Kafka文檔說可以)。您也可以使用Zookeeper客戶端「zkCli.sh」,它將向您顯示哪些代理已在Zookeeper中註冊(它允許您瀏覽Zookeeper znode結構)。 –