1、新建kafka目錄及下載解壓
mkdir /usr/local/kafka
wget https://mirrors.cnnic.cn/apache/kafka/1.0.0/kafka_2.12-1.0.0.tgz
tar -zxvf?kafka_2.12-1.0.0.tgz
2、到config目錄下復(fù)制兩個(gè)server.properties
cd config/
cp server.properties server1.properties
cp server.properties server2.properties
3、修改三個(gè)properties里的內(nèi)容



注意:
kafka 標(biāo)識(shí) id : 1~3
kafka 端口號(hào)范圍:9001~9003
log.dirs 目錄名稱: log1~log3
zookeeper.connect 三臺(tái)一樣。
4、啟動(dòng) Kafka 集群
bin/kafka-server-start.sh?config/server.properties?&???
bin/kafka-server-start.sh?config/server1.properties?&?
bin/kafka-server-start.sh?config/server2.properties?&??
5、啟動(dòng)可能會(huì)報(bào)錯(cuò):
錯(cuò)誤提示:
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的
export KAFKA_HEAP_OPTS="-Xmx1G -Xms1G"
修改為
export KAFKA_HEAP_OPTS="-Xmx256M -Xms128M"
因?yàn)槲业膬?nèi)存是2G
6、測(cè)試
創(chuàng)建一個(gè)topic
bin/kafka-topics.sh --create --zookeeper 172.16.59.150:2181 --replication-factor 3 --partitions 1 --topic test-replicated-topic??
查看topic
bin/kafka-topics.sh --list --zookeeper 172.16.59.150:2183
ps:172.16.59.150是我zookeeper偽集群ip
