一、部署
(1)zk配置
修改zk配置檔案config/zookeeper.properties,修改dataDir或埠
dataDir=/home/kafka/kafka3.7/data/zookeeper
clientPort=2181
(2)zk啟動
./zookeeper-server-start.sh -daemon ../config/zookeeper.properties
(3)kafka配置
以部署三臺kafka叢集為例
修改各自kafka配置檔案config/server.properties
borker.id=0 三臺需不同
listeners=PLAINTEXT://192.168.1.XX:9092 如需對外發布,需修改該配置
log.dirs=/home/kafka/kafka3.7/data/kafka-logs
(4)啟動kafka
./kafka-server-start.sh -daemon ../config/server.properties
二、建立主題
以三個分割槽,各自3個副本為例
./kafka-topics.sh --bootstrap-server 192.168.1.XX:9092 --topic mytopic --partitions 3 --replication-factor 3 --create
檢視主題
./kafka-topics.sh --bootstrap-server 192.168.1.11:9092 --list
和詳情
./kafka-topics.sh --bootstrap-server 192.168.1.11:9092 --describe
Topic: mytopic TopicId: qMZsyOdWRAizH8ydRuZq5Q PartitionCount: 3 ReplicationFactor: 3 Configs:
Topic: mytopic Partition: 0 Leader: 1 Replicas: 1,0,2 Isr: 1,0,2
Topic: mytopic Partition: 1 Leader: 0 Replicas: 0,2,1 Isr: 0,2,1
Topic: mytopic Partition: 2 Leader: 2 Replicas: 2,1,0 Isr: 2,1,0
也可透過prettyZOO視覺化檢視kafka狀態
三、訊息測試
./kafka-console-producer.sh --bootstrap-server 192.168.1.11:9092 --topic mytopic
./kafka-console-consumer.sh --bootstrap-server 192.168.1.11:9092 --topic mytopic