官方下载地址:http://kafka.apache.org/downloads.html
(1)上传并解压安装包
[zhangflink@9wmwtivvjuibcd2e package]$ tar -zxvf kafka_2.12-3.3.1.tgz -C ../software/
[zhangflink@9wmwtivvjuibcd2e software]$ mv kafka_2.12-3.3.1/ kafka
(3)进入到/opt/software/kafka目录,修改配置文件
[zhangflink@9wmwtivvjuibcd2e config]$ vim server.properties
[zhangflink@9wmwtivvjuibcd2e config]$ sudo vim /etc/profile
#KAFKA_HOME
export KAFKA_HOME=/opt/software/kafka
export PATH=$PATH:$KAFKA_HOME/bin
[zhangflink@9wmwtivvjuibcd2e config]$ source /etc/profile
(4)分发环境变量文件到其他节点,并source刷新配置文件
[zhangflink@9wmwtivvjuibcd2e software]$ /home/zhangflink/bin/xsync /etc/profile
[zhangflink@9wmwtivvjuibcd2e-0001 ~]$ source /etc/profile
[zhangflink@9wmwtivvjuibcd2e-0002 ~]$ source /etc/profile
(5)分发kafka文件到其他节点
[zhangflink@9wmwtivvjuibcd2e software]$ /home/zhangflink/bin/xsync kafka/
3.启动集群
先启动Zookeeper集群,然后启动Kafka。
[zhangflink@9wmwtivvjuibcd2e kafka]$ bin/kafka-server-start.sh -daemon config/server.properties
[zhangflink@9wmwtivvjuibcd2e-0001 kafka]$ bin/kafka-server-start.sh -daemon config/server.properties
[zhangflink@9wmwtivvjuibcd2e-0002 kafka]$ bin/kafka-server-start.sh -daemon config/server.properties
查看进程
**
**
修改完后再次启动日志正常,brokerID正常
4.集群启停脚本
(1)在/home/zhangflink/bin目录下创建文件kafka.sh脚本文件
[zhangflink@9wmwtivvjuibcd2e kafka]$ sudo vim /home/zhangflink/bin/kafka.sh
编辑脚本
#! /bin/bash
case $1 in
"start"){
for i in flinkv1 flinkv2 flinkv3
do
echo " --------启动 $i Kafka-------"
ssh $i "/opt/software/kafka/bin/kafka-server-start.sh -daemon /opt/software/kafka/config/server.properties"
done
};;
"stop"){
for i in flinkv1 flinkv2 flinkv3
do
echo " --------停止 $i Kafka-------"
ssh $i "/opt/software/kafka/bin/kafka-server-stop.sh "
done
};;
esac
(2)添加执行权限
[zhangflink@9wmwtivvjuibcd2e kafka]$ sudo chmod 777 /home/zhangflink/bin/kafka.sh
问题原因:
登录式Shell,采用用户名比如xxx登录,会自动加载/etc/profile
非登录式Shell,采用ssh比如ssh 192.168.1.121登录,不会自动加载/etc/profile,会自动加载~/.bashrc
解决方法:
先测试 ssh [bigdata111 ip] “which java” 是否有反应,如果显示"no found",则需要配置
执行命令
[zhangflink@9wmwtivvjuibcd2e bin]$ ssh flinkv1 "which java"
出现报错
which: no java in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
配置 ~/.bashrc文件
[zhangflink@9wmwtivvjuibcd2e ~]$ cd /home/zhangflink/bin/
[zhangflink@9wmwtivvjuibcd2e bin]$ vim ~/.bashrc
添加配置文件
export JAVA_HOME=/opt/software/jdk1.8.0_212
export PATH=$PATH:$JAVA_HOME/bin
并将.bashrc文件分发到其他节点上
[zhangflink@9wmwtivvjuibcd2e bin]$ /home/zhangflink/bin/xsync ~/.bashrc
继续测试 ssh [bigdata111 ip] “which java” 成功后重启脚本,看进程是否存在
然后再次执行脚本启动kafka,发现启动成功。