zoukankan      html  css  js  c++  java
  • kafka常用命令,启动/停止/查看主题列表/消费/生产

    kafka启动(需要先启动zk):

    bin/zookeeper-server-start.sh -daemon config/zookeeper.properties 
    bin/kafka-server-start.sh -daemon config/server.properties 

    kafka停止:

    bin/kafka-server-stop.sh 
    bin/zookeeper-server-stop.sh 

    把以下内容追加到bashrc中。

    以centos为例:

    vi ~/.bashrc

    追加内容如下:

    复制代码
    KAFKA_HOME="/usr/lib/kafka"
    KAFKA_ADDRESS="192.168.108.136"
    KAFKA_BIND="${KAFKA_ADDRESS}:9092"
    ZK_BIND="${KAFKA_ADDRESS}:2181"
    
    alias listtopics="${KAFKA_HOME}/bin/kafka-topics.sh --list --zookeeper ${ZK_BIND} "
    alias createtopic="${KAFKA_HOME}/bin/kafka-topics.sh --create --zookeeper ${ZK_BIND} --replication-factor 1 --partitions 1 --topic "
    alias kafkaproduce="${KAFKA_HOME}/bin/kafka-console-producer.sh --broker-list ${KAFKA_BIND} --topic "
    alias kafkaconsume="${KAFKA_HOME}/bin/kafka-console-consumer.sh --zookeeper ${ZK_BIND} --from-beginning --topic "
    alias kafkaconsumekey="${KAFKA_HOME}/bin/kafka-console-consumer.sh --zookeeper ${ZK_BIND} --from-beginning --property print.key=true --property key.separator=' --- ' --topic "
    alias kafkaconsumeoffset="${KAFKA_HOME}/bin/kafka-console-consumer.sh --zookeeper ${ZK_BIND} --from-beginning --print-offsets --topic"
    复制代码

    保存后使其生效

    source ~/.bashrc

    查看kafka主题:

    listtopics

    创建kafka主题parasis:

    createtopic parasis

    在parasis主题下生产数据,进入命令行后,输入生产数据,以回车结尾:

    kafkaproduce parasis

    消费parasis主题内数据:

    kafkaconsume parasis

    消费parasis主题内数据(包含key):

    kafkaconsumekey parasis

    消费parasis主题内数据(包含offset):

    kafkaconsumeoffset parasis
  • 相关阅读:
    python之路---23 模块 os sys pickle json
    Fiddler抓包【7】_次要功能和第三方插件
    Fiddler抓包【6】_Fiddler Script
    Fiddler抓包【5】_Fiddler过滤
    Fiddler抓包【4】_重定向AutoResponder
    Fiddler抓包【3】_设置断点修改
    Fiddler抓包【2】_捕获设置
    Fiddler抓包【1】_介绍及界面概述
    CSS常见兼容问题以及解决办法
    webpack入门文档教程
  • 原文地址:https://www.cnblogs.com/kwzblog/p/14101091.html
Copyright © 2011-2022 走看看