一、搭建配置好zookeeper集群并启动
二、搭建kafka集群
一、配置kafka环境
1.配置环境/etc/profile文件中添加
export KAFKA_HOME=/root/dev/kafka/kafka
export PATH=$PATH:$KAFKA_HOME/bin
执行命令加载文件生效
source /etc/profile
2.创建log目录 在 $KAFKA_HOME目录下创建目录 也可自定义一个目录
mkdir log
3.编辑配置文件 $KAFKA_HOME/config/server.properties 红颜色是根据自己机器的ip和端口号配置
#id 每台机器或者启动的id要不唯一
broker.id=1#192.168.37.121ip为自己机器的ip 端口号为没有用到的端口号
listeners=PLAINTEXT://192.168.37.121:9092
advertised.listeners=PLAINTEXT://192.168.37.121:9092log.dirs=/root/dev/kafka/kafka/log
# topic 在当前broker上的分片个数,与broker保持一致 有几台kafka机器就是几
num.partitions=3# 设置zookeeper集群地址与端口如下看下ip是否是自己的:
zookeeper.connect=192.168.37.121:2181,192.168.37.122:2181,1192.168.37.123:2181
4.启动命令
#启动
./kafka-server-start.sh -daemon ../config/cluster/server.properties
#创建主题cluster-topic 共3个分区,每个人去都分配3个副本:
./kafka-topics.sh --bootstrap-server localhost:9092 --create --topic cluster-topic --partitions 3 --replication-factor 3
#查看主题cluster-topic
./kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic cluster-topic
二、错误处理
1.当启动kafka 报错# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 1073741824 bytes for committing reserved memory.
# An error report file with more information is saved as:
就是虚拟机内存不够kafka-server-start.sh默认1GB内存需要自己重新分配大内存