1.离线安装脚本
为了能够快速部署,故编写了离线安装配置的 shell 脚本。
1.1 Zookeeper
Zookeeper 安装文件为apache-zookeeper-3.6.2-bin.tar.gz
脚本内容如下:
#!/bin/bash rm -rf /usr/local/zookeeper echo "(1/6): 解压Zookeeper安装文件..." tar -zxvf apache-zookeeper-3.6.2-bin.tar.gz sleep 10 echo "(1/6): Zookeeper安装文件解压完毕" echo "(2/6): 配置Zookeeper环境变量..." mv ./apache-zookeeper-3.6.2-bin/ /usr/local/zookeeper sleep 2 cat <<'EOF' > /etc/profile.d/zookeeper.sh export ZOOKEEPER_HOME=/usr/local/zookeeper export PATH=$PATH:$ZOOKEEPER_HOME/bin EOF sleep 1 source /etc/profile.d/zookeeper.sh echo "ZOOKEEPER_HOME目录:"${ZOOKEEPER_HOME} echo "(2/6): 配置Zookeeper环境变量完毕" echo "(3/6): 配置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/6): Zookeeper运行参数配置完毕" echo "(4/6): 初次启动Zookeeper..." zkServer.sh start sleep 2 zkServer.sh status echo "(4/6): Zookeeper初次启动完毕" echo "(5/6): 开启2181端口..." firewall-cmd --zone=public --add-port=2181/tcp --permanent && firewall-cmd --reload echo "(5/6): 2181端口开启完毕" echo "(6/6): Zookeeper加入到service服务并设置开机自启..." cat <<'EOF' > /etc/rc.d/init.d/zookeeper #!/bin/bash # chkconfig: 2345 10 90 # description: service zookeeper # processname: zookeeper export JAVA_HOME=/usr/local/java ZOOKEEPER_HOME=/usr/local/zookeeper case $1 in start) su root ${ZOOKEEPER_HOME}/bin/zkServer.sh start;; start-foreground) su root ${ZOOKEEPER_HOME}/bin/zkServer.sh start-foreground;; stop) su root ${ZOOKEEPER_HOME}/bin/zkServer.sh stop;; status) su root ${ZOOKEEPER_HOME}/bin/zkServer.sh status;; restart) su root ${ZOOKEEPER_HOME}/bin/zkServer.sh restart;; upgrade) su root ${ZOOKEEPER_HOME}/bin/zkServer.sh upgrade;; print-cmd) su root ${ZOOKEEPER_HOME}/bin/zkServer.sh print-cmd;; *) echo "require start|start-foreground|stop|status|restart|print-cmd";; esac EOF chmod +x /etc/rc.d/init.d/zookeeper chkconfig --add /etc/rc.d/init.d/zookeeper chkconfig zookeeper on echo "(6/6): Zookeeper加入到service服务并设置开机自启完毕"
1.2 Kafka
Kafka 安装文件为apache-zookeeper-3.6.2-bin.tar.gz
脚本内容如下:
#!/bin/bash rm -rf /usr/local/kafka echo "(1/6): 解压Kafka安装文件..." tar -zxvf kafka_2.12-2.6.0.tgz sleep 10 echo "(1/6): Kafka安装文件解压完毕" echo "(2/6): 配置Kafka环境变量..." mv ./kafka_2.12-2.6.0/ /usr/local/kafka sleep 2 cat <<'EOF' > /etc/profile.d/kafka.sh export KAFKA_HOME=/usr/local/kafka export PATH=$PATH:$KAFKA_HOME/bin EOF sleep 1 source /etc/profile.d/kafka.sh echo "KAFKA_HOME目录:"${KAFKA_HOME} echo "(2/6): Kafka环境变量配置完毕" echo "(3/6): 配置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/6): Kafka运行参数配置完毕" echo "(4/6): 首次启动Kafka..." kafka-server-start.sh -daemon ${KAFKA_HOME}/config/server.properties echo "(4/6): Kafka首次启动完毕" echo "(5/6): 开启9092端口..." firewall-cmd --zone=public --add-port=9092/tcp --permanent && firewall-cmd --reload echo "(5/6): 9092端口开启完毕" echo "(6/6): Kafka加入到service服务并设置开机自启..." cat <<'EOF' > /etc/rc.d/init.d/kafka #!/bin/bash # chkconfig: 2345 40 60 # description: service kafka # processname: kafka export JAVA_HOME=/usr/local/java KAFKA_HOME=/usr/local/kafka case $1 in start) ${KAFKA_HOME}/bin/kafka-server-start.sh -daemon ${KAFKA_HOME}/config/server.properties;; stop) ${KAFKA_HOME}/bin/kafka-server-stop.sh;; status) ${JAVA_HOME}/bin/jps | grep Kafka;; restart) ${KAFKA_HOME}/bin/kafka-server-stop.sh ${KAFKA_HOME}/bin/kafka-server-start.sh -daemon ${KAFKA_HOME}/config/server.properties;; *) echo "require start|stop|status|restart";; esac EOF chmod +x /etc/rc.d/init.d/kafka chkconfig --add /etc/rc.d/init.d/kafka chkconfig kafka on echo "(6/6): Kafka加入到service服务并设置开机自启完毕"
2.脚本使用说明
- 使用
source xxx.sh
执行上述脚本,否则环境变量无法在当前环境下生效。 - 不同安装文件的
(3/6): 配置xxx运行参数...
的代码可能不一致,需要自行整理。