$ bin/kafka-server-start.sh config/server.properties
创建 1个分区 1个备份 名为 "custom-topic-name" 的主题,并同步到 Zookeeper(localhost:2181)
$ bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1
--partitions 1 --topic custom-topic-name
$ bin/kafka-topics.sh --list --zookeeper localhost:2181
Kafka 自带终端控制指令,可在命令行向 Kafka 主题发送消息
$ bin/kafka-console-producer.sh --broker-list localhost:9092 --topic custom-topic-name
...
hello world
Kafka 自带终端控制指令,可在命令行打印主题内的新消息
bin/kafka-console-consumer.sh --zookeeper localhost:2181 —topic custom-topic-name
--from-beginning
...
hello world
复制 server.properties 到两个新文件 [server-one.properties, server-two.properties]
config / server-one.properties
# The id of the broker. This must be set to a unique integer for each broker.
broker.id=1
# The port the socket server listens on
port=9093
# A comma seperated list of directories under which to store log files
log.dirs=/tmp/kafka-logs-1
config / server-two.properties
# The id of the broker. This must be set to a unique integer for each broker.
broker.id=2
# The port the socket server listens on
port=9094
# A comma seperated list of directories under which to store log files
log.dirs=/tmp/kafka-logs-2
在每台机器(节点)上分别启动
bin/kafka-server-start.sh config/server.properties
bin/kafka-server-start.sh config/server-one.properties
bin/kafka-server-start.sh config/server-two.properties
--replication-factor 3, 3 = 代理数
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 -partitions 1 --topic custom-multi-broker-topic-name
bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic custom-multi-broker-topic-name
bin/kafka-topics.sh —zookeeper localhost:2181 --alter --topic custom-topic-name --partitions (count)
bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic custom-topic-name