上传安装包到/opt/software目录并解压
bash
[bigdata@node106 software]$ tar -zxvf kafka_2.12-3.5.2.tgz -C /opt/services/
重命名kafka
bash
[bigdata@node106 software]$ mv kafka_2.12-3.5.2 kafka_3.5.2
配置环境变量
bash
[bigdata@node106 ~]$ sudo vim /etc/profile.d/bigdata_env.sh
bash
export KAFKA_HOME=/opt/services/kafka_3.5.2
export PATH=$PATH:$JAVA_HOME/bin:$ZK_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$KAFKA_HOME/bin
分发环境变量
bash
[bigdata@node106 ~]$ sudo ./bin/xsync /etc/profile.d/bigdata_env.sh
刷新环境变量,5台机器上执行
bash
[bigdata@node106 ~]$ source /etc/profile
修改配置文件
bash
[bigdata@node106 ~]$ sudo vim /opt/services/kafka_3.5.2/config/server.properties
bash
broker.id=0
log.dirs=/opt/services/kafka_3.5.2/datas
zookeeper.connect=node106:2181,node107:2181,node108:2181/kafka
copy到其他节点
bash
[bigdata@node107 ~]$ scp -r bigdata@node106: /opt/services/kafka_3.5.2/ /opt/services/kafka_3.5.2/
[bigdata@node108 ~]$ scp -r bigdata@node106: /opt/services/kafka_3.5.2/ /opt/services/kafka_3.5.2/
修改配置文件
node107上修改broker.id=1
node108上修改broker.id=2
编写kafka.sh启动停止脚本
bash
#!/bin/bash
if [ $# -lt 1 ]
then
echo "No Args Input...[start,stop]"
exit ;
fi
case $1 in
"start")
echo " =================== 启动 kafka集群 ==================="
echo " --------------- 启动 node106 ---------------"
ssh node106 "$KAFKA_HOME/bin/kafka-server-start.sh -daemon $KAFKA_HOME/config/server.properties"
echo " --------------- 启动 node107---------------"
ssh node107 "$KAFKA_HOME/bin/kafka-server-start.sh -daemon $KAFKA_HOME/config/server.properties"
echo " --------------- 启动 node108 ---------------"
ssh node108 "$KAFKA_HOME/bin/kafka-server-start.sh -daemon $KAFKA_HOME/config/server.properties"
;;
"stop")
echo " =================== 关闭 kafka集群 ==================="
echo " --------------- 关闭 node106 ---------------"
ssh node106 "$KAFKA_HOME/bin/kafka-server-stop.sh"
echo " --------------- 关闭 node107---------------"
ssh node107 "$KAFKA_HOME/bin/kafka-server-stop.sh"
echo " --------------- 关闭 node108 ---------------"
ssh node108 "$KAFKA_HOME/bin/kafka-server-stop.sh"
;;
*)
echo "Input Args Error...[start,stop]"
;;
esac
授权
bash
[bigdata@node106 bin]$ chmod +x kafka.sh
分发到其他机器
bash
[bigdata@node106 bin]$ xsync kafka.sh
启动kafka
bash
[bigdata@node106 bin]$ kafka.sh start