编译安装Tomcat
- 下载jdk (http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)
- 解压jdk
# tar -zxvf jdk-8u65-linux-x64.gz -C /usr/local
# ln -sv /usr/local/jdk1.8.0_65 /usr/local/jdk - 设置jdk环境变量
# vi /etc/profile.d/java.sh
# Set java environment JAVA_HOME=/usr/local/jdk PATH=$PATH:$JAVA_HOME/bin CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export JAVA_HOME PATH CLASSPATH
# source /etc/profile.d/java.sh
- 下载Tomcat
# wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-8/v8.0.29/bin/apache-tomcat-8.0.29.tar.gz - 安装Tomcat
# tar -zxvf apache-tomcat-8.0.29.tar.gz -C /usr/local
# ln -sv /usr/local/apache-tomcat-8.0.29 /usr/local/tomcat - 新建网站根目录并更改SELinux类型
# mkdir -p /data/www && chcon -t httpd_sys_content_t -R /data/www/ - 修改Tomcat网站根目录
# vi /usr/local/tomcat/conf/server.xml
在<Host></Host>节点中增加一行
<Context path="" docBase="/data/www" debug="0" reloadable="true" crossContext="true" /> - 添加tomcat用户和用户组
# useradd -r -M -s /sbin/nologin tomcat - 修改Tomcat安装目录属组
# chown -R tomcat:tomcat /usr/local/tomcat/ - 创建Tomcat自启动脚本
# cd /usr/local/tomcat/bin
# tar -zxvf commons-daemon-native.tar.gz
# cd commons-daemon-1.0.10-native-src/unix
# ./configure --with-java=/usr/local/jdk
# make
# cp jsvc ../..
# cd ../..
# cp daemon.sh /etc/init.d/tomcat - 修改Tomcat自启动脚本
# vi /etc/init.d/tomcat
增加# chkconfig: - 80 20一行,如下所示:
#!/bin/sh # # chkconfig: - 80 20 # # Licensed to the Apache Software Foundation (ASF) under one or more
在注释后增加3行
JAVA_HOME=/usr/local/jdk
CATALINA_HOME=/usr/local/tomcat
TOMCAT_USER=tomcat
如下所示: -
# ----------------------------------------------------------------------------- # Commons Daemon wrapper script. # ----------------------------------------------------------------------------- JAVA_HOME=/usr/local/jdk CATALINA_HOME=/usr/local/tomcat TOMCAT_USER=tomcat # resolve links - $0 may be a softlink
- 设置Tomcat服务自启动
# chmod +x /etc/init.d/tomcat
# chkconfig tomcat on - 启动Tomcat服务
# service tomcat start
yum安装Tomcat
- 安装Java
# yum -y install java - 安装Tomcat
# yum -y install tomcat tomcat-webapps tomcat-admin-webapps - 设置Tomcat服务自启动
# systemctl enable tomcat - 启动Tomcat服务
# systemctl start tomcat