CentOS 7 搭建Kafka集群

CentOS 7 搭建Kafka集群

img

服务器环境准备

IP OS JDK
192.168.1.25 CentOS 7.9 1.8
192.168.1.28 CentOS 7.9 1.8
192.168.1.22 CentOS 7.9 1.8

下载Kafka包

官网: https://kafka.apache.org/downloads

下载地址:https://downloads.apache.org/kafka/3.4.0/kafka_2.13-3.4.0.tgz

在每台服务器执行已下操作

# 下载文件
wget  https://downloads.apache.org/kafka/3.4.0/kafka_2.13-3.4.0.tgz
# 解压到 /usr/local
tar -zxvf  kafka_2.13-3.4.0.tgz  -C  /usr/local

配置Zookeeper

修改配置文件

vi /usr/local/kafka_2.13-3.4.0/config/zookeeper.properties

修改完成后的配置,将此配置同步到其它两台服务器中

# 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.
# the directory where the snapshot is stored.
dataDir=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181
# disable the per-ip limit on the number of connections since this is a non-production config
maxClientCnxns=0
# Disable the adminserver by default to avoid port conflicts.
# Set the port to something non-conflicting if choosing to enable this
admin.enableServer=false
#admin.serverPort=8080
initLimit=10
syncLimit=5
tickTime=2000
server.0=192.168.1.25:12888:13888
server.1=192.168.1.28:12888:13888
server.2=192.168.1.22:12888:13888

创建 myid文件

需要和上面配置文件中 server.0=192.168.1.25:12888:13888 server.1=192.168.1.28:12888:13888 server.2=192.168.1.22:12888:13888 相对应;

192.168.1.25

mkdir  /tmp/zookeeper 
echo 0 > /tmp/zookeeper/myid

192.168.1.28

mkdir  /tmp/zookeeper 
echo 1 > /tmp/zookeeper/myid

192.168.1.22

mkdir  /tmp/zookeeper 
echo 2 > /tmp/zookeeper/myid

配置kafka

vi /usr/local/kafka_2.12-3.4.0/config/server.properties

192.168.1.25

broker.id=0
listeners=PLAINTEXT://192.168.1.25:9092
host.name=192.168.1.25
advertised.listeners=PLAINTEXT://192.168.1.25:9092
zookeeper.connect=localhost:2181,192.168.1.28:2181,192.168.1.22:2181

192.168.1.28

broker.id=1
listeners=PLAINTEXT://192.168.1.28:9092
host.name=192.168.1.28
advertised.listeners=PLAINTEXT://192.168.1.28:9092
zookeeper.connect=localhost:2181,192.168.1.25:2181,192.168.1.22:2181

192.168.1.22

broker.id=2
listeners=PLAINTEXT://192.168.1.22:9092
host.name=192.168.1.22
advertised.listeners=PLAINTEXT://192.168.1.22:9092
zookeeper.connect=localhost:2181,192.168.1.25:2181,192.168.1.28:2181

启动服务

启动zookeeper集群(分别在三台服务器上执行)

# 前台启动(用于测试,无异常使用可使用后台启动)
./bin/zookeeper-server-start.sh  config/zookeeper.properties 
# 后台启动
./bin/zookeeper-server-start.sh -daemon config/zookeeper.properties 

启动kafka集群(分别在三台服务器上执行,zookeeper集群已启动)

# 前台启动
./bin/kafka-server-start.sh config/server.properties 
# 后台启动
./bin/kafka-server-start.sh -daemon config/server.properties 

测试一下

我这里用的是GUI工具 Offset Explorer ,也可以安装web 版本Kafka-Manager

连接

image

可以看到三个节点

image

创建一个Topic

image

posted @   时光煮酒丶  阅读(185)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
点击右上角即可分享
微信分享提示