脚本是针对特定脚本编写的,使用的话要结合自己安装的版本进行调整。
1.zookeeper
#!/bin/bash
rm -rf /usr/local/zookeeper
echo "1.安装Zookeeper..."
tar -zxvf apache-zookeeper-3.6.2-bin.tar.gz
mv ./apache-zookeeper-3.6.2-bin/ /usr/local/zookeeper
echo "1.安装Zookeeper完毕"
echo "2.环境变量配置..."
cat <<EOF > /etc/profile.d/zookeeper.sh
export ZOOKEEPER_HOME=/usr/local/zookeeper
export PATH=$PATH:$ZOOKEEPER_HOME/bin
EOF
chmod +x /etc/profile.d/zookeeper.sh
source /etc/profile.d/zookeeper.sh
echo "ZOOKEEPER_HOME目录:"${ZOOKEEPER_HOME}
echo "2.环境变量配置完毕"
echo "3.Zookeeper配置..."
cp ${ZOOKEEPER_HOME}/conf/zoo_sample.cfg ${ZOOKEEPER_HOME}/conf/zoo.cfg
sed -i "12c dataDir=/usr/local/zookeeper/data" ${ZOOKEEPER_HOME}/conf/zoo.cfg
sed -i "13i dataLogDir=/usr/local/zookeeper/datalog" ${ZOOKEEPER_HOME}/conf/zoo.cfg
echo "3.Zookeeper配置完毕"
echo "4.启动Zookeeper..."
zkServer.sh start
echo "4.启动Zookeeper完毕"
echo "5.开启2181端口..."
firewall-cmd --zone=public --add-port=2181/tcp --permanent && firewall-cmd --reload
echo "5.开启2181端口完毕"
2.kafka
#!/bin/bash
rm -rf /usr/local/kafka
echo "1.安装Kafka..."
tar -zxvf kafka_2.12-2.6.0.tgz
mv ./kafka_2.12-2.6.0/ /usr/local/kafka
echo "1.安装Kafka完毕"
echo "2.环境变量配置..."
cat <<EOF > /etc/profile.d/kafka.sh
export KAFKA_HOME=/usr/local/kafka
export PATH=$PATH:$KAFKA_HOME/bin
EOF
chmod +x /etc/profile.d/kafka.sh
source /etc/profile.d/kafka.sh
echo "KAFKA_HOME目录:"${KAFKA_HOME}
echo "2.环境变量配置完毕"
echo "3.Kafka配置..."
sed -i "32i listeners=PLAINTEXT://localhost:9092" ${KAFKA_HOME}/config/server.properties
sed -i "61c log.dirs=${KAFKA_HOME}/kafka-logs" ${KAFKA_HOME}/config/server.properties
echo "3.Kafka配置完毕"
echo "4.启动Kafka..."
kafka-server-start.sh -daemon ${KAFKA_HOME}/config/server.properties
echo "4.启动Kafkaj完毕"
echo "5.开启9092端口..."
firewall-cmd --zone=public --add-port=9092/tcp --permanent && firewall-cmd --reload
echo "5.开启9092端口完毕"