kafka集群部署,三节点模式
Posted 西风h
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了kafka集群部署,三节点模式相关的知识,希望对你有一定的参考价值。
前提安装好jdk环境
#!/bin/bash
echo "本地yum源是否配置完毕,是请忽略,否请按CTRL+C退出!"
sleep 3
echo "自动化安装zookeeper-3.6.2+kafka_2.13-2.6.0三台服务器集群(前提安装好jdk环境):"
read -p "请根据实际数据挂载盘输入zookeeper和kafka安装的主目录(建议安装/data):" maindir
echo "---3台机均需执行该脚本,下面进行zookeeper集群创建---"
if [ -f /root/apache-zookeeper-3.6.2-bin.tar.gz ] && [ -f /root/kafka_2.13-2.6.0.tgz ];then
mkdir $maindir
tar xf apache-zookeeper-3.6.2-bin.tar.gz -C $maindir
mv $maindir/apache-zookeeper-3.6.2-bin $maindir/zookeeper
cd $maindir/zookeeper/conf/
mv zoo_sample.cfg zoo.cfg
mkdir $maindir/zookeeper/data
sed -i "s#/tmp/zookeeper#$maindir/zookeeper/data#" zoo.cfg
read -p "请输入zookeeper集群第1台服务器的ip:" ip1
read -p "请输入zookeeper集群第2台服务器的ip:" ip2
read -p "请输入zookeeper集群第3台服务器的ip:" ip3
cat >> zoo.cfg <<EOF
server.1=$ip1:2888:3888
server.2=$ip2:2888:3888
server.3=$ip3:2888:3888
EOF
read -p "请输入序号,集群第1台服务器填1,第2台服务器填2,第3台服务器填3:" number
echo $number > $maindir/zookeeper/data/myid
cd $maindir/zookeeper/bin
./zkServer.sh start
echo "###已完成zookeeper集群部署###"
echo "查看当前状态:"
$maindir/zookeeper/bin/zkServer.sh status
echo "停止zookeeper $maindir/zookeeper/bin/zkServer.sh stop"
echo "---开始部署kafka集群---"
cd /root
tar xf kafka_2.13-2.6.0.tgz
mv kafka_2.13-2.6.0 $maindir/kafka
cd $maindir/kafka
sed -i -c -e '/^$/d;/^#/d' config/server.properties
sed -i s/broker.id=0/broker.id=$number/g config/server.properties
sed -i "s#log.dirs=/tmp/kafka-logs#log.dirs=$maindir/kafka/logs#" config/server.properties
sed -i s/zookeeper.connect=localhost:2181/zookeeper.connect=$ip1:2181,$ip2:2181,$ip3:2181/g config/server.properties
read -p "请输入当前服务器的IP地址(内网地址,非127.0.0.1):" ip
cat >> config/server.properties <<EOF
listeners=PLAINTEXT://$ip:9092
advertised.listeners=PLAINTEXT://$ip:9092
EOF
source /etc/profile
$maindir/kafka/bin/kafka-server-start.sh $maindir/kafka/config/server.properties > /dev/null 2>&1 &
sleep 2
tail -500 $maindir/kafka/logs/server.log
echo "###如果遇到zookeeper无法启动的情况,是因为java变量未生效的缘故,请重新打开窗口或手工执行下source /etc/profile!"
echo "如果遇到kafka无法启动的情况,请在zookeeper全部启动的情况下(理论上启动2台以上的zookeeper则kafka可以正常启动),再启动kafka!"
echo "启动kafka的命令为:$maindir/kafka/bin/kafka-server-start.sh $maindir/kafka/config/server.properties > /dev/null 2>&1 &"
echo "停止命令: $maindir/kafka/bin/kafka-server-stop.sh $maindir/kafka/config/server.properties > /dev/null 2>&1 &"
echo "###已完成kafka集群部署###"
else
echo "请把相应的包上传到/root目录,再进行下一步!"
exit 0
fi
以上是关于kafka集群部署,三节点模式的主要内容,如果未能解决你的问题,请参考以下文章