【kafka】记一次kafka基于linux的原生命令的使用

news2024/10/7 6:47:25

环境是linux,4台机器,版本3.6,kafka安装在node 1 2 3 上,zookeeper安装在node2 3 4上。

安装好kafka,进入bin目录,可以看到有很多sh文件,是我们执行命令的基础。
在这里插入图片描述
启动kafka,下面的命令的后面带的配置文件的相对路径

kafka-server-start.sh ./server.properties

遇到不熟悉的sh文件,直接输入名字并回车,就会提示你可用的命令参数。如果参数用错了,kafka也会提示你相应的错误。

[root@localhost bin]# kafka-topics.sh
Create, delete, describe, or change a topic.
Option                                   Description                            
------                                   -----------                            
--alter                                  Alter the number of partitions and     
                                           replica assignment. Update the       
                                           configuration of an existing topic   
                                           via --alter is no longer supported   
                                           here (the kafka-configs CLI supports 
                                           altering topic configs with a --     
                                           bootstrap-server option).            
--at-min-isr-partitions                  if set when describing topics, only    
                                           show partitions whose isr count is   
                                           equal to the configured minimum.     
--bootstrap-server <String: server to    REQUIRED: The Kafka server to connect  
  connect to>                              to.                                  
--command-config <String: command        Property file containing configs to be 
  config property file>                    passed to Admin Client. This is used 
                                           only with --bootstrap-server option  
                                           for describing and altering broker   
                                           configs.                             
--config <String: name=value>            A topic configuration override for the 
                                           topic being created or altered. The  
                                           following is a list of valid         
                                           configurations:                      
                                         	cleanup.policy                        
                                         	compression.type                      
                                         	delete.retention.ms                   
                                         	file.delete.delay.ms                  
                                         	flush.messages                        
                                         	flush.ms                              
                                         	follower.replication.throttled.       
                                           replicas                             
                                         	index.interval.bytes                  
                                         	leader.replication.throttled.replicas 
                                         	local.retention.bytes                 
                                         	local.retention.ms                    
                                         	max.compaction.lag.ms                 
                                         	max.message.bytes                     
                                         	message.downconversion.enable         
                                         	message.format.version                
                                         	message.timestamp.after.max.ms        
                                         	message.timestamp.before.max.ms       
                                         	message.timestamp.difference.max.ms   
                                         	message.timestamp.type                
                                         	min.cleanable.dirty.ratio             
                                         	min.compaction.lag.ms                 
                                         	min.insync.replicas                   
                                         	preallocate                           
                                         	remote.storage.enable                 
                                         	retention.bytes                       
                                         	retention.ms                          
                                         	segment.bytes                         
                                         	segment.index.bytes                   
                                         	segment.jitter.ms                     
                                         	segment.ms                            
                                         	unclean.leader.election.enable        
                                         See the Kafka documentation for full   
                                           details on the topic configs. It is  
                                           supported only in combination with --
                                           create if --bootstrap-server option  
                                           is used (the kafka-configs CLI       
                                           supports altering topic configs with 
                                           a --bootstrap-server option).        
--create                                 Create a new topic.                    
--delete                                 Delete a topic                         
--delete-config <String: name>           A topic configuration override to be   
                                           removed for an existing topic (see   
                                           the list of configurations under the 
                                           --config option). Not supported with 
                                           the --bootstrap-server option.       
--describe                               List details for the given topics.     
--exclude-internal                       exclude internal topics when running   
                                           list or describe command. The        
                                           internal topics will be listed by    
                                           default                              
--help                                   Print usage information.               
--if-exists                              if set when altering or deleting or    
                                           describing topics, the action will   
                                           only execute if the topic exists.    
--if-not-exists                          if set when creating topics, the       
                                           action will only execute if the      
                                           topic does not already exist.        
--list                                   List all available topics.             
--partitions <Integer: # of partitions>  The number of partitions for the topic 
                                           being created or altered (WARNING:   
                                           If partitions are increased for a    
                                           topic that has a key, the partition  
                                           logic or ordering of the messages    
                                           will be affected). If not supplied   
                                           for create, defaults to the cluster  
                                           default.                             
--replica-assignment <String:            A list of manual partition-to-broker   
  broker_id_for_part1_replica1 :           assignments for the topic being      
  broker_id_for_part1_replica2 ,           created or altered.                  
  broker_id_for_part2_replica1 :                                                
  broker_id_for_part2_replica2 , ...>                                           
--replication-factor <Integer:           The replication factor for each        
  replication factor>                      partition in the topic being         
                                           created. If not supplied, defaults   
                                           to the cluster default.              
--topic <String: topic>                  The topic to create, alter, describe   
                                           or delete. It also accepts a regular 
                                           expression, except for --create      
                                           option. Put topic name in double     
                                           quotes and use the '\' prefix to     
                                           escape regular expression symbols; e.
                                           g. "test\.topic".                    
--topic-id <String: topic-id>            The topic-id to describe.This is used  
                                           only with --bootstrap-server option  
                                           for describing topics.               
--topics-with-overrides                  if set when describing topics, only    
                                           show topics that have overridden     
                                           configs                              
--unavailable-partitions                 if set when describing topics, only    
                                           show partitions whose leader is not  
                                           available                            
--under-min-isr-partitions               if set when describing topics, only    
                                           show partitions whose isr count is   
                                           less than the configured minimum.    
--under-replicated-partitions            if set when describing topics, only    
                                           show under replicated partitions     
--version                                Display Kafka version.                

如这里,我们创建一个topic名为test。

kafka-topics.sh --create --topic test  --bootstrap-server node1:9092 --partitions 2 --replication-factor 2
Created topic test.

连接其中node1上的kafka获得metedata里的topic列表

[root@localhost bin]# kafka-topics.sh --list --bootstrap-server node1:9092
test

查看某个topic的细节

[root@localhost bin]# kafka-topics.sh --describe --topic test --bootstrap-server node1:9092
Topic: test	TopicId: WgjG4Ou_Q7iQvzgipRgzjg	PartitionCount: 2	ReplicationFactor: 2	Configs: 
	Topic: test	Partition: 0	Leader: 2	Replicas: 2,1	Isr: 2,1
	Topic: test	Partition: 1	Leader: 3	Replicas: 3,2	Isr: 3,2

在其中的一台机器上起一个生产者,在其他两台机器上起2个消费者,都在同一个组里。

[root@localhost bin]# kafka-console-producer.sh --broker-list node1:9092 --topic test
>hello 03
>1
>2
>3
>4
>5
>6
>7
>8

可以看到同一个组内,如果组内消费者注册情况不变化有且只有同一个consumer能够消费数据。可以满足对于消息要求顺序性,不能并发消费的情况。

[root@localhost bin]# kafka-console-consumer.sh --bootstrap-server node1:9092 --topic test --group msb
hello 03
1
2
3
4
5
6
7
8

查看某个组内的情况

[root@localhost bin]# kafka-consumer-groups.sh --bootstrap-server node2:9092 --group msb --describe

GROUP           TOPIC           PARTITION  CURRENT-OFFSET  LOG-END-OFFSET  LAG             CONSUMER-ID                                           HOST             CLIENT-ID
msb             test            1          24              24              0               console-consumer-4987804d-6e59-4f4d-9952-9afb9aff6cbe /192.168.184.130 console-consumer
msb             test            0          0               0               0               console-consumer-242992e4-7801-4a38-a8f3-8b44056ed4b6 /192.168.184.130 console-consumer

最后看一下zk中的情况吧。
zk根目录下多了一个kafka节点

[zk: localhost:2181(CONNECTED) 1] ls /
[kafka, node1, node6, node7, testLock, zookeeper]

kafka下面有很多metedata信息,包含在这些节点中,如,,

[zk: localhost:2181(CONNECTED) 2] ls /kafka
[admin, brokers, cluster, config, consumers, controller, controller_epoch, feature, isr_change_notification, latest_producer_id_block, log_dir_event_notification]
#集群id
[zk: localhost:2181(CONNECTED) 3] ls /kafka/cluster 
[id]
[zk: localhost:2181(CONNECTED) 5] get /kafka/cluster/id 
{"version":"1","id":"8t14lxoAS1SdXapY6ysw_A"}
#controller的id
[zk: localhost:2181(CONNECTED) 6] get /kafka/controller
{"version":2,"brokerid":3,"timestamp":"1698841142070","kraftControllerEpoch":-1}

可以看到topics中有一个__consumer_offsets,是kafka用来存储offset的topic。

[zk: localhost:2181(CONNECTED) 10] ls /kafka/brokers/topics 
[__consumer_offsets, test]
[zk: localhost:2181(CONNECTED) 12] get /kafka/brokers/topics/__consumer_offsets 
{"partitions":{"44":[1],"45":[2],"46":[3],"47":[1],"48":[2],"49":[3],"10":[3],"11":[1],"12":[2],"13":[3],"14":[1],"15":[2],"16":[3],"17":[1],"18":[2],"19":[3],"0":[2],"1":[3],"2":[1],"3":[2],"4":[3],"5":[1],"6":[2],"7":[3],"8":[1],"9":[2],"20":[1],"21":[2],"22":[3],"23":[1],"24":[2],"25":[3],"26":[1],"27":[2],"28":[3],"29":[1],"30":[2],"31":[3],"32":[1],"33":[2],"34":[3],"35":[1],"36":[2],"37":[3],"38":[1],"39":[2],"40":[3],"41":[1],"42":[2],"43":[3]},"topic_id":"RGxJyefAQlKrmY3LTVbKGw","adding_replicas":{},"removing_replicas":{},"version":3}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1164397.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

蓝桥白皮书16.0版——2、蓝桥等考介绍及代报名方式、报名时间

等级考试综述 蓝桥等考全称为“蓝桥青少年信息技术等级考试” 。等级考试聚焦学生学习过程的跟 踪评价 &#xff0c;以考促学 &#xff0c;标准化中小学校教学、校外机构培训和家长学生自学的学习目标及学习进程。 等级考试命题原则 等级考试各组别考试范围是掌握该组别编程知识…

js字符串支持多个分隔符分割

js字符串支持多个分隔符分割 场景代码 场景 用户输入内容后&#xff0c;支持多个分隔符&#xff08;比如&#xff1a;中英文逗号&#xff0c;分号以及换号&#xff09;对字符串进行分割&#xff0c;之后提交给后台同学解析。 代码 function splitString(inputString, separat…

封装taro的api请求工具request.ts,并发送网络请求

使用taro的网络请求工具时&#xff0c;并没有统一的请求封装工具&#xff0c;这里我来分享一下我的请求工具&#xff0c;可以设置base_url和超时时间&#xff0c;还有响应数据格式处理。 在utils/request.ts中封装请求&#xff1a; import Taro from tarojs/taro;const TIME_…

Java——StringBuffer与StringBuilder的区别

Java——StringBuffer与StringBuilder的区别 StringBuffer和StringBuilder是Java中用于处理字符串的两个类&#xff0c;它们之间的主要区别在于线程安全性和性能方面。 1. 线程安全性&#xff1a; StringBuffer&#xff1a;StringBuffer 是线程安全的&#xff0c;所有的公共方…

知心早安问候语,愿你享受美好的时光,幸福快乐每一天

人生万里路&#xff0c;走好每一步&#xff0c;身体是本钱&#xff0c;平安是财富&#xff0c;开心就是护身符&#xff0c;健康才是摇钱树。新的一天&#xff0c;事事顺意&#xff01; 晨起福门开&#xff0c;快乐安康在&#xff0c;愉悦心态好&#xff0c;生活充满爱&#xf…

Blazor 虚拟滚动/瀑布流加载Table数据

page "/virtualScrolling" using BlazorApp.Data<h3>Table 虚拟滚动行</h3> <h4>Table 组件显示大数据时通常采用分页加载数据&#xff0c;还有一种虚拟行的技术类似手机滚动到底部时后台自动加载数据</h4><p>快速滚动时显示行占位&am…

【Linux系统学习】系统编程开发工具编译器gcc/g++使用

个人主页点击直达&#xff1a;小白不是程序媛 Linux专栏&#xff1a;Linux系统学习 目录 前言 Linux系统下安装gcc和g gcc和g的不同 gcc/g的使用 gcc/g选项 预处理 头文件的展开 宏替换 注释的删除 条件的编译 编译 汇编 链接 系统库 库的分类 库的安装 库的…

RT-Thread 9. VS2012下仿真RT-Thread 和LVGL

1. 在ENV中添加组件 2. 下载组件 3. 生成代码 4. 打开代码 双击project.vcxproj 编译 5. 运行

偶数矩阵判断【C语言作业】

题目 若一个布尔矩阵所有行和所有列的和都是偶数&#xff0c;则称为偶数矩阵。请编写一个程序&#xff0c;判断一个布尔矩阵是否是偶数矩阵。 要求&#xff1a; &#xff08;1&#xff09;输入:首先输入一个正整数n(n<100),代表该矩阵的大小&#xff0c;接下来是n行n列的矩…

Vue实现消费清单明细饼图展示

功能 可以进行消费项增删消费额大于500会标红消费金额合计饼图展示消费项 代码 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8" /><meta name"viewport" content"widthdevice-width, initial-…

代码随想录算法训练营第四十一天 | LeetCode 416. 分割等和子集

代码随想录算法训练营第四十一天 | LeetCode 416. 分割等和子集 文章链接&#xff1a;01背包理论基础 01背包理论基础&#xff08;滚动数组&#xff09; 分割等和子集 视频链接&#xff1a;01背包理论基础 01背包理论基础&#xff08;滚动数组&#xff09; 分割等和子集 1. 01 …

腾讯云双11活动时间、活动入口、优惠政策详细解读

2023年腾讯云双11大促活动已开启&#xff0c;作为年终最大的一次优惠促销活动&#xff0c;腾讯云的优惠力度还是不错的&#xff0c;爆款云服务器首年88元&#xff0c;还有9999元大额代金券免费领取&#xff01; 一、腾讯云双11活动时间 即日起至2023-11-30 23:59:59&#xff0…

Envoy动态配置

Envoy动态配置 本节我们将学习 Envoy 的核心 - 动态配置的使用。 目录 本节实战 实战名称&#x1f6a9; 实战&#xff1a;Envoy动态配置-EDS-2023.10.31(测试成功)&#x1f6a9; 实战&#xff1a;基于 API 的动态配置-2023.11.2(测试成功) 1、基于文件的动态配置 Envoy 除了…

Python实现自动化网页操作

1 准备 推荐使用Chrome浏览器 1.1 安装selenium程序包 激活虚拟环境&#xff0c;打开新的Terminal&#xff0c;输入以下代码&#xff1a; python -m pip install selenium 如下图所示&#xff0c;表示安装成功&#xff0c;版本为4.7.2 安装成功 关闭虚拟环境&#xff0c;打…

nginx项目部署教程

nginx项目部署教程 1. 项目部署介绍 当我们的项目开发完毕后&#xff0c;我们需要将项目打包、部署到服务器上&#xff0c;供用户来使用。 目前&#xff0c;常见的部署方式有两种&#xff1a; 后端部署 前后端分离部署 1-1 后端部署 这是最古老的部署方式&#xff0c;也是…

提升ChatGPT答案质量和准确性的方法Prompt engineering

文章目录 怎么获得优质的答案设计一个优质prompt的步骤:Prompt公式:示例怎么获得优质的答案 影响模型回答精确度的因素 我们应该知道一个好的提示词,要具备一下要点: 清晰简洁,不要有歧义; 有明确的任务/问题,任务如果太复杂,需要拆分成子任务分步完成; 确保prompt中…

TSINGSEE青犀智能视频管理监督系统在车站场景中的应用方案

旭帆科技的智能视频监控系统可应对绝大多数场景&#xff0c;近期就有一个粉丝私信&#xff0c;随着年关将近&#xff0c;越来越多的人需要返乡和外出旅游&#xff0c;高铁站、火车站这些地方人员密集度高&#xff0c;发生事故的风险也大&#xff0c;问我们有没有关于车站的智能…

Python最强自动化神器Playwright!再也不用为爬虫逆向担忧了!

版权说明:本文禁止抄袭、转载,侵权必究! 目录 一、简介+使用场景二、环境部署(准备)三、代码生成器(优势)四、元素定位器(核心)五、追踪查看器(辅助)六、权限控制与认证(高级)七、其他重要功能(进阶)八、作者Info一、简介+使用场景 Playwright是什么?来自Chat…

不是我吹牛逼,这绝对是去掉 if...else 最佳的文章

我相信小伙伴一定看过多篇怎么去掉 if…else 的文章&#xff0c;也知道大家都很有心得&#xff0c;知道多种方法来去掉 if…else &#xff0c;比如 Option&#xff0c;策略模式等等&#xff0c;但我相信大明哥这篇文章绝对是最全&#xff0c;最完备怎么去掉 if…else 的文章&am…

Git保姆级教学(超详细版)

一、Git概述 Git 是一个免费的、开源的 分布式版本控制系统 &#xff0c;可以快速高效地处理从小型到大型的各种 项目。 Git 易于学习&#xff0c;占地面积小&#xff0c;性能极快。 它具有廉价的本地库&#xff0c;方便的暂存区域和多个工作 流分支等特性。其性能优于 Sub…