Bootstrap

数据湖仓一体(二) 安装kafka

上传安装包到/opt/software目录并解压

[bigdata@node106 software]$ tar -zxvf kafka_2.12-3.5.2.tgz  -C /opt/services/ 

重命名kafka

[bigdata@node106 software]$ mv kafka_2.12-3.5.2 kafka_3.5.2 

配置环境变量

[bigdata@node106 ~]$ sudo vim /etc/profile.d/bigdata_env.sh
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

分发环境变量

[bigdata@node106 ~]$ sudo ./bin/xsync /etc/profile.d/bigdata_env.sh

刷新环境变量,5台机器上执行

[bigdata@node106 ~]$ source /etc/profile

修改配置文件

[bigdata@node106 ~]$ sudo vim /opt/services/kafka_3.5.2/config/server.properties 
broker.id=0
log.dirs=/opt/services/kafka_3.5.2/datas
zookeeper.connect=node106:2181,node107:2181,node108:2181/kafka

copy到其他节点

[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启动停止脚本

#!/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

授权

[bigdata@node106 bin]$ chmod +x kafka.sh

分发到其他机器

[bigdata@node106 bin]$ xsync  kafka.sh 

启动kafka

[bigdata@node106 bin]$ kafka.sh start

;