您的位置:首页 > 运维架构 > Shell

linux使用shell一键安装tomcat 并更改访问端口为 80

2018-03-16 11:08 721 查看
#!/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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  shell