Kafka 集群的安装、配置和常用指令

配置 zookeeper

Kafka 运行依赖 zookeeper:zookeeper 集群配置

下载解压

地址
选择:kafka_2.11-2.3.0.tgz

更改配置

分别更改三台机器上的 config/server.properties
其中,broker.id 需要更改,其它的直接粘贴上去就行。

broker0:

broker.id=0
listeners=PLAINTEXT://192.168.100.14:9092
advertised.listeners=PLAINTEXT://192.168.100.14:9092
zookeeper.connect=192.168.100.14:2181,192.168.100.15:2181,192.168.100.16:2181
delete.topic.enable=true

broker1:

broker.id=1
listeners=PLAINTEXT://192.168.100.15:9092
advertised.listeners=PLAINTEXT://192.168.100.15:9092
zookeeper.connect=192.168.100.14:2181,192.168.100.15:2181,192.168.100.16:2181
delete.topic.enable=true

broker2:

broker.id=2
listeners=PLAINTEXT://192.168.100.16:9092
advertised.listeners=PLAINTEXT://192.168.100.16:9092
zookeeper.connect=192.168.100.14:2181,192.168.100.15:2181,192.168.100.16:2181
delete.topic.enable=true

不要用 hostname 替代 listeners 和 advertised.listeners 里的 ip 地址。否则,可能会导致 Java 里的 consumer 收不到消息。
zookeeper.connect 里的 ip 地址可以用 hostname 替换

启动

kafka 目录下:
bin/kafka-server-start.sh config/server.properties

创建主题

启动了才能创建:
bin/kafka-topics.sh --create --zookeeper hadoop004:2181, hadoop005:2181, hadoop006:2181 --replication-factor 1 --partitions 4 --topic hello-topic

查看主题

bin/kafka-topics.sh --zookeeper hadoop004:2181, hadoop005:2181, hadoop006:2181 --describe --topic hello-topic

修改主题

bin/kafka-topics.sh --zookeeper hadoop004:2181, hadoop005:2181, hadoop006:2181 -alter --partitions 4 --topic hello-topic

删除主题

bin/kafka-topics.sh --delete --zookeeper hadoop004:2181, hadoop005:2181, hadoop006:2181 --topic hello-topic

列出所有主题

bin/kafka-topics.sh --zookeeper hadoop004:2181, hadoop005:2181, hadoop006:2181 --list

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 岁月 设计师:pinMode 返回首页