kafka_path=/usr/local
kafka_tar_version=kafka_2.12-2.2.0.tgz
kafka_version=kafka_2.12-2.2.0
confpath=$kafka_path/kafka
#判断目录
if [ ! -d $kafka_path ];then
mkdir -p $kafka_path
echo "重新创建目录成功"
else
#解压
ls /tmp | grep 'kafka.*[tgz]$'
if [ $? -ne 0 ];then
echo "没有发现kafka*.tar.gz,自动下载!"
wget -P /tmp http://mirrors.hust.edu.cn/apache/kafka/2.2.0/kafka_2.12-2.2.0.tgz
else
echo -e "kafka压缩包存在!"
fi
tar -xf /tmp/$kafka_tar_version -C $kafka_path
if [ ! -d $kafka_path/kafka ];then
mv $kafka_path/$kafka_version $kafka_path/kafka
if [ ! -d $kafka_path/kafka ];then
echo -e "创建kafka目录失败"
fi
#修改配置文件
echo -e "请输入kafka节点id:唯一值 例如 1"
read node_id
sed -i "s/^broker.id=0/broker.id=$node_id/g" $confpath/config/server.properties
sed -i "s/^#listeners=PLAINTEXT:\/\/:9092/listeners=PLAINTEXT:\/\/:9092/g" $confpath/config/server.properties
cat $confpath/config/server.properties | grep -w 'broker.id'
$confpath/bin/zookeeper-server-start.sh $confpath/config/zookeeper.properties 2>&1 >/dev/null &
$confpath/bin/kafka-server-start.sh $confpath/config/server.properties 2>&1 >/dev/null &
sleep 5
netstat -tupln | egrep "(2181|9092)"
else
echo 'kafka存在'
fi
fi
(shell系列)单机一键安装kafka
最新推荐文章于 2023-03-12 09:31:01 发布