# centos7安装Kafka并设置开机启动
单节点kafka安装,Kafka2.x版本依然需要依赖Zookeeper
# 上传Zookeeper、Kafka、Kafka-eagle程序包
Zookeeper版本:3.8.0
Kafka版本:2.13-2.8.2
Kafka-eagle版本:3.0.1
# 安装Zookeeper
# 解压Zookeeper
cd /opt/software/
tar -zxvf apache-zookeeper-3.8.0-bin.tar.gz
mv apache-zookeeper-3.8.0-bin zookeeper
# 复制Zookeeper配置文件
cd /opt/software/zookeeper/conf
cp zoo_sample.cfg zoo.cfg
# 设置Zookeeper环境变量
vim /etc/profile
export ZK_HOME=/opt/software/zookeeper
export PATH=$PATH:$ZK_HOME/bin
source /etc/profile
# 安装Kafka
# 解压Kafka
cd /opt/software/
tar -zxvf kafka_2.13-2.8.2.tgz
mv kafka_2.13-2.8.2 kafka
# 更新Kafka配置
vim /opt/software/kafka/config/server.properties
listeners=PLAINTEXT://192.168.216.43:9092
zookeeper.connect=192.168.216.43:2181
# 添加启动参数
vim /opt/software/kafka/bin/kafka-server-start.sh
#添加参数,为kafka-eagle 提供jxm数据支持,放置在脚本前面,如图。
if [ "x$KAFKA_HEAP_OPTS" = "x" ]; then
export KAFKA_HEAP_OPTS="-server -Xms2G -Xmx2G -XX:PermSize=128m -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:ParallelGCThreads=8 -XX:ConcGCThreads=5 -XX:InitiatingHeapOccupancyPercent=70"
export JMX_PORT="9999"
fi
# 设置Kafka环境变量
vim /etc/profile
export KAFKA_HOME=/opt/software/kafka
export PATH=$PATH:$KAFKA_HOME/bin
source /etc/profile
# 安装Kafka-eagle
# 解压Kafka-eagle
cd /opt/software/
tar -zxvf kafka-eagle-bin-3.0.1.tar.gz
mkdir /opt/software/kafka-eagle/
tar -zxvf kafka-eagle-bin-3.0.1/efak-web-3.0.1-bin.tar.gz -C /opt/software/kafka-eagle
cd kafka-eagle
mv efak-web-3.0.1/* ./
rm -rf efak-web-3.0.1
# 设置Kafka-eagle环境变量
vim /etc/profile
export KE_HOME=/opt/software/kafka-eagle
export PATH=$PATH:$KE_HOME/bin
source /etc/profile
# 更新Kafka-eagle配置
vim /opt/software/kafka-eagle/conf/system-config.properties
######################################
# multi zookeeper & kafka cluster list
# Settings prefixed with 'kafka.eagle.' will be deprecated, use 'efak.' instead
######################################
efak.zk.cluster.alias=cluster1
cluster1.zk.list=192.168.216.43:2181
#cluster2.zk.list=xdn10:2181,xdn11:2181,xdn12:2181
######################################
# kafka mysql jdbc driver address
######################################
efak.driver=com.mysql.cj.jdbc.Driver
efak.url=jdbc:mysql://192.168.216.22:3306/ke?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
efak.username=root
efak.password=tiankafei
# 制作启动脚本
# 启动脚本
vim /opt/software/kafka_start.sh
#!/bin/sh
export JAVA_HOME=/usr/java/default
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib
export ZK_HOME=/opt/software/zookeeper
export KAFKA_HOME=/opt/software/kafka
export KE_HOME=/opt/software/kafka-eagle
export PATH=$PATH:$JAVA_HOME/bin:$ZK_HOME/bin:$KAFKA_HOME/bin:$KE_HOME/bin
/opt/software/zookeeper/bin/zkServer.sh start
/opt/software/kafka/bin/kafka-server-start.sh -daemon /opt/software/kafka/config/server.properties
/opt/software/kafka-eagle/bin/ke.sh start
# 停止脚本
vim /opt/software/kafka_stop.sh
#!/bin/sh
/opt/software/zookeeper/bin/zkServer.sh stop
/opt/software/kafka/bin/kafka-server-stop.sh
/opt/software/kafka-eagle/bin/ke.sh stop
# kafka启动、停止赋执行权限
chmod +x /opt/software/kafka_start.sh
chmod +x /opt/software/kafka_stop.sh
# kafka开机启动脚本
vim /lib/systemd/system/kafka.service
[Unit]
Description=kafka
After=network.target
[Service]
Type=forking
ExecStart=/opt/software/kafka_start.sh
ExecStop=/opt/software/kafka_stop.sh
PrivateTmp=true
[Install]
WantedBy=multi-user.target
# 启动脚本重新加载
# 重新加载配置
systemctl daemon-reload
# 设置开机启动
systemctl enable kafka.service
# 启动
systemctl start kafka.service
# 停止
systemctl stop kafka.service
# 查看状态
systemctl status kafka.service