kafka知识整理——部署
一、部署
(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