安装文件及shell脚本网盘分享:
链接:https://pan.baidu.com/s/1ZQE6Chfvur_u_iefhbtFKQ 提取码:l6nw
包含文件:
以下脚本仅针对特定离线版本安装,方便快速部署。
1.脚本
- JDK安装脚本:jdkInstall.sh
- 时序数据库InfluxDB安装脚本:influxdbInstall.sh
- Zookeeper安装脚本:zookeeperInstall.sh
- Kafka安装脚本:kafkaInstall.sh
2.使用说明
按需将安装文件与 shell 安装脚本放在同一个文件夹下。
(1)使用 chmod +x *.sh
命令给shell 脚本赋可执行权限。
(2)由于脚本设置了全局变量,执行需要使用 source xxx.sh 命令。
- source jdkInstall.sh
- source influxdbInstall.sh
- source zookeeperInstall.sh
- source kafkaInstall.sh
2.1 JDK安装脚本
脚本仅适用于jdk-8u241-linux-x64.tar.gz
的安装部署。
- 步骤 (2/3)
JAVA_HOME
文件夹可自定义,默认为/usr/local/java/jdk1.8.0_241
。
#!/bin/bash rm -rf /usr/local/java/jdk1.8.0_241 echo "(1/3): 解压JDK安装文件..." mkdir -p /usr/local/java/jdk1.8.0_241 tar -zxvf jdk-8u241-linux-x64.tar.gz sleep 10 echo "(1/3): JDK安装文件解压完毕" echo "(2/3): 配置JDK环境变量..." mv -f jdk1.8.0_241/ /usr/local/java sleep 2 cat <<'EOF' > /etc/profile.d/java.sh export JAVA_HOME=/usr/local/java/jdk1.8.0_241 export PATH=$PATH:$JAVA_HOME/bin EOF sleep 1 source /etc/profile.d/java.sh echo "JAVA_HOME目录:"${JAVA_HOME} echo "(2/3): JDK环境变量配置完毕" echo "(3/3): 验证JDK版本..." java -version echo "(3/3): JDK版本验证完毕"
2.2 时序数据库InfluxDB安装脚本
脚本仅适用于influxdb-1.7.6.x86_64.rpm
的安装部署。
- 步骤 (2/6) 配置数据存储位置,根据实际情况进行配置。
- 步骤 (4/6) 创建admin用户及数据库,根据实际情况进行配置。
#!/bin/bash # yum -y remove influxdb.x86_64 echo "(1/6): 安装InfluxDB..." yum localinstall -y influxdb-1.7.6.x86_64.rpm echo "(1/6): InfluxDB安装完毕" echo "(2/6): 配置InfluxDB运行参数..." mkdir -p /home/influxdb/meta mkdir -p /home/influxdb/data mkdir -p /home/influxdb/wal chown -R influxdb:influxdb /home/influxdb sed -i "26c dir = \"/home/influxdb/meta\"" /etc/influxdb/influxdb.conf sed -i "45c dir = \"/home/influxdb/data\"" /etc/influxdb/influxdb.conf sed -i "48c wal-dir = \"/home/influxdb/wal\"" /etc/influxdb/influxdb.conf sed -i "247c enabled = true" /etc/influxdb/influxdb.conf echo "(2/6): InfluxDB运行参数配置完毕" echo "(3/6): 首次启动InfluxDB..." systemctl start influxd sleep 3 systemctl status influxd echo "(3/6): InfluxDB首次启动完毕" echo "(4/6): 创建用户及数据库..." influx -execute 'create user "dsj" with password '\''dsj'\'' with all privileges;' -format 'json' -pretty sleep 1 influx -execute 'create database "sjzt";' -format 'json' -pretty sleep 1 echo "(4/6): 用户及数据库创建完毕" echo "(5/6): 开启权限认证并重启InfluxDB..." sed -i "259c auth-enabled = true" /etc/influxdb/influxdb.conf systemctl restart influxd sleep 3 systemctl status influxd echo "(5/6): 开启权限认证并重启InfluxDB完毕" echo "(6/6): 配置InfluxDB开机启动..." cat <<EOF >> /etc/rc.loal systemctl start influxd EOF echo "(6/6): InfluxDB开机启动配置完毕"
2.3 Zookeeper安装脚本
脚本仅适用于apache-zookeeper-3.6.2-bin.tar.gz
的安装部署。
- 步骤 (2/6) 内
ZOOKEEPER_HOME
可自定义 - 步骤 (3/6) 内运行参数可配置
- 步骤 (6/6) 内
JAVA_HOME
需根据实际情况进行修改,默认为/usr/local/java/jdk1.8.0_241
。
#!/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/jdk1.8.0_241 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服务并设置开机自启完毕"
2.4 Kafka安装脚本
脚本仅适用于kafka_2.12-2.6.0.tgz
的安装部署。
- 步骤 (2/6) 内
KAFKA_HOME
可自定义,Kafka会存储较多数据,需选择空间较大磁盘。 - 步骤 (3/6) 内运行参数可配置
- 步骤 (6/6) 内
JAVA_HOME
需根据实际情况进行修改,默认为/usr/local/java/jdk1.8.0_241
。
#!/bin/bash rm -rf /usr/local/kafka # 获取local_host值 local_host=`ifconfig|grep "broadcast"|tail -1|awk '{print $2}'` 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://"${local_host}":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/jdk1.8.0_241 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服务并设置开机自启完毕"
3.更新记录
- 20220520 kafka脚本修改监听地址从
localhost(127.0.0.1)
改为获取的本机host值。