kafka 3.5.0 raft协议安装

前言

最近做项目,需要使用kafka进行通信,且只能使用kafka,笔者没有测试集群,就自己搭建了kafka集群,实际上笔者在很早之前就搭建了,因为当时还是zookeeper(简称ZK)注册元数据,现在新版kafka(3.0.0开始)已经自带了元数据能力(使用raft协议)减少了kafka对zk的依赖性。笔者在查询资料发现,说jdk至少jdk11,实测jdk8也能运行,且并不需要网上说的3+4节点,3+3即可,当然理论上broker节点越多越好,但是元数据节点建议3、5个最合适,raft的过半一致性和容错性的综合取舍。

准备

准备kafka安装包:Apache Kafka

笔者使用的kafka 3.5.0和scala 2.13,采用3台虚拟机,当然容器也不是不行,注意持久化pv pvc和配置的管理(ip换成域名,dns的切换支持),中间件建议使用虚拟机,可以降低很多容错性。

jdk使用open jdk,配置java_home和path,以Ubuntu为例

 sudo apt install openjdk-8-jdk-headless

以macOS为例,创建一个ubuntu-server 最小安装的虚拟机(vmware,毕竟个人使用不要钱),然后安装openssh 和 openjdk,然后shutdown now

网络选择桥接,相当于一台“真实在”网络上的一台物理机

这样就得到了

192.168.0.108

192.168.0.107

192.168.0.106

3台虚拟机

步骤

先看kafka集群的架构图,实际上安装的过程就是架构图的执行过程

 

从图中可以看出已经没有zk的存在了,从kafka节点自己管理元数据,通过raft协议选主的方式。

1. kafka的准备

上传kafka安装包,必须是二进制安装包,不要源码包,编译比较麻烦,然后解压

tar -zxvf  kafka_2.13-3.5.0.gz

查看配置目录会发现

明显多了kraft的配置目录,那么如果使用kafka raft元数据中心,则需要修改kraft目录,启动时指定kraft目录的配置

2. 配置修改

raft协议实际上跟zk差不多,使用raft协议的中间件就太多了,但是本质上每个节点都需要一个唯一id,zk也是如此,所以kafka kraft就相当于集成的zk。

在kraft下的有3个文件文件,其中启动相关的是server.properties中

执行配置修改


# The role of this server. Setting this puts us in KRaft mode
process.roles=broker,controller# The node id associated with this instance's roles
node.id=1# The connect string for the controller quorum
controller.quorum.voters=1@localhost:9093############################# Socket Server Settings ############################## The address the socket server listens on.
# Combined nodes (i.e. those with `process.roles=broker,controller`) must list the controller listener here at a minimum.
# If the broker listener is not defined, the default listener will use a host name that is equal to the value of java.net.InetAddress.getCanonicalHostName(),
# with PLAINTEXT listener name, and port 9092.
#   FORMAT:
#     listeners = listener_name://host_name:port
#   EXAMPLE:
#     listeners = PLAINTEXT://your.host.name:9092
listeners=PLAINTEXT://:9092,CONTROLLER://:9093# Name of listener used for communication between brokers.
inter.broker.listener.name=PLAINTEXT# Listener name, hostname and port the broker will advertise to clients.
# If not set, it uses the value for "listeners".
advertised.listeners=PLAINTEXT://localhost:9092# A comma-separated list of the names of the listeners used by the controller.
# If no explicit mapping set in `listener.security.protocol.map`, default will be using PLAINTEXT protocol
# This is required if running in KRaft mode.
controller.listener.names=CONTROLLER# Maps listener names to security protocols, the default is for them to be the same. See the config documentation for more details
listener.security.protocol.map=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL# The number of threads that the server uses for receiving requests from the network and sending responses to the network
num.network.threads=3# The number of threads that the server uses for processing requests, which may include disk I/O
num.io.threads=8# The send buffer (SO_SNDBUF) used by the socket server
socket.send.buffer.bytes=102400# The receive buffer (SO_RCVBUF) used by the socket server
socket.receive.buffer.bytes=102400# The maximum size of a request that the socket server will accept (protection against OOM)
socket.request.max.bytes=104857600############################# Log Basics ############################## A comma separated list of directories under which to store log files
log.dirs=/tmp/kraft-combined-logs# The default number of log partitions per topic. More partitions allow greater
# parallelism for consumption, but this will also result in more files across
# the brokers.
num.partitions=1# The number of threads per data directory to be used for log recovery at startup and flushing at shutdown.
# This value is recommended to be increased for installations with data dirs located in RAID array.
num.recovery.threads.per.data.dir=1############################# Internal Topic Settings  #############################
# The replication factor for the group metadata internal topics "__consumer_offsets" and "__transaction_state"
# For anything other than development testing, a value greater than 1 is recommended to ensure availability such as 3.
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1############################# Log Flush Policy ############################## Messages are immediately written to the filesystem but by default we only fsync() to sync
# the OS cache lazily. The following configurations control the flush of data to disk.
# There are a few important trade-offs here:
#    1. Durability: Unflushed data may be lost if you are not using replication.
#    2. Latency: Very large flush intervals may lead to latency spikes when the flush does occur as there will be a lot of data to flush.
#    3. Throughput: The flush is generally the most expensive operation, and a small flush interval may lead to excessive seeks.
# The settings below allow one to configure the flush policy to flush data after a period of time or
# every N messages (or both). This can be done globally and overridden on a per-topic basis.# The number of messages to accept before forcing a flush of data to disk
#log.flush.interval.messages=10000# The maximum amount of time a message can sit in a log before we force a flush
#log.flush.interval.ms=1000############################# Log Retention Policy ############################## The following configurations control the disposal of log segments. The policy can
# be set to delete segments after a period of time, or after a given size has accumulated.
# A segment will be deleted whenever *either* of these criteria are met. Deletion always happens
# from the end of the log.# The minimum age of a log file to be eligible for deletion due to age
log.retention.hours=168# A size-based retention policy for logs. Segments are pruned from the log unless the remaining
# segments drop below log.retention.bytes. Functions independently of log.retention.hours.
#log.retention.bytes=1073741824# The maximum size of a log segment file. When this size is reached a new log segment will be created.
log.segment.bytes=1073741824# The interval at which log segments are checked to see if they can be deleted according
# to the retention policies
log.retention.check.interval.ms=300000

每一行都有注释,重点关注

笔者设定

192.168.0.106 nodeid 1 

192.168.0.107 nodeid 2

192.168.0.108 nodeid 3

至此配置基本上完成,同理一个节点可以同时是controller和broker,也可以仅仅是controller或者broker,因为controller的负载比较轻,所以一般是和broker一起。其中有个log.dir这个的路径是下面元数据生成的路径(选主)和数据事务日志,索引日志的存储目录

3. 启动

1. 生成uuid

任意找一个节点执行:

./kafka-storage.sh random-uuid

每次执行uuid会不一样,这个uuid标识是一个集群,所以所有节点公用一个uuid,不要每个节点重新生成,会识别不了 

 

然后执行format,如下标红是我生成的,这个每次不是固定的

 ./kafka-storage.sh format -t gZzkfRm4T1y8wSAY-ZNG5Q -c ../config/kraft/server.properties  

 格式化配置文件,同步其他节点

配置文件有什么变化?在日志配置的目录下出现

关键还是meta的文件,有集群id和节点id,版本号,这个对启动至关重要。

即在上面的log.dir的目录生成,所以尽量不能使用临时目录

2. 启动

启动就很简单了,使用刚刚配置的server.properties执行启动即可

./kafka-server-start.sh -daemon ../config/kraft/server.properties

不过为了方便查看启动日志,建议执行日志的console文件输出

 先看事务日志和索引

验证

验证很简单,查看bin同级目录下的日志即可

日志带有[2025-02-08 08:34:12,286] INFO [KafkaRaftServer nodeId=1] Kafka Server started (kafka.server.KafkaRaftServer) 

如果生成用途可以安装kafka的控制台,kafka-ui,不过我这里就不安装了,因为docker安装比较容易。

总结

kafka从3.0.0开始推出了raft模式的元数据中心,实际上类似zk,kafka自己命名kraft。使用这种方式搭建kafka集群将不再需要zk,同理,kafka的集群的每个节点可以同时是broker和controller(以前zk充当),也可以是单独的broker,controller(负载不重,不建议单独controller,跟zk没区别),官方说明需要jdk11及以上,实测jdk8可以运行,但是生成建议严格按照官方标定的jdk执行,jdk是向下兼容的,但是不确定是否会涉及新api或新特性的使用。

另外实际使用中,可能会涉及使用iptables做nat限制kafka的连接方,比如在kafka节点通过iptables限制发送者或者消费端的ip

iptables -t nat -A PREROUTING -p tcp -m tcp --dport 9093 -j DNAT --to-destination kafkaxxx:9093

kafkaxxx --- 指定的是 Kafka 服务所在的机器地址

如果kafka是对接方提供,则在nat打通时,需要客户端连接的服务器也执行iptables,否则可能出现连接kafka正常,但是不能消费。

iptables -t nat -A POSTROUTING -p tcp -m tcp --dport 9093 -j SNAT --to-source natxxx

natxxx --- 指定的是配置 iptables 的本机的地址

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

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

相关文章

Unity项目接入xLua的一种流程

1. 导入xlua 首先导入xlua,这个不用多说 2. 编写C#和Lua交互脚本 基础版本,即xlua自带的版本 using System.Collections; using System.Collections.Generic; using UnityEngine; using XLua; using System; using System.IO;[Serializable] public…

四次挥手详解

文章目录 一、四次挥手各状态FIN_WAIT_1CLOSE_WAITFIN_WAIT_2LAST_ACKTIME_WAITCLOSE 二、双方同时调用close(),FIN_WAIT_1状态后进入CLOSING状态CLOSING状态 三、TIME_WAIT状态详解(1) TIME_WAIT状态下的2MSL是什么MSL (报文最大生存时间)为…

【嵌入式 Linux 音视频+ AI 实战项目】瑞芯微 Rockchip 系列 RK3588-基于深度学习的人脸门禁+ IPC 智能安防监控系统

前言 本文主要介绍我最近开发的一个个人实战项目,“基于深度学习的人脸门禁 IPC 智能安防监控系统”,全程满帧流畅运行。这个项目我目前全网搜了一圈,还没发现有相关类型的开源项目。这个项目只要稍微改进下,就可以变成市面上目前…

java: framework from BLL、DAL、IDAL、MODEL、Factory using oracle

oracel 21c sql: -- 创建 School 表 CREATE TABLE School (SchoolId CHAR(5) NOT NULL,SchoolName NVARCHAR2(500) NOT NULL,SchoolTelNo VARCHAR2(8) NULL,PRIMARY KEY (SchoolId) );CREATE OR REPLACE PROCEDURE addschool(p_school_id IN CHAR,p_school_name IN NVARCHAR2,p…

1.攻防世界 baby_web

题目描述这里有提示,初始页面 进入题目页面如下 很简洁的页面只有一行HELLO WORLD ctrlu查看了源码也没有信息 用burp suite抓包,并发送到重放器 根据提示(初始页面)修改访问index.php文件 index.php index.php 是一种常见的…

什么是三层交换技术?与二层有什么区别?

什么是三层交换技术?让你的网络飞起来! 一. 什么是三层交换技术?二. 工作原理三. 优点四. 应用场景五. 总结 前言 点个免费的赞和关注,有错误的地方请指出,看个人主页有惊喜。 作者:神的孩子都在歌唱 大家好…

【机器学习】数据预处理之数据归一化

数据预处理之数据归一化 一、摘要二、数据归一化概念三、数据归一化实现方法3.1 最值归一化方法3.2 均值方差归一化方法 一、摘要 本文主要讲述了数据归一化(Feature Scaling)的重要性及其方法。首先通过肿瘤大小和发现时间的例子,说明了不同…

【AIGC】语言模型的发展历程:从统计方法到大规模预训练模型的演化

博客主页: [小ᶻ☡꙳ᵃⁱᵍᶜ꙳] 本文专栏: AIGC | ChatGPT 文章目录 💯前言💯语言模型的发展历程:从统计方法到大规模预训练模型的演化1 统计语言模型(Statistical Language Model, SLM):统…

Java面试题2025-JVM

JVM 1.为什么需要JVM,不要JVM可以吗? 1.JVM可以帮助我们屏蔽底层的操作系统 一次编译,到处运行 2.JVM可以运行Class文件 2.JDK,JRE以及JVM的关系 3.我们的编译器到底干了什么事? 仅仅是将我们的 .java 文件转换成了…

Deepseek的MLA技术原理介绍

DeepSeek的MLA(Multi-head Latent Attention)技术是一种创新的注意力机制,旨在优化Transformer模型的计算效率和内存使用,同时保持模型性能。以下是MLA技术的详细原理和特点: 1. 核心思想 MLA技术通过低秩联合压缩技术,将多个注意力头的键(Key)和值(Value)映射到一…

QML初识

目录 一、关于QML 二、布局定位和锚点 1.布局定位 2.锚点详解 三、数据绑定 1.基本概念 2.绑定方法 3.数据模型绑定 四、附加属性及信号 1.附加属性 2.信号 一、关于QML QML是Qt框架中的一种声明式编程语言,用于描述用户界面的外观和行为;Qu…

java项目之美妆产品进销存管理系统的设计与开发源码(ssm+mysql)

项目简介 美妆产品进销存管理系统的设计与开发实现了以下功能: 美妆产品进销存管理系统的设计与开发的主要使用者分为管理员登录后修改个人的密码。产品分类管理中,对公司内的所有产品分类进行录入,也可以对产品分类进行修改和删除。产品管…

Python(pymysql包)操作MySQL【增删改查】

下载pymysql: pip install pymysql 在MySQL中创建数据库:unicom create database unicom DEFAULT CHARSET utf8 COLLATE utf8_general_ci;use unicom; 在unicom中创建数据表:admin create table admin(id int not null primary key auto_i…

HTTP无状态的概念以及对后端服务的设计会产生的影响

HTTP无状态(Statelessness) 是指每个HTTP请求都是独立的,服务器不会记住或依赖于前一个请求的任何信息。每次请求的处理都与其他请求没有直接关系。也就是说,服务器在处理请求时,不会存储关于客户端状态的信息。 一、HTTP无状态的具体含义 ①每个请求独立:每个请求包含了…

操作系统—进程与线程

补充知识 PSW程序状态字寄存器PC程序计数器:存放下一条指令的地址IR指令寄存器:存放当前正在执行的指令通用寄存器:存放其他一些必要信息 进程 进程:进程是进程实体的运行过程,是系统进行资源分配和调度的一个独立单位…

【基于SprintBoot+Mybatis+Mysql】电脑商城项目之上传头像和新增收货地址

🧸安清h:个人主页 🎥个人专栏:【Spring篇】【计算机网络】【Mybatis篇】 🚦作者简介:一个有趣爱睡觉的intp,期待和更多人分享自己所学知识的真诚大学生。 目录 🚀1.上传头像 -持久…

Windows下ollama详细安装指南

文章目录 1、Windows下ollama详细安装指南1.1、ollama介绍1.2、系统要求1.3、下载安装程序1.4、安装步骤1.5、验证安装1.6、环境变量配置1.7、模型选择与安装【deepseek 示例】1.7.1、拉取并运行模型1.7.2、进阶使用技巧 1、Windows下ollama详细安装指南 1.1、ollama介绍 olla…

10vue3实战-----实现登录的基本功能

10vue3实战-----实现登录的基本功能 1.基本页面的搭建2.账号登录的验证规则配置3.点击登录按钮4.表单的校验5.账号的登录逻辑和登录状态保存6.定义IAccount对象类型 1.基本页面的搭建 大概需要搭建成这样子的页面: 具体的搭建界面就不多讲。各个项目都有自己的登录界面&#…

vue3 点击图标从相册选择二维码图片,并使用jsqr解析二维码(含crypto-js加密解密过程)

vue3 点击图标从相册选择二维码图片,并使用jsqr解析二维码(含crypto-js加密解密过程) 1.安装 jsqr 和 crypto-js npm install -d jsqr npm install crypto-js2.在util目录下新建encryptionHelper.js文件,写加密解密方法。 // e…

支持多种网络数据库格式的自动化转换工具——VisualXML

一、VisualXML软件介绍 对于DBC、ARXML……文件的编辑、修改等繁琐操作,WINDHILL风丘科技开发的总线设计工具——VisualXML,可轻松解决这一问题,提升工作效率。 VisualXML是一个强大且基于Excel表格生成多种网络数据库文件的转换工具&#…