• 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  总共要消费的消息个数

  • 相关阅读:
    图解HTTP笔记整理(前六章)
    heketi管理glusterfs,k8s基于glusterfs创建storageclass
    React 入门:使用 create-react-app 创建 react 17 版本的应用
    Transformer pytorch实现逐行详解
    spring-boot-admin-starter-server监控springboot项目
    全网最全fiddler使用教程和fiddler如何抓包
    LeetCode·51.N皇后·递归+回溯
    Kotlin 中 apply、let、also、run的区别
    (四)安装gitlab服务器
    在ubuntu上安装mysql(在线安装需要)
  • 原文地址:https://blog.csdn.net/extremelove520/article/details/133394655