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目录下复制两个server.properties
cd config/
cp server.properties server1.properties
cp server.properties server2.properties
3、修改三个properties里的内容
注意:
kafka 标识 id : 1~3
kafka 端口号范围:9001~9003
log.dirs 目录名称: log1~log3
zookeeper.connect 三台一样。
4、启动 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、启动可能会报错:
错误提示:
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"
因为我的内存是2G
6、测试
创建一个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