Tomcat 一键化脚本自动安装(linux)

在执行脚本先检查环境中是否已存在服务,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






  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ApLinuxor

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值