Tomcat部署步骤
2.1、下载并安装JDK
1、JDK是Java语言的软件开发工具包
2、JDK是Tomcat运行的必要环境
3、根据计算机硬件配置,选择安装包
[root@server1 opt]# tar zxf jdk-8u91-linux-x64.tar.gz
[root@server1 opt]# mv jdk1.8.0_91/ /usr/local/java
[root@server1 opt]# cd /etc/profile.d/
[root@server1 profile.d]# vim java.sh
export JAVA_HOME=/usr/local/java ###设置java根目录
export PATH=$PATH:$JAVA_HOME/bin ###在PATH环境变量中添加JAVA根目录下的bin子目录
[root@server1 profile.d]# source java.sh ###java.sh脚本导入到环境变量中,使其生效
[root@server1 ~]# java -version ###查看版本
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-b12)
OpenJDK 64-Bit Server VM (build 25.131-b12, mixed mode)
2.2、安装并启动Tomcat
[root@server1 opt]# tar zxf apache-tomcat-8.5.16.tar.gz
[root@server1 opt]# mv apache-tomcat-8.5.16 /usr/local/tomcat8
[root@server1 opt]# /usr/local/tomcat8/bin/startup.sh ###启动tomcat
Using CATALINA_BASE: /usr/local/tomcat8
Using CATALINA_HOME: /usr/local/tomcat8
Using CATALINA_TMPDIR: /usr/local/tomcat8/temp
Using JRE_HOME: /usr/local/java
Using CLASSPATH: /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar
Tomcat started.
[root@server1 opt]# /usr/local/tomcat8/bin/shutdown.sh ###关闭tomcat
Using CATALINA_BASE: /usr/local/tomcat8
Using CATALINA_HOME: /usr/local/tomcat8
Using CATALINA_TMPDIR: /usr/local/tomcat8/temp
Using JRE_HOME: /usr/local/java
Using CLASSPATH: /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar
[root@server1 ~]# ln -s /usr/local/tomcat8/bin/startup.sh /usr/bin/tomcatup ##优化执行路径
[root@server1 ~]# ln -s /usr/local/tomcat8/bin/shutdown.sh /usr/bin/tomcatdown
[root@server1 ~]# tomcatup
Using CATALINA_BASE: /usr/local/tomcat8
Using CATALINA_HOME: /usr/local/tomcat8
Using CATALINA_TMPDIR: /usr/local/tomcat8/temp
Using JRE_HOME: /usr/local/java
Using CLASSPATH: /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar
Tomcat started.
[root@server1 ~]# netstat -anpt | grep 8080
tcp6 0 0 :::8080 :::* LISTEN 48759/java
[root@server1 ~]# systemctl stop firewalld
[root@server1 ~]# setenforce 0
在浏览器中输入 http://192.168.158.10:8080 即可访问tomcat主页
2.3、Tomcat常用文件
●bin
存放启动和关闭Tomcat扽脚本文件,比较常用的是catalina.sh、startup.sh、shutdown.sh三个文件
●conf
存放Tomcat服务器的各种配置文件,比较常用的是server.xml、context.xml、tomcat-users.xml、web.xml四个文件
●lib
存放Tomcat服务器的jar包,一般不作任何改动,除非连接第三方服务,比如redis,那就需要添加相对应的jar包
●logs
存放tomcat日志
●temp
存放Tomcat运行时产生的文件
●webapps
存放项目资源的目录
●work
Tomcat工作目录,一般清除Tomcat缓存的时候会使用到
三、配置虚拟主机
3.1、基于域名
1、创建主页并修改主页内容
[root@server1 ~]# mkdir -p /var/www/html
[root@server1 ~]# mkdir -p /var/www/tom
[root@server1 ~]# mkdir -p /var/www/jerry
[root@server1 ~]# vi /var/www/tom/index.jsp
<h1>tom</h1>
2、修改Tomcat主配置文件
[root@server1 ~]# vi /var/www/jerry/index.jsp
<h1>jerry</h1>
#末行合适位置添加
[root@server1 ~]# vi /web/webapp1/test1/index.jsp
</Host>
<Host name="www.tom.com" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context docBase="/var/www/tom" path="" reloadable="false" />
</Host>
<Host name="www.jerry.com" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context docBase="/var/www/jerry" path="" reloadable="false" />
</Host>
</Engine>
</Service>
</Server>
3、本地增加映射
[root@server1 ~]# vi /etc/hosts
192.168.158.10 www.tom.com www.jerry.com