千家信息网

Linux下安装kafka

发表于:2025-02-05 作者:千家信息网编辑
千家信息网最后更新 2025年02月05日,前置条件必须安装zookeeper。Linux安装zookeeperkafka官方源kafka官网下载页面下载kafka安装包# 版本:kafka_2.11-2.3.0.tgzwget http://
千家信息网最后更新 2025年02月05日Linux下安装kafka

前置条件

必须安装zookeeper。Linux安装zookeeper

kafka官方源

kafka官网下载页面

下载kafka安装包

# 版本:kafka_2.11-2.3.0.tgzwget http://mirrors.tuna.tsinghua.edu.cn/apache/kafka/2.3.0/kafka_2.11-2.3.0.tgz

解压安装包

tar -zxvf kafka_2.11-2.3.0.tgzcp kafka_2.11-2.3.0 /usr/local/kafka

启动kafka服务

cd /usr/local/kafka/bin# 启动命令:守护进程进行启动./kafka-server-start.sh -daemon ../config/server.properties 

备注:这里有可能报错,因为默认情况下,kafka默认的内存要1G,如果你这里没有这么多内存可用,那么就会启动失败。报错如下:

Java Hotspot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c5330000, 986513408, 0) failed; error='Cannot allocate memory' (errno=12)## There is insufficient memory for the Java Runtime Environment to continue.# Native memory allocation (malloc) failed to allocate 986513408 bytes for committing reserved memory.# An error report file with more information is saved as:# hs_err_pid5535.log

解决方案

修改启动脚本:kafka-server-start.shvim kafka-server-start.sh


设置内容根据自己情况进行设置。

创建一个topic

# 名为test的chart,只有一个副本,一个分区kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic chart# 查看kafka的topickafka-topics.sh -list -zookeeper localhost:2181

生产、消费测试

# 启动生产端./kafka-console-producer.sh --broker-list localhost:9092 --topic chart#启动消费端./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic chart --from-beginning



0