#! /bin/sh
##======================================================================
## KAFKA安装脚本
## AUTHOR: JPanda
## EMAIL: jpanda@aliyun.com
## DATE: 2019年9月17日
## ======================================================================
## 下载安装
mkdir -p /data/kafka/kafka-logs
cd /data
wget -nc http://mirrors.tuna.tsinghua.edu.cn/apache/kafka/2.3.0/kafka_2.12-2.3.0.tgz
tar -zxvf kafka_2.12-2.3.0.tgz --strip-components 1 -C kafka/
## 移除Windows Bat脚本
rm -rf /data/kafka/bin/windows
# ln -s /data/kafka/bin/* /usr/local/bin/
echo "broker.id=0
#修改监听端口
listeners = PLAINTEXT://:9093
num.network.threads=3
num.io.threads=8
socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
#修改落盘数据存放位置
log.dirs=/data/kafka/kafka-logs
#kafka-topic日志定时清理
log.cleanup.policy=delete
#清理超过指定时间清理:
log.retention.hours=168
#超过指定大小后,删除旧的消息:
log.retention.bytes=5368709120
num.partitions=1
num.recovery.threads.per.data.dir=1
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1
log.retention.hours=168
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
zookeeper.connect=localhost:2181
zookeeper.connection.timeout.ms=6000
#group.initial.rebalance.delay.ms=0
" >/data/kafka/config/server.properties
## 启动kafka
/data/kafka/bin/kafka-server-start.sh /data/kafka/config/server.properties >/dev/null 2>&1 &
## 睡5秒等待kafka启动完毕,可以考虑使用retry机制
sleep 5
## 创建Topics
/data/kafka/bin/kafka-topics.sh --create --zookeeper 127.0.0.1:2181 --replication-factor 1 --partitions 4 --topic topic-01
/data/kafka/bin/kafka-topics.sh --create --zookeeper 127.0.0.1:2181 --replication-factor 1 --partitions 4 --topic topic-02
echo "/data/kafka/bin/kafka-server-start.sh /data/kafka/config/server.properties >/dev/null 2>&1 &">>/etc/rc.d/rc.local
网友评论