kafka操作命令


kafka-server-start.bat ../../config/server.properties &
kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 2 --topic tm-tongji
kafka-topics.bat --list --zookeeper localhost:2181
kafka-console-consumer.bat --zookeeper localhost:2181 --topic tm-tongji --from-beginning

  

创建kafka topic
bin/kafka-topics.sh --zookeeper node01:2181 --create --topic t_cdr --partitions 30 --replication-factor 2

查看所有topic列表
bin/kafka-topics.sh --zookeeper node01:2181 --list

查看指定topic信息
bin/kafka-topics.sh --zookeeper node01:2181 --describe --topic t_cdr

控制台向topic生产数据
bin/kafka-console-producer.sh --broker-list node86:9092 --topic t_cdr

控制台消费topic的数据
bin/kafka-console-consumer.sh --zookeeper node01:2181 --topic t_cdr --from-beginning

查看topic某分区偏移量最大(小)值
bin/kafka-run-class.sh kafka.tools.GetOffsetShell --topic hive-mdatabase-hostsltable --time -1 --broker-list node86:9092 --partitions 0

注: time为-1时表示最大值,time为-2时表示最小值


增加topic分区数
为topic t_cdr 增加10个分区

$KAFKA_HOME/bin/kafka-topics.sh --zookeeper 10.3.0.19:2181,10.3.0.18:2181 --alter --topic tm-tongji --partitions 1

删除topic,慎用,只会删除zookeeper中的元数据,消息文件须手动删除
$KAFKA_HOME/bin/kafka-run-class.sh kafka.admin.DeleteTopicCommand --zookeeper 10.8.0.19:2181,10.8.0.18:2181 --topic tm-tongji


查询topic的offset的范围
用下面命令可以查询到topic:DynamicRange broker:SparkMaster:9092的offset的最小值:

$ /opt/cloudera/parcels/KAFKA/bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list SparkMaster:9092 —topic DynamicRange --time -2
输出

DynamicRange:0:1288
查询offset的最大值:

$ /opt/cloudera/parcels/KAFKA/bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list SparkMaster:9092 —topic DynamicRange --time -1
输出

DynamicRange:0:7885
从上面的输出可以看出topic:DynamicRange只有一个partition:0 offset范围为:[1288,7885]

 

设置consumer group的offset
启动zookeeper client

$ /opt/cloudera/parcels/CDH/lib/zookeeper/bin/zkCli.sh
通过下面命令设置consumer group:DynamicRangeGroup topic:DynamicRange partition:0的offset为1288:

set /consumers/DynamicRangeGroup/offsets/DynamicRange/0 1288
注意如果你的kafka设置了zookeeper root,比如为/kafka,那么命令应该改为:

set /kafka/consumers/DynamicRangeGroup/offsets/DynamicRange/0 1288


nohup bin/kafka-manager -Dconfig.file=conf/application.conf -Dhttp.port 9001 &
nohup bin/kafka-manager >/dev/null 2>&1 &

只保留输出错误信息 nohup command >/dev/null 2>log &
所有信息都不要 nohup command >/dev/null 2>&1 &
nohup command > vienout.txt 2>&1 &
nohup command > vienout.txt 2>&1 &

由于使用nohup时,会自动将输出写入nohup.out文件中,如果文件很大的话,nohup.out就会不停的增大,我们可以利用Linux下一个特殊的文件/dev/null来解决这个问题,这个文件就相当于一个黑洞,任何输出到这个文件的东西都将消失
只保留输出错误信息 nohup command >/dev/null 2>log &
所有信息都不要 nohup command >/dev/null 2>&1 &

这里解释一下后面的2>&1 。 这涉及到Linux的重定向,其中0、1、2分别是标准输入、标准输出、标准错误输出,用来指定需要重定向的标准输入输出。默认情况下是标出输出,也就是1 。例如我们而上文提到的 2>&1 是 将错误信息重定向到标准输出。

还有就是如果不想让程序输出,Linux下有一个/dev/null的特殊文件,就像一个黑洞,所有输出到这个文件的信息全部会消失,如果你不需要输出日志,这样做就不会导致输出日志文件越来越大,占用存储空间的问题了

  

映射常用命令组合
vim ~/.bashrc
vim /etc/bashrc

alias tomcatlog="tail -f /usr/local/tomcat/logs/catalina.out"
alias zhao="ps -ef|grep "

alias kafkaserver="cd /data/local/kafka/"
alias kafkarun="cd /data/kafka/runlog/"
alias kafkalog="tail -f /data/kafka/runlog/server.out"
alias kafkaerr="tail -f /data/kafka/runlog/server.err"
alias zookeeper="cd /data/log/zookeeper"

source /etc/bashrc

posted @ 2017-11-23 08:42  yuan.net  阅读(677)  评论(0编辑  收藏  举报