问题导读
1.如何查看有哪些topic?
2.如何查看topic的详细信息?
3.topic分区通过什么命令添加?
4.本文涉及哪些常用命令?
0.查看有哪些主题:
[mw_shl_code=bash,true]./kafka-topics.sh --list --zookeeper 192.168.0.201:12181
[/mw_shl_code]
1.查看topic的详细信息
[mw_shl_code=bash,true]./kafka-topics.sh -zookeeper 127.0.0.1:2181 -describe -topic testKJ1
[/mw_shl_code]
2、为topic增加副本
[mw_shl_code=bash,true]./kafka-reassign-partitions.sh -zookeeper 127.0.0.1:2181 -reassignment-json-file json/partitions-to-move.json -execute
[/mw_shl_code]
3、创建topic
[mw_shl_code=bash,true]./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic testKJ1
[/mw_shl_code]
4、为topic增加partition
[mw_shl_code=bash,true]./bin/kafka-topics.sh –zookeeper 127.0.0.1:2181 –alter –partitions 20 –topic testKJ1
[/mw_shl_code]
5、kafka生产者客户端命令
[mw_shl_code=bash,true]./kafka-console-producer.sh --broker-list localhost:9092 --topic testKJ1
[/mw_shl_code]
6、kafka消费者客户端命令
[mw_shl_code=bash,true]./kafka-console-consumer.sh -zookeeper localhost:2181 --from-beginning --topic testKJ1
[/mw_shl_code]
7、kafka服务启动
[mw_shl_code=bash,true]./kafka-server-start.sh -daemon ../config/server.properties
[/mw_shl_code]
8、下线broker
[mw_shl_code=bash,true]./kafka-run-class.sh kafka.admin.ShutdownBroker --zookeeper 127.0.0.1:2181 --broker #brokerId# --num.retries 3 --retry.interval.ms 60
shutdown broker[/mw_shl_code]
9、删除topic
[mw_shl_code=bash,true]./kafka-run-class.sh kafka.admin.DeleteTopicCommand --topic testKJ1 --zookeeper 127.0.0.1:2181
./kafka-topics.sh --zookeeper localhost:2181 --delete --topic testKJ1[/mw_shl_code]
10、查看consumer组内消费的offset
[mw_shl_code=bash,true]./kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --zookeeper localhost:2181 --group test --topic testKJ1
./kafka-consumer-offset-checker.sh --zookeeper 192.168.0.201:12181 --group group1 --topic group1[/mw_shl_code]
11、关闭
[mw_shl_code=bash,true]/usr/local/kafka/bin/kafka-server-stop.sh
[/mw_shl_code]kafka-server-stop.sh后面需要配置文件如下面
bin/kafka-server-stop.sh config/server.properties,有时候不能停止,可以使用暴力了。
12、添加开机启动
[mw_shl_code=bash,true]echo ‘
# start kafka
/usr/local/kafka/bin/kafka-server-start.sh -daemon /usr/local/kafka/config/server.properties
‘ >> /etc/rc.local[/mw_shl_code]
参考:
和风细雨汪汪、mamicode
|
|