• kafka 集群搭建 & 常用命令


    1、集群搭建:

    <1> 将kafka 压缩包解压到某一目录

    tar -zxvf kafka_2.12-3.5.1.tgz

    <2> 修改节点配置文件

    vim config/server.properties

    broker.id=0

    log.dirs=/tmp/kafka-logs

    zookeeper 连接配置

    zookeeper.connect=节点1:2181,节点2:2181,节点3:2181

    <3> 将安装好的kafka 分发到其他服务器

    scp -r kafka_2.12-2.4.1/ xxx

    <4>配置KAFKA_HOME环境变量

     vim /etc/profile

    export KAFKA_HOME=/home/abin/kafka_2.12-3.5.1

    export PATH=:$PATH:$(KAFKA_HOME)

    将profile分发到各节点

     scp /etc/profile 服务器

     source /etc/profile

    <5>查看是否搭建成功

    bin/kafka-topics.sh --bootstrap-server localhost:9092 --list
     

    2、kafka  常用命令

    zookeeper启动:nohup bin/zookeeper-server-start.sh config/zookeeper.properties

    kafka启动:nohup bin/kafka-server-start.sh config/server.properties

    jps 查看是否启动

    创建主题:

    ./kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test

    topic分区扩容

    ./kafka-topics.sh --zookeeper  localhost:2181 --alter --topic test --partitions 4

    ./kafka-topics.sh --bootstrap-server localhost:9092 --alter --topic test --
    partitions 3

    删除topic

    <1>kafka-topics.sh --delete --zookeeper  localhost:2181 localhost:9092 --topic test

    <2>./kafka-topics.sh --delete --bootstrap-server localhost:9092 --topic test (高版本不依赖zookeeper)

    查询topic 详细信息

    ./kafka-topics.sh --describe --topic test --bootstrap-server localhost:9092

    列出主题:

    ./kafka-topics.sh --list --bootstrap-server localhost:9092

    发送消息:

    ./kafka-console-producer.sh --broker-list localhost:9092 --topic test_topic

    消费消息:

    ./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test_topic --from-beginning

    3、kafka 的基准测试

    ./kafka-producer-perf-test.sh --topic test --num-record 500000 --throughput -1 --record-size 1000 --producer-props bootstrap.servers=localhost:9092 acks=1

    --topic    topic 的名字

    --num-records  指定总共生产数据量(默认5000W)

    --throughput     指定吞吐量,限流,-1不指定

    --record-size  record 数据大小(字节)

    --producer-props bootstrap.servers=localhost:9092 acks=1  指定kafka 集群地址,ACK模式

    测试消费的效率

     ./kafka-consumer-perf-test.sh --broker-list localhost:9092 --topic test --fetch-size 1048576 --messages 500000

    --fetch-size  每次要拉去的数据大小

    --messages  总共要消费的消息个数

  • 相关阅读:
    c++无痛实现日期类
    ES6(一)
    DTO 模式(数据传输对象)
    .Net7自定义GC垃圾回收器
    网络安全—小白自学
    头歌实践平台-数据结构-二叉树及其应用
    C++11——— 包装器
    一文看懂网络安全五年之巨变
    Dynamo_修复导出EXCEL时出现的组件丢失问题
    第P6周—好莱坞明星识别(1)
  • 原文地址:https://blog.csdn.net/extremelove520/article/details/133394655