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
相关推荐
深蓝AI6 小时前
Python 3.13 的 Queue.shutdown:异步消费者终于能正常收工了
后端
武子康6 小时前
MultiNet6 空闲崩溃:`EXCVADDR=0x8` 后又出现 `CORRUPT HEAP`
人工智能·后端·agent
武子康7 小时前
MultiNet7 每轮都 clean,ESP32-P4 内存为什么还在掉?
人工智能·后端·agent
超级架构师8 小时前
PRAXO-CORE 2.5.0:用 conformance 和显式边界构建 Go Agent 框架
开发语言·人工智能·后端·golang·ai编程·智能体框架·praxo-core
陈随易8 小时前
AI 运维服务器,安全又可靠的方法
前端·后端·程序员
IT_陈寒10 小时前
JavaScript的this坑人实录,这次我真的记下来了
前端·人工智能·后端
starzy199011 小时前
Scala类和对象:从构造器到样例类的完整指南
开发语言·后端·scala
梦影_11 小时前
MySQL进阶教程(五)—— SQL调优(下)
android·大数据·数据库·后端·sql·mysql·database
考虑考虑11 小时前
mariadb数据库
数据库·后端·mariadb
明月_清风11 小时前
用自然语言操控真机:Google Artemis 移动端 AI Agent 上手与实践
人工智能·后端