必須安裝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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。