下载
https://www.apache.org/dyn/closer.cgi?path=/kafka/2.8.0/kafka_2.12-2.8.0.tgz
解压
tar xvzf kafka_2.12-2.8.0.tgz
mv kafka_2.12-2.8.0 kafka
配置
server.properties
#节点唯一标识
broker.id=0
#访问地址端口
listeners=PLAINTEXT://192.168.158.129:9092
#消息保存目录
log.dirs=/home/sirui/kafka/kafka-logs
#zookeeper连接地址
zookeeper.connect=192.168.158.129:2181,192.168.158.130:2181,192.168.158.131:2181
启动
zkServer.sh start
./bin/kafka-server-start.sh -daemon config/server.properties
创建主题
./bin/kafka-topics.sh --create --zookeeper 192.168.158.129:2181 --replication-factor 1 --partit
ions 1 --topic test
查看主题
./bin/kafka-topics.sh --list --zookeeper 192.168.158.129:2181
删除主题
./bin/kafka-topics.sh --delete --zookeeper 192.168.158.129:2181
发消息
./bin/kafka-console-producer.sh --broker-list 192.168.158.129:9092 --topic test
消费消息
./bin/kafka-console-consumer.sh --bootstrap-server 192.168.158.129:9092 --topic test
单播消息
./bin/kafka-console-consumer.sh --bootstrap-server 192.168.158.129:9092 --consumer-property group.id=testGroup --topic test
多播消息
./bin/kafka-console-consumer.sh --bootstrap-server 192.168.158.129:9092 --consumer-property group.id=testGroup-2 --topic test
查看消费组名
./bin/kafka-consumer-groups.sh --bootstrap-server 192.168.158.129:9092 --list
查看消费组的消费偏移量
./bin/kafka-consumer-groups.sh --bootstrap-server 192.168.158.129:9092 --describe --group testGroup
查看信息
./bin/kafka-topics.sh --describe --zookeeper 192.168.158.129:2181 --topic test
分区扩容
./bin/kafka-topics.sh -alter --partitions 3 --zookeeper 192.168.158.129:2181 --topic test
创建集群主题
./bin/kafka-topics.sh --create --zookeeper 192.168.158.129:2181 --replication-factor 3 --partitions 2 --topic mytopic
|