环境说明
三台虚机
- 192.168.21.100
- 192.168.21.101
- 192.168.21.102
zookeeper服务
- 192.168.21.100:2181
- 192.168.21.101:2181
- 192.168.21.102:2181
kafka服务
- 192.168.21.100:9092
- 192.168.21.101:9092
- 192.168.21.102:9092
命令
启动客户端
/opt/zookeeper/bin/zkCli.sh -server 127.0.0.1:2181
查看zookeeper状态
/opt/zookeeper/bin/zkServer.sh status
kafk服务启动
bin/kafka-server-start.sh config/server.properties
创建topic其中包含一个分区和一个副本因子
bin/kafka-topics.sh --create --zookeeper 192.168.21.100:2181 --replication-factor 1 --partitions 1 --topic topic-name-test
获取Kafka服务器中的主题列表
/opt/kafka/bin/kafka-topics.sh --list --zookeeper 192.168.21.100:2181, 192.168.21.101:2181, 192.168.21.102:2181
使用 –describe 来查看topic
/opt/kafka/bin/kafka-topics.sh --describe --zookeeper 192.168.21.100:2181, 192.168.21.101:2181, 192.168.21.102:2181 --topic test-1
删除topic
/opt/kafka/bin/kafka-topics.sh --delete --zookeeper 192.168.21.100:2181 --topic topic_name
启动生产者
/opt/kafka/bin/kafka-console-producer.sh --broker-list 192.168.21.100:9092, 192.168.21.101:9092, 192.168.21.102:9092 --topic test-1
启动消费者
bin/kafka-console-consumer.sh --zookeeper 192.168.21.100:2181 —-topic topic-1 --from-beginning
新版本中使用下面命令
/opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server 192.168.21.100:2181, 192.168.21.101:2181, 192.168.21.102:2181 --from-beginning --topic test-1
创建一个console consumer group
/opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server 192.168.21.100:9092,192.168.21.101:9092,192.168.21.102:9092 --topic topic-name-test --from-beginning --new-consumer
获取该consumer group的group id(后面需要根据该id查询它的位移信息)
/opt/kafka/bin/kafka-consumer-groups.sh --bootstrap-server 192.168.21.100:9092,192.168.21.101:9092,192.168.21.102:9092 --list --new-consumer