在进行安装配置Tomcat前请确保系统中已安装jdk并配置好java的环境变量,tomcat与jdk版本对应表如下所示
Servlet Spec | JSP Spec | EL Spec | WebSocket Spec | JASPIC Spec | Apache Tomcat Version | Latest Released Version | Supported Java Versions |
4.0 | TBD (2.4?) | TBD (3.1?) | TBD (1.2?) | 1.1 | 9.0.x | 9.0.0.M21 (alpha) | 8 and later |
3.1 | 2.3 | 3.0 | 1.1 | 1.1 | 8.5.x | 8.5.15 | 7 and later |
3.1 | 2.3 | 3.0 | 1.1 | N/A | 8.0.x (superseded) | 8.0.44 (superseded) | 7 and later |
3.0 | 2.2 | 2.2 | 1.1 | N/A | 7.0.x | 7.0.78 | 6 and later(7 and later for WebSocket) |
2.5 | 2.1 | 2.1 | N/A | N/A | 6.0.x | 6.0.53 | 5 and later |
2.4 | 2.0 | N/A | N/A | N/A | 5.5.x (archived) | 5.5.36 (archived) | 1.4 and later |
2.3 | 1.2 | N/A | N/A | N/A | 4.1.x (archived) | 4.1.40 (archived) | 1.3 and later |
2.2 | 1.1 | N/A | N/A | N/A | 3.3.x (archived) | 3.3.2 (archived) | 1.1 and later |
下面以安装配置tomcat 8.5.15为例。
1.到tomcat官网下载tomcat 8.5.15.tar.gz.
#wget –O apache-tomcat-8.5.15.tar.gz http://mirrors.hust.edu.cn/apache/tomcat/tomcat-8/v8.5.15/bin/apache-tomcat-8.5.15.tar.gz
2.将下载好的压缩文件解压到当前文件夹,并复制到/usr/local/,且重命名为tomcat8
#tar zxvf apache-tomcat-8.5.15.tar.gz #cp –R apache-tomcat-8.5.15 /usr/local/tomcat8
3.切换目录至/usr/local/tomvat8/bin,启动tomcat服务器
#cd /usr/local/tomcat8/bin #./startup.sh
启动成功后,可以访问http://你的IP:8080,若访问成功,出现如下tomcat管理页面则表示安装成功,否则为安装失败。
4.因为此时tomcat并没有设置角色以及用户名密码等信息,所以点击manager apps等按钮时会出现403错误,此时需配置tomcat-users.xml添加角色及用户名密码,在tomcat-users.xml中<tomcat-users>*</tomcat-users>标签中间添加如下内容
<role rolename="tomcat"/> <role rolename="manager-gui"/> <user username="admin" password="123456" roles="tomcat,manager-gui"/>
5.配置好tomcat-users.xml文件后,重新启动服务器,若点击manager apps等按钮仍出现403错误,则需要对/usr/local/tomcat8/webapps/manager/META-INF/context.xml进行修改,注释掉其中的value标签。
<Context antiResourceLocking="false" privileged="true" > <!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" > --> </Context>
再次重新启动tomcat,此时发现manager apps等功能已可以正常使用