【Tomcat各版本自动化脚本安装】#!/bin/bash# func:Tomcat 6.0/7.0/8.5/9.0 安装# 定义安装目录、及日志信息. /etc/init.d/functions[ $(id -u) != "0" ] && echo "请使用root用户执行" && exit 1export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bindownload_path=/tmp/tmpdir/install_log_name=install_tomcat.logenv_file=/etc/profile.d/tomcat.shinstall_log_path=/var/log/Appinstall/install_path=/usr/local/clearecho "#############################"echo "#安装 tomcat 6.0/7.0/8.5/9.0#"echo "#############################"echo "1: Install tomcat-6.0"echo "2: Install tomcat-7.0"echo "3: Install tomcat-8.5"echo "4: Install tomcat-9.0"echo "5: EXIT"# 选择安装软件版本read -p "Please input your choice:" softversionif [ "${softversion}" == "1" ];thenURL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/tomcat/Apache-tomcat-6.0.9.zip"elif [ "${softversion}" == "2" ];thenURL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/tomcat/apache-tomcat-7.0.79.zip"elif [ "${softversion}" == "3" ];thenURL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/tomcat/apache-tomcat-8.5.20.zip"elif [ "${softversion}" == "4" ];thenURL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/tomcat/apache-tomcat-9.0.0.M26.zip"elif [ "${softversion}" == "5" ];thenecho "you choce channel!"exit 1;elseecho "input Error! Place input{1|2|3|4|5}"exit 0;fi# 传入内容,格式化内容输出,可以传入多个参数,用空格隔开output_msg() {for msg in $*;doaction $msg /bin/truedone}# 判断命令是否存在,第一个参数 $1 为判断的命令,第二个参数为提供该命令的yum 软件包名称check_yum_command() {output_msg "命令检查:$1"hash $1 >/dev/null 2>&1if [ $? -eq 0 ];thenecho "`date +%F' '%H:%M:%S` check command $1 ">>${install_log_path}${install_log_name} && return 0elseyum -y install $2 >/dev/null 2>&1fi}# 判断目录是否存在,传入目录绝对路径,可以传入多个目录check_dir() {output_msg "目录检查"for dirname in $*;do[ -d $dirname ] || mkdir -p $dirname >/dev/null 2>&1echo "`date +%F' '%H:%M:%S` $dirname check success!" >> ${install_log_path}${install_log_name}done}# 下载文件并解压至安装目录,传入url链接地址download_file() {output_msg "下载源码包"mkdir -p $download_pathfor file in $*;dowget $file -c -P $download_path &> /dev/nullif [ $? -eq 0 ];thenecho "`date +%F' '%H:%M:%S` $file download success!">>${install_log_path}${install_log_name}elseecho "`date +%F' '%H:%M:%s` $file download fail!">>${install_log_path}${install_log_name} && exit 1fidone}# 解压文件,可以传入多个压缩文件绝对路径,用空格隔开,解压至安装目录extract_file() {output_msg "解压源码"for file in $*;doif [ "${file##*.}" == "gz" ];thentar -zxf $file -C $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name}elif [ "${file##*.}" == "zip" ];thenunzip -q $file -d $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name}elseecho "`date +%F' '%H:%M:%S` $file type error, extrac fail!">>${install_log_path}${install_log_name} && exit 1fidone}# 配置环境变量,第一个参数为添加环境变量的绝对路径config_env() {output_msg "环境变量配置"echo "export PATH=$PATH:$1" >${env_file}source ${env_file} && echo "`date +%F' '%H:%M:%S` 软件安装完成!">> ${install_log_path}${install_log_name}}main() {check_dir $install_log_path $install_pathcheck_yum_command wget wgetcheck_yum_command unzip unzipdownload_file $URLsoftware_name=$(echo $URL|awk -F'/' '{print $NF}'|awk -F'.zip' '{print $1}')for filename in `ls $download_path`;doextract_file ${download_path}$filenamedonerm -fr ${download_path}ln -s $install_path$software_name ${install_path}tomcatconfig_env ${install_path}tomcat/bin}main
推荐阅读
- redis5.0.7 版本集群liunx部署简易流程
- 各种生物只能埋藏在与它们不同时期的地层当中 一些科学家认为在6500万年前
- tomcat启动流程个人小计
- 红茶、绿茶、黄茶、白茶、黑茶、乌龙茶各有什么特征?怎么区分?[红茶]
- 休闲沙发介绍 各类沙发的分类
- 11种养生茶搭配表,各种养生茶搭配及功效[养生茶]
- 养生壶煮茶的各种配方夏季,养生壶适合煮什么茶?[养生茶]
- 地球演变的五个时代及各时期代表性动植物 地球演变的五个时代和对应图片
- 各个行星到地球的距离 几千光年的行星怎么探测到的
- 外星信号是怎么破译的