在执行脚本先检查环境中是否已存在服务,tomcat或者java;如果有请删干净相关文件及配置;如果java环境已经配置完成则不需要再安装java,中间步骤即可跳过,直接去执行启动。
随便创建一个.sh文件,复制粘贴下面代码执行即可:
#创建文件
touch tomcat_install.sh
#复制代码粘贴到指定文件
#执行脚本
sh tomcat_install.sh
#!/usr/local
function check_tomcat(){
if [ "$install_or" == "y" ]; then
wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.91/bin/apache-tomcat-9.0.91.zip&&sleep 0.5
echo "[Warning]Executing decompression..."&&unzip apache-tomcat-9.0.91.zip -d /opt/
echo "your tomcat service have installed">/opt/apache-tomcat-9.0.91/webapps/ROOT/index.html&&sleep 0.5&&sh /opt/apache-tomcat-9.0.91/bin/startup.sh&&sleep 2
else
echo "[Warning]:tomcat has installed"
fi
}
function check_java(){
if java --version >> /dev/null; then
echo "[Warning]:java service existed"
else
echo "[Warning]:If failed,maybe lack of java configuration,please check and install:"
echo "`uname -a`"
echo "We provide two version for you,choose the best use by your system opration:"
printf "%s \n" " ------------------------------------"
printf "%s \n" "| -*-*-* 1.Linux--ARM64 *-*-*- |"
printf "%s \n" "| -*-*-* 2.Linux--x64 *-*-*- |"
printf "%s \n" "| -*-*-* 0. Exit *-*-*- |"
printf "%s \n" " ------------------------------------"
read -p "choose your version:" download_or
case $download_or in
1)
echo "[Warning]Executing online software package download, please wait..."
wget https://download.oracle.com/java/22/latest/jdk-22_linux-aarch64_bin.tar.gz&&mv jdk* /opt/
echo "[Warning]Executing loading..."
sleep 7
echo "[Warning]During the execution of environment configuration..."&&mkdir -p /usr/local/java && tar -vxf /opt/jdk-22_linux-aarch64_bin.tar.gz -C /usr/local/java/
echo "export JAVA_HOME=/usr/local/java/jdk-22.0.2">> /etc/profile
echo "export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar">> /etc/profile
echo "export PATH=$PATH:$JAVA_HOME/bin">> /etc/profile && source /etc/profile
;;
2)
echo "[Warning]Executing online software package download, please wait..."
wget https://download.oracle.com/java/22/latest/jdk-22_linux-x64_bin.tar.gz&&mv jdk* /opt/
echo "[Warning]Executing loading..."
sleep 7
echo "[Warning]During the execution of environment configuration..."&&mkdir -p /usr/local/java && tar -vxf /opt/jdk-22_linux-x64_bin.tar.gz -C /usr/local/java/
echo "export JAVA_HOME=/usr/local/java/jdk-22.0.2">> /ect/profile
echo "export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar">> /etc/profile
echo "export PATH=$PATH:$JAVA_HOME/bin">> /etc/profile
;;
0)
exit 0
;;
esac
source /etc/profile
echo "[Warning]Perform authorization operationing, check and modify other requirements on your own"
chmod 775 /opt/apache-tomcat-9.0.91/bin/*&&chmod 775 /opt/apache-tomcat-9.0.91/webapps/ROOT/*&&sleep 2&&clear
sh /opt/apache-tomcat-9.0.91/bin/catalina.sh && sh /opt/apache-tomcat-9.0.91/bin/startup.sh&&clear
echo "[Warning]:Please insure the network in normal(ctrl+c to exit)"&&sleep 2
echo "[Warning]:Please ensure that there are no previous residual file resources on the system"&&sleep 2
echo "This process will install service 'Tomcat' for your linux-system,please waite for minutes..."&&sleep 2
clear
total_tasks=100
for ((i=1; i<=total_tasks; i++)); do
sleep 0.01
progress=$((100 * i / total_tasks))
printf "\rsystem-information-aplexia: [%d%%] [" $progress
for ((j=1; j<=progress/1; j++)); do
printf "*"
done
for ((j=progress/10+1; j<=10; j++)); do
printf " "
done
printf "]"
done
echo "(java --version):"&& java --version
echo "Tomcat service install successfully!"
echo "java configuration files location: /usr/local/java"
echo "tomcat configuration files location: /opt/apache-tomcat-9.0.91"
echo "tomcat start/shutdwon:"
echo "cd /opt/apache-tomcat-9.0.91/bin"
echo "./start.sh or ./shutdown.sh"
echo "----------------------------------------------------------------------"
echo "|Thanks for use Alexia shell service,please connetct:2637192651@qq.com|"
echo "----------------------------------------------------------------------"
printf %s "[Warning]Copyright Notice: This article is an original script and follows the copyright agreement. Please attach the original source link and this statement when reprinting.\n"
fi
}
read -p "please insure tomcat not installed yet,if continue press(y) or not install (n)" install_or
check_tomcat
check_java