ubuntu 17.04 Tomcat安装
安装Tomcat分为两步: JDK和Tomcat
安装jdk
1、在oralce官网下载jdk
2、解压并创建jdk目录
~# tar jdk-89121-linux-x64.tar.gz
~# mkdir /usr/lib/jvm
~# cp -R jdk1.8.0_121 /usr/lib/jvm
3、添加环境变量
在/etc/bash.bashrc末尾添加以下内容后重启
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_121
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
4、测试jdk
# source /etc/bash.bashrc
# java -version
Tomcat安装
1、在apache tomcat官网下载最新版本tomcat
2、解压并复制到/opt目录
~# mkdir /opt/tomcat
~# tar -zxvf apache-tomcat-9.0.0.M17.tar.gz -C /opt/tomcat/
3、创建启动文件 tomcat.service, 设置为开机启动
可选 # sed '136a# Setting tomcat.pid' -i /opt/tomcat/apache-tomcat-9.0.0.M17/bin/catalina.sh
可选 # sed '137aCATALINA_PID="\$CATALINA_BASE/tomcat.pid"' -i /opt/tomcat/apache-tomcat-9.0.0.M17/bin/catalina.sh
cat <<EOF >> /usr/lib/systemd/system/tomcat.service
[Unit]
Description=Tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=oneshot
ExecStart=/opt/tomcat/apache-tomcat-9.0.0.M17/bin/startup.sh
ExecStop=/opt/tomcat/apache-tomcat-9.0.0.M17/bin/shutdown.sh
ExecReload=/bin/kill -s HUP $MAINPID
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
EOF
# systemctl enable tomcat.service
# systemctl start tomcat.service
4、启动tomcat