#!/bin/bash
kafka_ver=kafka_2.11-2.2.1
kafka_tgz=$kafka_ver.tgz
hostip=`hostname -i`
broker_id=`echo $hostip | awk -F . '{print $4}'`
cd /home/service/app
wget http://10.12.29.98:8090/tools/kafka/$kafka_tgz
tar zxf $kafka_tgz
mv $kafka_ver kafka
cd kafka/bin
mv kafka-server-start.sh kafka-server-start.sh.bak
wget http://10.12.29.98:8090/tools/kafka/kafka-server-start.sh
cd ../config
mv log4j.properties log4j.properties.bak
#mv server.properties server.properties.bak
wget http://10.12.29.98:8090/tools/kafka/log4j.properties
#wget http://10.12.29.98:8090/tools/kafka/server.properties
cat <<EOF > server.properties
broker.id=$broker_id
listeners=PLAINTEXT://$hostip:9092
port=9092
host.name=$hostip
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
log.dirs=/home/service/var/kafka
num.partitions=6
auto.create.topics.enable=false
default.replication.factor=2
offsets.topic.replication.factor=3
log.retention.hours=24
log.retention.bytes=1073741824
log.segment.bytes=1073741824
log.retention.check.interval.ms=100000
zookeeper.connect=10.15.72.29:2181,10.15.78.234:2181,10.15.66.217:2181/kafka_log
zookeeper.connection.timeout.ms=6000
group.initial.rebalance.delay.ms=3000
log.cleaner.enable=true
delete.topic.enable=true
EOF
wget http://10.12.29.98:8090/tools/kafka/start.sh -O /home/service/app/kafka/start.sh
echo "*/2 * * * * root /bin/bash /home/service/app/kafka/start.sh" >> /etc/crontab
mkdir -p /home/service/var/kafka
chown -R service.service /home/service/var/kafka
chown -R service.service /home/service/app/kafka
su - service -c 'sh /home/service/app/kafka/bin/kafka-server-start.sh -daemon /home/service/app/kafka/config/server.properties'