kafka安装

Posted Sysnap 谢奕智

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了kafka安装相关的知识,希望对你有一定的参考价值。

1 下载解压

http://kafka.apache.org/downloads.html 选择合适的包

wget -q http://www-us.apache.org/dist/kafka/0.11.0.0/kafka_2.11-0.11.0.0.tgz

tar -xzvf kafka_2.11-0.11.0.0.tgz

rm kafka_2.11-0.11.0.0.tgz 

 

2 启动

cd kafka_2.11-0.11.0.0

启动zookeeper

bin/zookeeper-server-start.sh config/zookeeper.properties & 

可能会提示下面的错误

[email protected] kafka_2.11-0.11.0.0]# Java HotSpot(TM) 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.
# An error report file with more information is saved as:
# /home/kafaka/kafka_2.11-0.11.0.0/hs_err_pid22906.log

可以修改 bin/zookeeper-server-start.sh   里面的内存大小,这里指为128M, export KAFKA_HEAP_OPTS="-Xmx128M -Xms128M"

启动kafka 

bin/kafka-server-start.sh config/server.properties &

可能会报如下错误

[2017-08-21 03:53:36,632] FATAL [Kafka Server 0], Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer)
java.net.UnknownHostException: host.localdomain: host.localdomain: Name or service not known
at java.net.InetAddress.getLocalHost(InetAddress.java:1505)

修改/etc/host

127.0.0.1 host.localdomain localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 host.localdomain localhost localhost.localdomain localhost6 localhost6.localdomain6

 

3 停止

停止Kafka server bin/kafka-server-stop.sh
停止Zookeeper server: bin/zookeeper-server-stop.sh

 

4 测试连通性

运行producer: bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test 

运行consumer: bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning

在producer端输入字符串并回车,查看consumer端是否显示。

 

以上是关于kafka安装的主要内容,如果未能解决你的问题,请参考以下文章

Kafka

linux安装kafka

Kafka入门系列——Kafka环境安装

linux环境kafka安装及配置

2. kafka安装

Kafka的入门及安装使用