安装

运行

zk集群

1
# 安装zk集群

broker

1
2
3
4
# kafka在启动服务之前必须要设定3个参数:broker.id、log.dirs、zookeeper.connect
broker.id=10
log.dirs=/opt/kafka/data/
zookeeper.connect=n183:2181,n184:2181,n185:2181
1
./kafka-server-start.sh -daemon ../config/server.properties
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
[2019-04-08 20:43:53,886] INFO Registered kafka:type=kafka.Log4jController MBean (kafka.utils.Log4jControllerRegistration$)
[2019-04-08 20:43:54,327] ERROR Exiting Kafka due to fatal exception (kafka.Kafka$)
java.lang.IllegalArgumentException: requirement failed: broker.id must be equal or greater than -1 and not greater than reserved.broker.max.id
	at scala.Predef$.require(Predef.scala:281)
	at kafka.server.KafkaConfig.validateValues(KafkaConfig.scala:1441)
	at kafka.server.KafkaConfig.<init>(KafkaConfig.scala:1437)
	at kafka.server.KafkaConfig.<init>(KafkaConfig.scala:1097)
	at kafka.server.KafkaConfig$.fromProps(KafkaConfig.scala:1077)
	at kafka.server.KafkaServerStartable$.fromProps(KafkaServerStartable.scala:28)
	at kafka.Kafka$.main(Kafka.scala:59)
	at kafka.Kafka.main(Kafka.scala)


[2019-04-08 20:44:44,579] INFO Cluster ID = NPj6E5Z9Tceeiyi6Etpo5Q (kafka.server.KafkaServer)
[2019-04-08 20:44:44,584] ERROR Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer)
kafka.common.InconsistentBrokerIdException: Configured broker.id 10 doesn't match stored broker.id 0 in meta.properties. If you moved your data, make sure your configured broker.id matches. If you intend to create a new broker, you should remove all data in your data directories (log.dirs).
	at kafka.server.KafkaServer.getBrokerIdAndOfflineDirs(KafkaServer.scala:710)
	at kafka.server.KafkaServer.startup(KafkaServer.scala:212)
	at kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:38)
	at kafka.Kafka$.main(Kafka.scala:75)
	at kafka.Kafka.main(Kafka.scala)
1
2
3
4
./bin/kafka-topics.sh --create --zookeeper n183:2181 --replication-factor 1 --partitions 1 --topic test
./bin/kafka-topics.sh --list --zookeeper n183:2181
./bin/kafka-console-producer.sh --broker-list n199:9092 --topic test
./bin/kafka-console-consumer.sh --bootstrap-server n199:9092--topic test --from-beginning

kafka

structured streaming

es