环境介绍
kafka1: 192.168.174.100
kafka2: 192.168.174.101
kafka3: 192.168.174.102
下载 kafka
# wget https://dlcdn.apache.org/kafka/3.8.0/kafka_2.13-3.8.0.tgz
解压 kafka
# tar xf kafka_2.13-3.8.0.tgz -C /usr/local
# ln -sv /usr/local/kafka_2.13-3.8.0 /usr/local/kafka
配置 kafka
配置文件路径:config/kraft/server.properties
############################# Server Basics #############################
# The role of this server. Setting this puts us in KRaft mode
process.roles=broker,controller
# The node id associated with this instance's roles
node.id=2
# The connect string for the controller quorum
[email protected]:9093,[email protected]:9093,[email protected]:9093
log.dirs=/tmp/kraft-combined-logs
部署 kafka
生成集群 UUID
$ KAFKA_CLUSTER_ID="$(bin/kafka-storage.sh random-uuid)"
设置日志目录的格式
$ bin/kafka-storage.sh format -t $KAFKA_CLUSTER_ID -c config/kraft/server.properties
启动 Kafka 服务器
$ bin/kafka-server-start.sh -daemon config/kraft/server.properties
查看服务端口
# netstat -tnlp
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp6 0 0 :::9092 :::* LISTEN 619535/java
tcp6 0 0 :::9093 :::* LISTEN 619535/java
firewalld 放行端口
firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv4" source address="192.168.174.100" port protocol="tcp" port="9092" accept'
firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv4" source address="192.168.174.100" port protocol="tcp" port="9093" accept'
firewall-cmd --reload
测试 kafka
创建 topic
# bin/kafka-topics.sh --create --topic wgs-test-event --bootstrap-server 192.168.174.100:9092
Created topic wgs-test-event.
查看 topic
# bin/kafka-topics.sh --list --bootstrap-server 192.168.174.100:9092
__consumer_offsets
wgs-test-event
产生消息
# bin/kafka-console-producer.sh --topic wgs-test-event --bootstrap-server 192.168.174.100:9092
消费消息
# bin/kafka-console-consumer.sh --topic wgs-test-event --from-beginning --bootstrap-server 192.168.174.100:9092
删除 topic
# bin/kafka-topics.sh --delete --topic wgs-test-event --bootstrap-server 30.8.78.10:19092
参考文档
https://docs.confluent.io/platform/current/overview.html
标签:bin,部署,192.168,kafka,--,KRaft,174.100,server,Kafka From: https://www.cnblogs.com/wangguishe/p/18502339