官网下载最新的tomcat9,解压 http://tomcat.apache.org/download-90.cgi
环境变量配置
**JAVA_HOME: **
C:Program FilesJavajdk1.8.0_91
CLASS_PATH:
.;%JAVA_HOME%lib;%JAVA_HOME%lib ools.jar
PATH:
;%JAVA_HOME%in;
安装服务
D:apache tomcat9_x64in下面cmd
service install
net start tomcat9
部署项目
文件拷贝到D:apache tomcat9_x64webapps下面
多站点配置
1. 同一服务端口下多域名多站点的配置
修改配置文件D:apache tomcat9_x64confserver.xml
在Engine节点下添加Host节点
<Host name="boystyle.cn"
debug="0"
appBase="webapps"
unpackWARs="true"
autoDeploy="true"
xmlValidation="false"
xmlNamespaceAware="false">
<Alias>www.boystyle.cn</Alias>
<Logger className="org.apache.catalina.logger.FileLogger"
directory="logs"
prefix="localhost_log."
suffix=".txt"
timestamp="true"/>
<Context path=""
docBase="D:apache tomcat9_x64webappsexamples"
reloadable="true"
caseSensitive="false"
debug="0">
</Context>
</Host>
<Host name="qiuboai.com"
debug="0"
appBase="webapps"
unpackWARs="true"
autoDeploy="true"
xmlValidation="false"
xmlNamespaceAware="false">
<Alias>www.qiuboai.com</Alias>
<Logger className="org.apache.catalina.logger.FileLogger"
directory="logs"
prefix="localhost_log."
suffix=".txt"
timestamp="true"/>
<Context path=""
docBase="D:apache tomcat9_x64webappsexamples"
reloadable="true"
caseSensitive="false"
debug="0">
</Context>
</Host>
这样使用下面两个url都能访问了
http://www.boystyle.cn:8080/
http://www.qiuboai.com:8080/
2. 多服务端口多站点的配置
http://linder.iteye.com/blog/782071
Tomcat 6.0 配置多个端口,其实也就是给Tomcat增加几个server,并设置对应目录。下面以增加两个端口号
注意Service, Engine, appBase名字应不同
<Service name="Catalina_1">
<Connector port="8080"
maxHttpHeaderSize="8192"
maxThreads="150"
minSpareThreads="25"
maxSpareThreads="75"
enableLookups="false"
redirectPort="8443"
acceptCount="100"
connectionTimeout="20000"
disableUploadTimeout="true"/>
<Connector port="8009"
enableLookups="false"
redirectPort="8443"
protocol="AJP/1.3"/>
<Engine name="Catalina_1"defaultHost="localhost">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"resourceName="UserDatabase"/>
<!-- appBase: 每个service应配置独立的跟路径,可以在tomcat根目录下新建文件夹 -->
<Host name="localhost"
appBase="webapps1"
unpackWARs="true"
autoDeploy="true"
xmlValidation="false"
xmlNamespaceAware="false">
</Host>
</Engine>
</Service>
<Service name="Catalina_2">
<Connector port="8080"
maxHttpHeaderSize="8192"
maxThreads="150"
minSpareThreads="25"
maxSpareThreads="75"
enableLookups="false"
redirectPort="8443"
acceptCount="100"
connectionTimeout="20000"
disableUploadTimeout="true"/>
<Connector port="8009"
enableLookups="false"
redirectPort="8443"
protocol="AJP/1.3"/>
<Engine name="Catalina_2"defaultHost="localhost">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"resourceName="UserDatabase"/>
<Host name="localhost"
appBase="webapps2"
unpackWARs="true"
autoDeploy="true"
xmlValidation="false"
xmlNamespaceAware="false">
</Host>
</Engine>
</Service>
之后需要参考默认的服务添加配置目录和配置文件
D:apache tomcat9_x64confCatalina
D:apache tomcat9_x64confCatalina_1
D:apache tomcat9_x64confCatalina_2
错误排查
遇到错误不要怕,看一下log文件就知道了
$ tree "D:apache tomcat9_x64logs" /f
卷 软件 的文件夹 PATH 列表
卷序列号为 000E-E536
D:APACHE TOMCAT9_X64LOGS
catalina.2016-12-10.log
commons-daemon.2016-12-10.log
host-manager.2016-12-10.log
localhost.2016-12-10.log
localhost_access_log.2016-12-10.txt
manager.2016-12-10.log
tomcat9-stderr.2016-12-10.log
tomcat9-stdout.2016-12-10.log