kafka0.10.0.0版本安裝
1、下載https://www.apache.org/dyn/closer.cgi?path=/kafka/0.10.0.0/kafka_2.11-0.10.0.0.tgz
2、解壓
tar -zxvf kafka_2.11-0.10.0.0.tgz
3、cd /usr/local/wl/kafka/kafka_2.11-0.10.0.0
4、啟動zookeeper
bin/zookeeper-server-start.sh config/zookeeper.properties
5、開啟kafka服務
bin/kafka-server-start.sh config/server.properties
出現:
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000b5a00000, 1073741824, 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 1073741824 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /tmp/jvm-4499/hs_error.log
解決辦法: 將 kafka-server-start.sh的 export KAFKA_HEAP_OPTS="-Xmx1G -Xms1G" 修改為 export KAFKA_HEAP_OPTS="-Xmx256M -Xms128M"
6、釋出主題
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic kafkatopic
列出topic bin/kafka-topics.sh --list --zookeeper localhost:
7、建立生產者
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic kafkatopic
8、建立消費者
bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic kafkatopic --from-beginning
9、測試
在生產者端輸入訊息回車,然後檢視消費者端是否已經接收到訊息