zoukankan      html  css  js  c++  java
  • kakfa的常用命令总结

    Kafka的版本间差异较大,下面是0.8.2.1的操作方法

    首先cd到kafaka的bin目录下;

     

    #step1启动zookeeper服务

    nohup bin/zookeeper-server-start.sh config/zookeeper.properties > zookeeper.out &

    #step2 启动kafka服务

    nohup bin/kafka-server-start.sh config/server.properties &

    nohup bin/kafka-server-start.sh config/server.properties > kafka_server.out &

    #step3创建一个kafka消息队列
    bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

    bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test2

    注: 

    --partitions 1            为分区数,为分区数,0.8.1默认就是2

    --replication-factor 3 设置是topic消息的备份份数为3份,即副本数

    #创建消息队列,并指定topic的配置参数(消息的最大值参数max.message.bytes

    kafka-topics.sh --create --zookeeper $ZK_CONNECT  --replication-factor 2 --partitions 200 --topic cdn_gz_data --config max.message. bytes=10485760 --config flush.message=1

    Image(4)

     

    #step4列出现有的topic列表
    bin/kafka-topics.sh --list --zookeeper localhost:2181

    #step5发送消息
    Kafka提供了命令行工具从文件获取输入或者标准输入 ,作为消息发送到kafka集群,默认一行一个消息。
    标准输入:
    bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test

    #step6启动consumer,接收消息
    bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning

    #step7查看一个topic的明细 即describe topics,

    bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic page_visits

    #step8 删除topic

    kafka-topics.sh --topic test_kafka1 --zookeeper $ZK_CONNECT --delete test_kafka1

    Image(6)Image(5)

    # 给一个topic 添加配置项

    To add configs:

     > bin/kafka-topics.sh --zookeeper zk_host:port/chroot --alter --topic my_topic_name --config x=y
    

    # 给一个topic 添加配置项

    To remove a config:

    > bin/kafka-topics.sh --zookeeper zk_host:port/chroot --alter --topic my_topic_name --deleteConfig x

    #给一个topic增加分区数(本来有20个分区,修改为26个)

    kafka-topics.sh --zookeeper $ZK_CONNECT --alter --partitions 26  --topic app_request

    # 将一个topic标记为删除,删除的topic默认不可用。

    And finally deleting a topic:

     > bin/kafka-topics.sh --zookeeper zk_host:port/chroot --delete --topic my_topic_name
    

    Topic deletion option is disabled by default. To enable it set the server config

    delete.topic.enable=true

    ##删除topic,慎用,只会删除zookeeper中的元数据,消息文件须手动删除,0.82版本后不可用。

    kafka-run-class.sh kafka.admin.DeleteTopicCommand --topic tvstore --zookeeper $ZK_CONNECT 

    #查看不可用分区
    ./kafka-topics.sh -topic tvstore -describe -unavailable-partitions -zookeeper $ZK_CONNECT 

    #kafka查看topic各个分区的消息的信息

    kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --group cdn_log_group  --topic cdn_gzip_data  --zookeeper $ZK_CONNECT 

    Image(7)

    -----------------------------------------

    ####kafka系统工具################

    Consumer Offset Checker

    Displays the:  Consumer Group, Topic, Partitions, Offset, logSize, Lag, Owner for the specified set of Topics and Consumer Group

    bin/kafka-run-class.sh kafka.tools.ConsumerOffsetChecker

    kafka-run-class.sh kafka.tools.DumpLogSegments

     

    Dump Log Segment
    This can print the messages directly from the log files or just verify the indexes correct for the logs

    bin/kafka-run-class.sh kafka.tools.DumpLogSegments

  • 相关阅读:
    DES CBC java加密 php解密
    CocosCreator入门(一) ------ 简介、安装、微信小游戏
    H5游戏开发----CocosCreator、CocosCreator3D、Cocos2dX差异与选择
    GIT:git -c diff.mnemonicprefix=false -c core.quotepath=false revert --no-edit
    xxx was built without full bitcode" 编译错误解决
    程序猿之GitHub
    【北医三院】生孩、出院等事宜
    Unity:Andriod部分手机频繁闪退,vivo y55a等,Skipped 62 frames! The application may be doing too much work on its main thread
    初识LUA
    Unity3D开发之Matrix4x4矩阵变换
  • 原文地址:https://www.cnblogs.com/honeybee/p/5258906.html
Copyright © 2011-2022 走看看