1. 程式人生 > >linux使用shell一鍵安裝tomcat 並更改訪問埠為 80

linux使用shell一鍵安裝tomcat 並更改訪問埠為 80

#!/bin/sh
sduo su

sofeware_file="/home/sofeware"
tomcat_dir="/usr/local/webserver/tomcat"
get_tomcat_url=https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v7.0.79/bin/apache-tomcat-7.0.79.tar.gz
# $1 傳入的第一個引數(獲取安裝包的遠端路徑)
if [ ! -n "$1" ];then
 get_tomcat_url=$1
fi
# $2 傳入的第二個引數 (安裝目錄)
if [ ! -n "$2" ];then
  tomcat_dir=$2
fi

if [ ! -d "${sofeware_file}" ];then
  mkdir -p ${sofeware_file}
fi

# create tomcat file
if [ ! -d "$tomcat_dir" ];
then
 mkdir $tomcat_dir
fi

cd $sofeware_file

tomcat_file=$(find `dirname $sofeware_file` -name *tomcat*.tar.gz)
# 遠端獲取
if [ ! -e "$tomcat_file" ];
then
  wget $get_tomcat_url
  if [ $? -ne 0 ];then
   read -p "Remote access failed, do you use default address access?(y/n) " name
   if [ "y" = "$name" ];then
    wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v7.0.79/bin/apache-tomcat-7.0.79.tar.gz
    if [ $? -ne 0 ];then
     echo "Remote access to tomcat installation package failed!"
     exit 0
    fi
   else
     exit 0
   fi
  fi
fi
# 查詢檔案
tomcat_file=$(find `dirname $sofeware_file` -name *tomcat*.tar.gz)
# 解壓
tar -zxvf ${tamcat_file##*/} -C ${tomcat_dir}
# 獲取資料夾名稱
wj_file=$(ls $tomcat_dir/ -l| awk '/^d/{print $NF}')
wj_new_file=${tomcat_dir}/${wj_file}
# 修改埠為 80
sed -i 's/8080/80/' $wj_new_file/conf/server.xml

cd $wj_new_file/bin
# 賦權
chmod u+x *.sh
# 啟動
./startup.sh