基于ZK的kafka环境搭建
Kafka
环境:Window10、VMware 16
安装镜像:CentOS-7-x86_64-DVD-1810.iso
kafka_2.12-2.7.2.tgz
kafka:http://kafka.apache.org/downloads
清华镜像:https://mirrors.tuna.tsinghua.edu.cn/apache/kafka/
安装
tar -zxvf kafka_2.12-2.7.2.tgz
设置环境变量
vim /etc/profile
# kafka env
export KAFKA_HOME=/home/soft/kafka
export PATH=$PATH:$KAFKA_HOME/bin
source /etc/profile
配置
vim server.properties
#DEV01
# broker就是一个kafka的部署实例,在一个kafka集群中,每一台kafka都要有一个broker.id
# 并且,该id唯一,且必须为整数
broker.id=1
log.dirs=/home/soft/kafka/kafka-logs
zookeeper.connect=DEV01:2181,DEV02:2181,DEV03:2181
mkdir -p /home/soft/kafka/kafka-logs
vim producer.properties
bootstrap.servers=DEV01:9092,DEV02:9092,DEV03:9092
vim consumer.properties
bootstrap.servers=DEV01:9092,DEV02:9092,DEV03:9092
分发到服务器上
#分发到另外的服务器
scp /etc/profile DEV02:/etc/
scp /etc/profile DEV03:/etc/
source /etc/profile
scp -r /home/soft/kafka/ DEV02:/home/soft/
scp -r /home/soft/kafka/ DEV03:/home/soft/
ssh dev02
source /etc/profile
mkdir -p /home/soft/kafka/kafka-logs
cd /home/soft/kafka/config/
vim server.properties
broker.id=2
ssh dev03
source /etc/profile
mkdir -p /home/soft/kafka/kafka-logs
cd /home/soft/kafka/config/
vim server.properties
broker.id=3
启动
# dev01、02、03均启动zk
zkServer.sh start
# dev01、02、03均启动kafka
kafka-server-start.sh -daemon /home/soft/kafka/config/server.properties
#
测试
# 创建一个主题:dev
kafka-topics.sh --create --zookeeper dev01:2181,dev02:2181,dev03:2181 --replication-factor 2 --partitions 2 --topic dev
Created topic dev.、
# 查看
kafka-topics.sh --list --zookeeper dev01:2181
dev
kafka-topics.sh --list --zookeeper dev01:2181,dev02:2181,dev03:2181
dev
#dev01
kafka-console-producer.sh --broker-list dev01:9092 --topic dev
#dev02
kafka-console-consumer.sh --bootstrap-server dev01:9092 --topic dev --from-beginning