实验环境:CentOS7
使用系统yum仓库安装:
#安装基本包和开发工具包 [root@~ localhost]#yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel #配置环境变量 [root@~ localhost]#vim /etc/profile.d/java.sh export JAVA_HOME=/usr [root@~ localhost]#. /etc/profile.d/java.sh #安装Tomcat相关包 [root@~ localhost]#yum -y install tomcat tomcat-webapps tomcat-admin-webapps tomcat-docs-webapp [root@~ localhost]#systemctl start tomcat.service [root@~ localhost]#ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:22 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 100 :::8080 :::* LISTEN 0 128 :::22 :::* LISTEN 0 100 ::1:25 :::* LISTEN 0 1 ::ffff:127.0.0.1:8005 :::* LISTEN 0 100 :::8009 :::*
rpm包的安装方法:
[root@~ localhost]#ls anaconda-ks.cfg apache-tomcat-8.0.23.tar.gz jdk-8u131-linux-x64.rpm #RPM安装JDK [root@bin localhost]#rpm -ivh jdk-8u131-linux-x64.rpm #编辑Java环境变量 [root@bin localhost]#vim /etc/profile.d/java.sh export JAVA_HOME=/usr/java/latest export PATH=$JAVA_HOME/bin:$PATH [root@bin localhost]#. /etc/profile.d/java.sh #安装Tomcat [root@bin localhost]#tar xf apache-tomcat-8.0.23.tar.gz -C /usr/local/ [root@bin localhost]#ln -sv apache-tomcat-8.0.23/ tomcat #编辑Tomcat的环境变量 [root@bin localhost]#vim /etc/profile.d/tomcat.sh export CATALINA_HOME=/usr/local/tomcat export PATH=$CATALINA_HOME/bin:$PATH [root@bin localhost]#. /etc/profile.d/tomcat.sh #测试配置文件 [root@bin localhost]#catalina.sh configtest #启动Tomcat [root@bin localhost]#catalina.sh start
编辑测试脚本:
[root@test localhost]#cd /usr/local/tomcat/webapps/test [root@test localhost]#cat index.jsp <%@ page language="java" %> <%@ page import="java.util.*" %> <html> <head> <title>Test Page</title> </head> <body> <% out.println("hello linux"); %> </body> </html>
在登录的首页,我们可以看到
这三个链接需要相关的配置才可以打开:
#Server Status和Manager APP [root@conf localhost]#vim tomcat-users.xml
<tomcat-users>
<role rolename="manager-gui"/><role rolename="admin-gui"/>
<user username="tomcat" password="tomcat" roles="manager-gui,admin-gui"/>
</tomcat-users>
[root@conf localhost]#catalina.sh stop [root@conf localhost]#catalina.sh start #定义server,Manager和Host
输入用户名和密码就可以登录;