Kafka安装教程

KAFKA

1、安装JDK

(1)解压tar.gz

shell 复制代码
tar -zxvf jdk-8u321-linux-x64.tar.gz

(2)配置环境变量

shell 复制代码
export JAVA_HOME=/opt/jdk/jdk1.8.0_321
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:${PATH}

2、安装Zookeeper

(1)解压zookeeper安装包

shell 复制代码
tar -zxvf apache-zookeeper-3.5.7-bin.tar.gz

(2)将conf/zoo_sample.cfg复制为zoo.cfg,并修改zk的数据存储位置

shell 复制代码
#将zoo_sample.cfg复制一份,重命名为zoo.cfg
cp conf/zoo_sample.cfg  conf/zoo.cfg

#在解压目录下新建目录data
mkdir data

#data下新建文件myid
touch data/myid

#编辑myid,写一个1。myid在zkServer集群中才有用,单机版zkServer可以不配置
vim data/myid

vim conf/zoo.cfg

# The number of milliseconds of each tick
tickTime=2000  #心跳间隔,每隔2000ms即2s发送一次心跳
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10  #10*2s=20s,如果连续10次即20s内没有收到某个服务节点的心跳,就认为该节点挂掉了
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5  #follower从leader同步数据时,发送同步请求后,如果5个心跳时间即10s内没有收到leader的确认应答,就认为本次同步请求失败
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
#dataDir=/tmp/zookeeper
dataDir=/usr/local/apache-zookeeper-3.6.0-bin/data  #数据存储位置
# the port at which the clients will connect
clientPort=2181  #zk client与zk server通信使用的端口号
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60  #zk client的最大数量

(3)防火墙开放指定端口给zk client连接

shell 复制代码
firewall-cmd --add-port=2181/tcp --zone=public --permanent 

firewall-cmd --reload

(4)启动

shell 复制代码
./zkServer.sh  start

start #启动

stop #停止

restart #重启

status #查看状态

version #查看zk server的版本

(5)测试

shell 复制代码
./zkCli -server 192.168.1.9:2181

3、安装Kafka

(1)解压kafka安装包

shell 复制代码
tar -zxvf kafka_2.12-3.0.0.tgz

(2)修改/conf/server.properties

shell 复制代码
log.dirs=/opt/moudle/kafka/datas

(3)启动

shell 复制代码
./kafka-server-start.sh -daemon ../config/server.properties

(4)创建topic

shell 复制代码
./kafka-topics.sh  --bootstrap-server localhost:9092 --topic test  --create  --replication-factor 1 --partitions 1

(5)启动消费端

shell 复制代码
./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test

(6)启动生产者

shell 复制代码
./kafka-console-producer.sh --bootstrap-server localhost:9092 --topic test
相关推荐
牛奔2 小时前
Go 如何避免频繁抢占?
开发语言·后端·golang
想用offer打牌6 小时前
MCP (Model Context Protocol) 技术理解 - 第二篇
后端·aigc·mcp
KYGALYX8 小时前
服务异步通信
开发语言·后端·微服务·ruby
掘了8 小时前
「2025 年终总结」在所有失去的人中,我最怀念我自己
前端·后端·年终总结
爬山算法8 小时前
Hibernate(90)如何在故障注入测试中使用Hibernate?
java·后端·hibernate
Moment9 小时前
富文本编辑器在 AI 时代为什么这么受欢迎
前端·javascript·后端
Cobyte10 小时前
AI全栈实战:使用 Python+LangChain+Vue3 构建一个 LLM 聊天应用
前端·后端·aigc
程序员侠客行10 小时前
Mybatis连接池实现及池化模式
java·后端·架构·mybatis
Honmaple11 小时前
QMD (Quarto Markdown) 搭建与使用指南
后端
PP东11 小时前
Flowable学习(二)——Flowable概念学习
java·后端·学习·flowable