Zookeeper
1.zookeeper启动:zkServer.sh start
2.zookeeper关闭:zookeeper.sh stop
3.启动zookeeper客户端:zkCli.sh -server localhost:2181,server-1:2181(使用到的时候,用[zkCli]标示)
Kafka
1.kafka启动:Kafka-server-start.sh -daemon ${KAFKA_HOME}/config/server.properties
2.kafka关闭:kafka-server-stop.sh
3.主题相关(kafka-topics.sh -help):
修改主题的配置:https://kafka.apache.org/documentation/#topicconfigs
(1) 创建主题:kafka-topics.sh --zookeeper localhost:2181 --create --replication-factor 2 --partitions 3 --topic 主题名 [--config max.message.bytes=404800, flush.message=1]
[zkCli] ls /brokers/topics/主题名
[zkCli] ls /brokers/topics/主题名/partitions
(2) 删除主题:kafka-topics.sh --zookeeper localhost:2181 --delete --topic 主题名
当${KAFKA_HOME}/config/server.properties中设置delete.topic.enable=true才会真正删除主题,否则只是将该主题标记为删除状态。
(3) 查看所有的主题:kafka-topics.sh --zookeeper localhost:2181 --list
(4) 查看某个特定的主题的详细信息: kafka-topic.sh --zookeeper localhost:2181 --topic 主题名 --describe
(5) 查看所有主题的详细信息:kafka-topics.sh --zookeeper localhost:2181 --describe
(6) 查看正在同步的主题:处于该状态的主题可能正在同步也可能发生异常,需要重点关注
kafka-topics.sh --zookeeper localhost:2181 [--topic 主题名] --describe --under-replication
(7) 查看没有leader的分区:kafka-topics.sh --zookeeper localhost:2181 [--topic 主题名] --describe --unavaliable-partitions
(8) 查看主题覆盖的配置:kafka-topics.sh --zookeeper localhost:2181 [--topic 主题名] --desrcibe --topics-with-overrides
4.修改topics、clients、users、brokers
主题级别:
(1)查看主题已覆盖的配置:kafka-config.sh --zookeeper localhost:2181 --entity-type topics --entity-name 主题名 --describe
(2)修改主题的配置:kafka-config.sh --zookeeper localhost:2181 --entity-type topics --entity-name 主题名 --alter --add-config flush.messages=2,max.message.bytes=102400
(3)删除主某些主题配置,恢复默认:kafka-config.sh --zookeeper localhost:2181 --entity-type topics --entity-name 主题名 --alter --delete-config max.message.bytes,flush.messages
代理级别:
(1)代理级别提供流量控制:
kafka-config.sh --zookeeper localhost:2181 --entity-type brokers --entity-name 0 --alter --add-config follower.replication.throttled.rate=102340,leader.replication.throttled.rate=1023444
(2)删除配置:
kafka-config.sh --zookeeper localhost:2181 --entity-type brokers --entity-name 0 --alter --delete-config follow.replication.throttled.rate,leader.replication.throttled.rate
5.生产者Producer[kafka-console-producer.sh]
kafka-console-producer.sh --broker-list localhost:9092 --topic kafka-action [--property parse.key=true]
6.消费者Consumer[kafka-console-cunsumer.sh]
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic kafka-action --group 组别名(组别名用于实现单播和多播)
查看消息偏移量:kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group 组别
查看所有组别:kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list
新版本在[zkCli]的元数据中ls /consumers/ 没有任何信息,所以使用以下命令删除组:
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --delete --group 组别
7.kafka-run-class.sh的使用
使用格式:kafka-run-class.sh kafka.tools.类 参数
kafka.tools.tools中的类有:
具体的参数使用kafka-run-class.sh kafka.tools.具体的类查看
常用的两个实例:
查询某一个topic每一个分区具体的偏移量:
kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic 主题名 [--partitions 0,1] [--time -1/-2]
--time -1->latest -2->earliest
查看produce的数据:
kafka-run-class.sh kafka.tools.DumpLogSegments --file ${KAFAK_HOME}/logs/kafka-action-0/
00000000000000000000.log --print-data-log