传统的消息队列的主要应用场景包括:缓存/消峰、解耦和异步通信。
缓冲/消峰:有助于控制和优化数据流经过系统的速度,解决生产消息和消费消息的处理速度不一致的情况。
解耦:允许你独立的扩展或修改两边的处理过程,只要确保它们遵守同样的接口约束。
异步通信:允许用户把一个消息放入队列,但并不立即处理它,然后在需要的时候再去处理它们
master | slave1 | slave2 |
---|---|---|
zk | zk | zk |
kafka | kafka | kafka |
[atguigu@master software]$ tar -zxvf kafka_2.12-3.0.0.tgz -C /opt/module/
[atguigu@master module]$ mv kafka_2.12-3.0.0/ kafka
#broker 的全局唯一编号,不能重复,只能是数字。
broker.id=0
#kafka 运行日志(数据)存放的路径,路径不需要提前创建,kafka 自动帮你创建,可以
配置多个磁盘路径,路径与路径之间可以用","分隔
log.dirs=/opt/module/kafka/datas
#配置连接 Zookeeper 集群地址(在 zk 根目录下创建/kafka,方便管理)
zookeeper.connect=master:2181,slave1:2181,slave2:2181/ka
fka
[atguigu@master module]$ xsync kafka/
中的 broker.id=1、broker.id=2
[atguigu@master module]$ ssh slave1
Last login: Mon Jul 11 21:03:23 2022 from 192.168.10.1
[atguigu@slave1 ~]$ cd /opt/module/kafka/config/
[atguigu@slave1 config]$ vim server.properties
[atguigu@slave1 config]$ ssh slave2
Last login: Mon Jul 11 21:03:28 2022 from 192.168.10.1
[atguigu@slave2 ~]$ vim /opt/module/kafka/config/server.properties
[atguigu@slave2 ~]$
#KAFKA_HOME
export KAFKA_HOME=/opt/module/kafka
export PATH=$PATH:$KAFKA_HOME/bin
[atguigu@master module]$ source /etc/profile
[atguigu@master module]$ sudo /home/atguigu/bin/xsync /etc/profile.d/my_env.sh
[atguigu@slave1 config]$ source /etc/profile
[atguigu@slave2 config]$ source /etc/profile
[atguigu@master module]$ zk.sh start
[atguigu@master kafka]$ bin/kafka-server-start.sh -daemon config/server.properties
[atguigu@slave1 kafka]$ bin/kafka-server-start.sh -daemon config/server.properties
[atguigu@slave2 kafka]$ bin/kafka-server-start.sh -daemon config/server.properties
[atguigu@master kafka]$ bin/kafka-server-stop.sh
[atguigu@slave1 kafka]$ bin/kafka-server-stop.sh
[atguigu@slave2 kafka]$ bin/kafka-server-stop.sh
[atguigu@master bin]$ vim kf.sh
#! /bin/bash
case $1 in
"start"){
for i in master slave1 slave2
do
echo " --------启动 $i Kafka-------"
ssh $i "/opt/module/kafka/bin/kafka-server-start.sh -daemon /opt/module/kafka/config/server.properties"
done
};;
"stop"){
for i in master slave1 slave2
do
echo " --------停止 $i Kafka-------"
ssh $i "/opt/module/kafka/bin/kafka-server-stop.sh "
done
};;
esac
[atguigu@master bin]$ chmod 777 kf.sh
[atguigu@master bin]$ kf.sh start
[atguigu@master bin]$ xcall.sh jps