必须安装zookeeper。Linux安装zookeeper
kafka官网下载页面
# 版本:kafka_2.11-2.3.0.tgz
wget 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.tgz
cp kafka_2.11-2.3.0 /usr/local/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.sh
vim kafka-server-start.sh
设置内容根据自己情况进行设置。
# 名为test的chart,只有一个副本,一个分区
kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic chart
# 查看kafka的topic
kafka-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
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。