1、下载地址:
2、上传到虚拟机并解压
tar -zxvf /tempupload/kafka_2.13-3.6.0.tgz
mv kafka_2.13-3.6.0 kafka
3、 创建存放kafka消息的目录
cd kafka
mkdir kafka-logs
4、修改配置文件
进入配置文件目录
cd config/
备份
cp server.properties server.properties.bak
修改配置文件
vim server.properties
# 修改如下参数
broker.id=0
listeners=PLAINTEXT://hadoop100:9092
log.dirs=/opt/module/kafka/kafka-logs
zookeeper.connect=hadoop100:2181,hadoop101:2181
5、分发kafka安装目录
scp -r /opt/module/kafka/ hadoop101:/opt/module
修改hadoop101配置文件server.properties中的broker.id和listeners参数
broker.id=2
listeners=PLAINTEXT://hadoop2:9092
6、编写kafka集群操作脚本
cd /opt/module/kafka/bin
vim kafka-cluster.sh
case $1 in
"start"){
for i in hadoop100 hadoop101
do
echo -------------------------------- $i kafka 启动 ---------------------------
ssh $i "source /etc/profile;/opt/module/kafka/bin/kafka-server-start.sh -daemon /opt/module/kafka/config/server.properties"
done
}
;;
"stop"){
for i in hadoop100 hadoop101
do
echo -------------------------------- $i kafka 停止 ---------------------------
ssh $i "/opt/module/kafka/bin/kafka-server-stop.sh"
done
}
;;
esac
保存退出后,修改执行权限
chmod +x ./kafka-cluster.sh