Kafka之——replication factor: 1 larger than available brokers: 0 問題解決方案
一、問題
用kfafka命令:./kafka-server-start.sh ../config/server.properties &啟動時報以下錯誤:
[2018-01-28 21:54:44,745] ERROR [KafkaApi-100] error when handling request Name: TopicMetadataRequest; Version: 0; CorrelationId: 1496; ClientId: producer-1; Topics: Interation,Booksheet (kafka.server.KafkaApis) kafka.admin.AdminOperationException: replication factor: 1 larger than available brokers: 0 at kafka.admin.AdminUtils$.assignReplicasToBrokers(AdminUtils.scala:70) at kafka.admin.AdminUtils$.createTopic(AdminUtils.scala:155) at kafka.server.KafkaApis anonfun$handleTopicMetadataRequest$2.apply(KafkaApis.scala:618)atkafka.server.KafkaApis anonfun$handleTopicMetadataRequest$2.apply(KafkaApis.scala:612) at scala.collection.immutable.Set$Set2.foreach(Set.scala:106) at kafka.server.KafkaApis.handleTopicMetadataRequest(KafkaApis.scala:612) at kafka.server.KafkaApis.handle(KafkaApis.scala:71) at kafka.server.KafkaRequestHandler.run(KafkaRequestHandler.scala:42) at java.lang.Thread.run(Thread.java:662)
二、解決方案
解決辦法是:
複製kafka/config路徑下的server.properties檔案為:server-1.properties和server-2.properties
並修改這三個檔案的配置項:
broker.id、port、log.dir在這三個配置項中都不一樣。server.properties broker.id=0 port=9092 log.dir=/tmp/kafka-logs-0 host.name=localhost server-1.properties broker.id=1 port=9093 log.dir=/tmp/kafka-logs-1 host.name=localhost server-2.properties broker.id=2 port=9094 log.dir=/tmp/kafka-logs-2 host.name=localhost
修改完成之後啟動:
nohup ./kafka-server-start.sh ../config/server.properties &
nohup ./kafka-server-start.sh ../config/server-1.properties &
nohup ./kafka-server-start.sh ../config/server-2.properties &
前一個啟動可能還會報這個錯,繼續啟動,都啟動成功之後這個問題就解決了!