当前位置: 首页 > news >正文

Kafka入门到实战-第五弹

Kafka入门到实战

  • Kafka常见操作
    • 官网地址
    • Kafka概述
    • Kafka的基础操作
    • 更新计划

Kafka常见操作

官网地址

声明: 由于操作系统, 版本更新等原因, 文章所列内容不一定100%复现, 还要以官方信息为准

https://kafka.apache.org/

Kafka概述

Apache Kafka 是一个开源的分布式事件流平台,提供高性能数据管道、流分析、 数据集成和任务关键型应用程序。

Kafka的基础操作

本节将在Kafka集群上执行。所有工具都可以在Kafka发行版的bin/目录下使用,如果在没有参数的情况下运行,每个工具都会打印所有可能的命令行选项的详细信息。

  • 添加和删除主题 创建一个名为 my_topic_name的主题, 分区为10, 副本数为2(上次搭建的集群只有两个broker), 保留时间是1天

    bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic my_topic_name \--partitions 10 --replication-factor 2 --config retention.ms=86400000
    

    在这里插入图片描述

  • 查看分区是否正常创建 ls /tmp/kraft-combined-logs/
    在这里插入图片描述

  • 删除主题, 可以看到分区被逻辑删除啦,

    bin/kafka-topics.sh --bootstrap-server localhost:9092 --delete --topic my_topic_name
    

    在这里插入图片描述

  • 修改主题, 只需要把delete 改为alert即可

  • 优雅地关闭, 以下内容直接参考官网, 未在本机上测试

    • 关闭生产者
    • 关闭消费者
    • 添加controlled.shutdown.enable=true
    • bin/kafka-server-stop.sh
  • 设置具有优先的领导权, 用于一个服务实例宕机启动

    auto.leader.rebalance.enable=true
    
  • 跨机架平衡复制副本, 实现Kafka故障转移和容灾备份

     broker.rack=my-rack-id
    
  • 查看消费者的位置

    bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group my-group
    
  • 管理消费者组

    bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list
    
  • 列出消费者组详细信息

    bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group my-group
    
    • 还可以加一些参数
    • –members 提供使用者组中所有活动成员的列表
    • –members --verbose 还提供分配给每个成员的分区
    • –offsets 默认的description选项,提供与“–description”选项相同的输出
    • –state 提供有用的组级别信息
    • –delete 删除一个或多个消费者组
  • 扩展集群

  • 下线服务实例

  • 增加复制因子

  • 限制数据迁移期间的带宽使用

  • 配置额度

    • 自定义额度对于 (user=user1, client-id=clientA)

      bin/kafka-configs.sh  --bootstrap-server localhost:9092 --alter --add-config 'producer_byte_rate=1024,consumer_byte_rate=2048,request_percentage=200' --entity-type users --entity-name user1 --entity-type clients --entity-name clientA
      
    • 自定义额度对于 user=user1

      bin/kafka-configs.sh  --bootstrap-server localhost:9092 --alter --add-config 'producer_byte_rate=1024,consumer_byte_rate=2048,request_percentage=200' --entity-type users --entity-name user1
      
    • 自定义额度对于 client-id=clientA

      bin/kafka-configs.sh  --bootstrap-server localhost:9092 --alter --add-config 'producer_byte_rate=1024,consumer_byte_rate=2048,request_percentage=200' --entity-type clients --entity-name clientA
      
    • 为user=userA配置默认客户端id配额

      bin/kafka-configs.sh  --bootstrap-server localhost:9092 --alter --add-config 'producer_byte_rate=1024,consumer_byte_rate=2048,request_percentage=200' --entity-type users --entity-name user1 --entity-type clients --entity-default
      
    • 配置默认配额对于user

      bin/kafka-configs.sh  --bootstrap-server localhost:9092 --alter --add-config 'producer_byte_rate=1024,consumer_byte_rate=2048,request_percentage=200' --entity-type users --entity-default
      
    • 配置默认配额对于client-id

      bin/kafka-configs.sh  --bootstrap-server localhost:9092 --alter --add-config 'producer_byte_rate=1024,consumer_byte_rate=2048,request_percentage=200' --entity-type clients --entity-default
      
    • 查询分配的配额 (user, client-id)

      bin/kafka-configs.sh  --bootstrap-server localhost:9092 --describe --entity-type users --entity-name user1 --entity-type clients --entity-name clientA
      
    • 查询分配的配额 (user)

      bin/kafka-configs.sh  --bootstrap-server localhost:9092 --describe --entity-type users --entity-name user1
      
    • 查询分配的配额 (client-id)

      bin/kafka-configs.sh  --bootstrap-server localhost:9092 --describe --entity-type clients --entity-name clientA
      
    • 查询分配的配额 (所有user)

      bin/kafka-configs.sh  --bootstrap-server localhost:9092 --describe --entity-type users
      
    • 查询分配的配额 (所有user, client-id)

      bin/kafka-configs.sh  --bootstrap-server localhost:9092 --describe --entity-type users --entity-type clients
      

更新计划

下一部分是Kafka实战的代码部分, 敬请期待…

http://www.lryc.cn/news/331378.html

相关文章:

  • Ideal Holidays
  • Raven:一款功能强大的CICD安全分析工具
  • 【苹果MAC】苹果电脑 LOGI罗技鼠标设置左右切换全屏页面快捷键
  • IDE/VS2015和VS2017帮助文档MSDN安装和使用
  • 开启 Keep-Alive 可能会导致http 请求偶发失败
  • 【leetcode面试经典150题】4.删除有序数组中的重复项 II(C++)
  • 【LeetCode热题100】【普通数组】合并区间
  • 自我认识的方法模型图
  • dhcp和dhcp中继代理
  • 【fastadmin】脚本模式下,日志钩子函数执行出现死循环,导致内存溢出奔溃
  • gitlab代码迁移,包含历史提交记录、标签、分支
  • 通过TCP或UDP向某个IP和端口发送数据
  • Go语言介绍及Go语言成功的项目列举
  • CQI-17:2021 V2 英文 、中文版。特殊过程:电子组装制造-锡焊系统评审标准
  • 普通Java工程可执行JAR两种打包方式探讨
  • 开源博客项目Blog .NET Core源码学习(13:App.Hosting项目结构分析-1)
  • Vue的双向绑定v-model详细介绍
  • AWS入门实践-S3对象存储的基本用法
  • el-tree-v2渲染树形大数据并设置默认展开
  • 损失函数篇 | YOLOv8更换损失函数之MPDIoU(23年7月首发论文)
  • 【力扣】200.岛屿数量(染色法DFS深搜)
  • 达梦配置ODBC连接
  • 独孤思维:高客单价项目,必须来一个
  • 学习java第三十二天
  • 力扣150. 逆波兰表达式求值
  • hololens 2 投屏 报错
  • 初次在 GitHub 建立仓库以及公开代码的流程 - 公开代码
  • 论文笔记 - :MonoLSS: Learnable Sample Selection For Monocular 3D Detection
  • LVS、HAProxy
  • 开发环境->生产环境