说明:此脚本适用于centos、ubuntu系统,安装kafka版本为3.1
废话不多说直接上脚本!
#!/bin/bash
#
#********************************************************************
#Author: Jason
#QQ: 1654028243
#Date: 2022-03-26
#FileName: install_kafka.sh
#URL: jason.cn
#Description: The test script
#Copyright (C): 2022 All rights reserved
#********************************************************************
mkdir -p /data/server
download_install () {
wget https://mirrors.tuna.tsinghua.edu.cn/apache/kafka/3.1.0/kafka_2.12-3.1.0.tgz
tar xf kafka_2.12-3.1.0.tgz -C /data/server/
cd /data/server
ln -s kafka_2.12-3.1.0 kafka
echo 'export PATH=/data/server/kafka/bin:$PATH' > /etc/profile.d/kafka.sh
source /etc/profile.d/kafka.sh
mkdir -p /data/server/kafka/logs
}
service () {
cat > /lib/systemd/system/kafka.service <<EOF
[Unit]
Description=Apache kafka
After=network.target
[Service]
Type=simple
Environment=JAVA_HOME=/data/server/java
PIDFile=/data/server/kafka/kafka.pid
ExecStart=/data/server/kafka/bin/kafka-server-start.sh /data/server/kafka/config/server.properties
ExecStop=/bin/kill -TERM ${MAINPID}
Restart=always
RestartSec=20
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl start kafka.service
systemctl status kafka.service
}
download_install
service