下载 Kafka
wget https://mirror-hk.koddos.net/apache/kafka/3.0.0/kafka_2.13-3.0.0.tgz
解压缩
tar xzf kafka_2.13-3.0.0.tgz
sudo mv kafka_2.13-3.0.0 /opt/kafka
修改配置
vi /opt/kafka/config/zookeeper.properties
clientPortAddress=192.168.50.15
vi /opt/kafka/config/server.properties
#listeners=PLAINTEXT://:9092
listeners=PLAINTEXT://192.168.50.15:9092
#zookeeper.connect=localhost:2181
zookeeper.connect=192.168.50.15:2181
起动 Kafka
/opt/kafka/bin/zookeeper-server-start.sh /opt/kafka/config/zookeeper.properties
/opt/kafka/bin/kafka-server-start.sh /opt/kafka/config/server.properties
一般使用
/opt/kafka/bin/kafka-topics.sh --list --bootstrap-server 192.168.50.15:9092
/opt/kafka/bin/kafka-topics.sh --create --topic test-topic --partitions 1 --replication-factor 1 --bootstrap-server 192.168.50.15:9092
注: topic 名字 不要使用 . 或 _
/opt/kafka/bin/kafka-topics.sh --describe --topic test-topic --bootstrap-server 192.168.50.15:9092
/opt/kafka/bin/kafka-topics.sh --list --bootstrap-server 192.168.50.15:9092
/opt/kafka/bin/kafka-console-consumer.sh --topic test-topic --from-beginning --bootstrap-server 192.168.50.15:9092
/opt/kafka/bin/kafka-console-producer.sh --topic test-topic --bootstrap-server 192.168.50.15:9092
test 1
test 2
/opt/kafka/bin/kafka-topics.sh --delete --topic test.topic --bootstrap-server 192.168.50.15:9092
/opt/kafka/bin/kafka-topics.sh --delete --topic __consumer_offsets --bootstrap-server 192.168.50.15:9092
停止 Kafka
/opt/kafka/bin/kafka-server-stop.sh
/opt/kafka/bin/zookeeper-server-stop.sh