一、安装JDK
1.1 下载JDK
官网下载地址
1.2 安装JDK
#cat install_jdk.sh
#!/bin/bash
DIR=`pwd`
JDK_FILE="jdk-8u291-linux-x64.tar.gz"
JDK_DIR="/usr/local"
color () {
RES_COL=60
MOVE_TO_COL="echo -en \\033[${RES_COL}G"
SETCOLOR_SUCCESS="echo -en \\033[1;32m"
SETCOLOR_FAILURE="echo -en \\033[1;31m"
SETCOLOR_WARNING="echo -en \\033[1;33m"
SETCOLOR_NORMAL="echo -en \E[0m"
echo -n "$2" && $MOVE_TO_COL
echo -n "["
if [ $1 = "success" -o $1 = "0" ] ;then
${SETCOLOR_SUCCESS}
echo -n $" OK "
elif [ $1 = "failure" -o $1 = "1" ] ;then
${SETCOLOR_FAILURE}
echo -n $"FAILED"
else
${SETCOLOR_WARNING}
echo -n $"WARNING"
fi
${SETCOLOR_NORMAL}
echo -n "]"
echo
}
install_jdk(){
if ! [ -f "$DIR/$JDK_FILE" ];then
color 1 "$JDK_FILE 文件不存在"
exit;
elif [ -d $JDK_DIR/jdk ];then
color 1 "JDK 已经安装"
exit
else
[ -d "$JDK_DIR" ] || mkdir -pv $JDK_DIR
fi
tar xvf $DIR/$JDK_FILE -C $JDK_DIR
cd $JDK_DIR && ln -s jdk1.8.* jdk
export JAVA_PATH="`ls /usr/local/jdk1.* -d`/bin/"
cat > /etc/profile.d/jdk.sh <<EOF
export JAVA_HOME=$JDK_DIR/jdk
export JRE_HOME=\$JAVA_HOME/jre
export CLASSPATH=\$JAVA_HOME/lib/:\$JRE_HOME/lib/
export PATH=$JAVA_PATH:\$JAVA_HOME:\$PATH
EOF
chmod +x /etc/profile.d/jdk.sh
. /etc/profile.d/jdk.sh
java -version && color 0 "JDK 安装完成" || { color 1 "JDK 安装失败" ; exit; }
}
install_jdk
#bash install_jdk.sh
二、安装tomcat
2.1 源码包下载及安装
#wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.75/bin/apache-tomcat-8.5.75.tar.gz
#tar xvf apache-tomcat-8.5.75.tar.gz -C /usr/local
#cd /usr/local/
#ln -s apache-tomcat-8.5.75/ tomcat
#echo 'PATH=/usr/local/tomcat/bin:$PATH' > /etc/profile.d/tomcat.sh
#chmod +x /etc/profile.d/tomcat.sh
#. /etc/profile.d/tomcat.sh
2.2 添加用户
#useradd tomcat -s /sbin/nologin
#chown -R tomcat.tomcat /usr/local/tomcat/
#chown -R tomcat.tomcat /usr/local/apache-tomcat-8.5.75/
2.3 启动tomcat
#startup.sh