centos搭建kafka集群
安装zookeeper
参考文档:https://blog.csdn.net/zhangchaoyang/article/details/124079541
下载地址:https://zookeeper.apache.org/releases.html
1. 安装jdk
export JAVA_HOME=/opt/jdk1.8.0_341 export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin export PATH=$PATH:${JAVA_PATH}
2. 安装zookeeper
准备三台机器
63 tar -xvf apache-zookeeper-3.5.10-bin.tar.gz 65 cd apache-zookeeper-3.5.10-bin/conf 69 mv zoo_sample.cfg zoo.cfg
创建数据目录
73 mkdir /data/zookeeper/data -p
修改配置文件
vim zoo.cfg
# The number of milliseconds of each tick tickTime=2000 # The number of ticks that the initial # synchronization phase can take initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=5 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. dataDir=/data/zookeeper/data # the port at which the clients will connect # 2181 : 对 client 端提供服务 clientPort=2181 # the maximum number of client connections. # increase this if you need to handle more clients maxClientCnxns=2000 # Be sure to read the maintenance section of the # administrator guide before turning on autopurge. # # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance # # The number of snapshots to retain in dataDir #autopurge.snapRetainCount=3 # Purge task interval in hours # Set to "0" to disable auto purge feature #autopurge.purgeInterval=1 admin.serverPort=8888 # 2888 : 集群内机器通信使用 # 3888 : 选举 leader 使用(Leader监听此端口) server.1=192.168.50.208:2888:3888 server.2=192.168.50.209:2888:3888 server.3=192.168.50.210:2888:3888
在每个 zookeeper 的 data 目录下创建一个 myid 文件,内容分别是 1、2、3,对应 zoo.cfg 文件中的 server.1、server.2、server.3 三台服务器。
82 echo 1 >myid 72 echo 2 >myid 72 echo 3 >myid
启动zookeeper
77 ./zkServer.sh start 78 sh zkServer.sh status 79 jps -l 80 ll 81 tail -f ../logs/zookeeper-root-server-controller.out
连接zookeeper集群
使用 PrettyZoo 连接 zookeeper
PrettyZoo GitHub地址:GitHub PrettyZoo
PrettyZoo 下载地址:Releases · vran-dev/PrettyZoo · GitHub
安装kafka
Kafka下载
参考文档:https://blog.csdn.net/zhangchaoyang/article/details/124082608
下载地址:https://kafka.apache.org/downloads
修改配置文件
每台服务器的 broker.id 必须唯一,host.name=ip 是新增的一行配置,避免本来连接虚拟机中的Kafka服务器报错。
在配置zookeeper 的连接地址时,后面需要加上 /kafka ,这样Kafka 的相关配置就在zookeeper的 /kafka 节点下。
# Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # This configuration file is intended for use in ZK-based mode, where Apache ZooKeeper is required. # See kafka.server.KafkaConfig for additional details and defaults # ############################# Server Basics ############################# # The id of the broker. This must be set to a unique integer for each broker. broker.id=2 ############################# Socket Server Settings ############################# # The address the socket server listens on. If not configured, the host name will be 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://192.168.64.12:9092 # Listener name, hostname and port the broker will advertise to clients. # If not set, it uses the value for "listeners". advertised.listeners=PLAINTEXT://192.168.64.12:9092 # 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=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=6 # 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=10240000 # The receive buffer (SO_RCVBUF) used by the socket server socket.receive.buffer.bytes=10240000 # 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=/opt/kafka/kafka_2.12-3.6.2/data # 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. # 与集群内broker数量相同 num.partitions=3 # 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=3 ############################# 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. # 组元数据内部主题“__consumer_offsets”和“__transaction_state”的复制因子 offsets.topic.replication.factor=3 transaction.state.log.replication.factor=3 transaction.state.log.min.isr=3 ############################# 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=5000 ############################# 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 ############################# Zookeeper ############################# # Zookeeper connection string (see zookeeper docs for details). # This is a comma separated host:port pairs, each corresponding to a zk # server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002". # You can also append an optional chroot string to the urls to specify the # root directory for all kafka znodes. zookeeper.connect=192.168.50.64:10,192.168.64.11:2181,192.168.64.12:2181/kafka # Timeout in ms for connecting to zookeeper # 超过18s未连接触发kafka选举 zookeeper.connection.timeout.ms=18000 ############################# Group Coordinator Settings ############################# # The following configuration specifies the time, in milliseconds, that the GroupCoordinator will delay the initial consumer rebalance. # The rebalance will be further delayed by the value of group.initial.rebalance.delay.ms as new members join the group, up to a maximum of max.poll.interval.ms. # The default value for this is 3 seconds. # We override this to 0 here as it makes for a better out-of-the-box experience for development and testing. # However, in production environments the default value of 3 seconds is more suitable as this will help to avoid unnecessary, and potentially expensive, rebalances during application startup. group.initial.rebalance.delay.ms=0
启动
110 ./kafka-server-start.sh -daemon ../config/server.properties
安装kafka tools: https://www.kafkatool.com/
越学越感到自己的无知
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!