美文网首页
Kafka 安装教程 + nodejs 连接

Kafka 安装教程 + nodejs 连接

作者: lihao_李浩 | 来源:发表于2020-12-09 09:18 被阅读0次

安装java1.8.0

yum -y install java-1.8.0*

下载安装包:

1、kafka安装包
http://kafka.apache.org/downloads

image.png

2、zookeeper安装包
https://zookeeper.apache.org/releases.html#download

image.png

解压安装

1、先安装运行zookeeper

tar -zxvf apache-zookeeper-3.6.2-bin.tar.gz
cd ./apache-zookeeper-3.6.2-bin
cp ./conf/zoo_sample.cfg ./conf/zoo.cfg
./bin/zkServer.sh start

2、安装运行kafka

tar -zxvf kafka_2.12-2.6.0.tgz
cd kafka_2.12-2.6.0
vim ./config/server.properties
# 修改看下图
./bin/kafka-server-start.sh ./config/server.properties
# 后台运行 nohup ./bin/kafka-server-start.sh ./config/server.properties > /dev/null 2>&1 &

修改下图ip
advertised.listeners=PLAINTEXT://71.24.89.191:9092


image.png

检测是否安装成功

这里主要是检测对应的端口是否是打开状态
分别是 zookeeper的默认端口 2181 和 kafka的 9092
检测网址

image.png
如果都是开启状态,就可以了

添加修改topic主题

1、 添加

bin/kafka-topics.sh --zookeeper localhost:2181 --create --replication-factor 1 --partitions 1 --topic test

2、查看所有主题

bin/kafka-topics.sh --zookeeper localhost:2181 --list

3、查看主题下所有分区

bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic test

4、动态 修改主题 分区为12

bin/kafka-topics.sh --alter --zookeeper localhost:2181 --topic test --partitions 12
image.png

Nodejs 连接

小伙伴们可以看我另一片文章
Nodejs kafka连接

常见错误

1、内存不足
这里因为我的机器的内存比较小
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000e0000000, 536870912, 0) failed; error='Cannot allocate memory' (errno=12)

There is insufficient memory for the Java Runtime Environment to continue.
Native memory allocation (mmap) failed to map 536870912 bytes for committing reserved memory.

image.png

我们只需要把kafka启动脚本修改一下就可以了

vim ./bin/kafka-server-start.sh

修改内存为256:


image.png

相关文章

网友评论

      本文标题:Kafka 安装教程 + nodejs 连接

      本文链接:https://www.haomeiwen.com/subject/dzicgktx.html