安装Tomcat
1 下载Tomcat
2 上传虚拟机
- 上传用到xshell、xftp => 下载
unzip xxx.zip -d /home/path/tomcat #解压
chmod -R 775 /home/path/tomcat #赋予执行权限
3 配置Tomcat
-
Tomcat是Java语言编写的也是jar包启动的,只要jdk配置完成 -
java -jar 命令可以执行,此时就可以启动Tomcat了 -
配置jdk查看 => Linux安装Java jdk -
/home/path/tomcat/apache-tomcat-9.0.52/bin/startup.sh #使用bin下的sh脚本启动默认配置的Tomcat -
/home/path/tomcat/apache-tomcat-9.0.52/bin/shutdown.sh #关闭tomcat,准备自定义配置tomcat
配置Tomcat
- 修改tomcat启动端口
cd /home/path/tomcat/apache-tomcat-9.0.52/conf/ #进入配置文件夹找到server.xml vi server.xml #编辑修改端口8284 => 中文配置文件,附录自行获取
映射tomcat应用文件 => 不需要的不要设置
-
tomcat可以将前端的html等文件放置
webapps 目录下
也可以用映射路径的方式去映射文件路径
<!--
映射路径 => 如果不需要映射请不要添加这个,找不到真实路径会报错。
path: 访问localhost:8080/web/gis/monitor 会去映射的docBase路径下找文件
相当于已经将文件放到了webapps目录下,不用手动将文件放置webapps下面。
docBase: 真实文件存放的位置。
workDir: 存放一些编译的文件,大多都是指jsp编译成class文件。
crossContext: 多个应用部署在一个tomcat时,true表示可以互相照顾。
-->
<!--
<Context path="/web/gis/monitor" docBase="/home/sg/sgssjd/ONEMAP/SSJD/web/sfs-gis-monitor" workDir="" crossContext="true" />
<Context path="/web/gis/sdk" docBase="/home/sg/sgssjd/ONEMAP/BASE/web/sfs-gis-sdk" workDir="" crossContext="true" />
<Context path="/web/gis/manage" docBase="/home/sg/sgssjd/ONEMAP/BASE/web/sfs-gis-manage" workDir="" crossContext="true" />
<Context path="/web/gis/home" docBase="/home/sg/sgssjd/ONEMAP/BASE/web/sfs-gis-home" workDir="" crossContext="true" />
<Context path="/web/gis/bi" docBase="/home/sg/sgssjd/ONEMAP/BASE/web/sfs-gis-bi" workDir="" crossContext="true" />
<Context path="/monitor/mis" docBase="/home/sg/sgssjd/ONEMAP/BASE/web/mis" workDir="" crossContext="true" />
<Context path="/monitor/cdn" docBase="/home/sg/sgssjd/ONEMAP/BASE/web/cdn" workDir="" crossContext="true" />
<Context path="/home/file" docBase="/home/sg/sgssjd/ONEMAP/file" reloadable="true" />
<Context path="/web/gis/proxy" docBase="/home/sg/sgssjd/ONEMAP/BASE/web/sfs-gis-sdk/proxy"
workDir="/home/sg/sgssjd/ONEMAP/BASE/web/sfs-gis-sdk/proxy/WEB-INF/classes" crossContext="true" />
-->
4 开机启动脚本
vi /etc/init.d/tomcat #编辑一个启动脚本,开机自启chkconfig --add tomcat #添加到系统快捷执行脚本中
service xxx #用service命令执行创建的脚本 chkconfig tomcat on #开机自动执行
export JAVA_HOME=/home/path/java/jdk1.8.0_301
export JRE_HOME=/home/path/java/jdk1.8.0_301/jre
export CATALINA_HOME=/home/path/tomcat/apache-tomcat-9.0.52
export CATALINA_BASE=/home/path/tomcat/apache-tomcat-9.0.52
start()
{
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"启动 Tomcat"
$CATALINA_HOME/bin/startup.sh
echo $"启动完成"
fi
}
stop()
{
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"停止 Tomcat"
$CATALINA_HOME/bin/shutdown.sh
echo $"成功停止"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
echo $"重启 Tomcat"
stop
sleep 1
start
;;
*)
echo $"重启 Tomcat"
stop
sleep 1
start
;;
esac
exit 0
service tomcat stop #start/stop/restart => 启动/停止/重启(无参数默认重启)
开放端口
- 添加指定需要开放的端口:
firewall-cmd --add-port=8284/tcp --permanent - 重载入添加的端口:
firewall-cmd --reload
附录
tomcat中文配置文件
<?xml version="1.0" encoding="UTF-8"?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
<Connector port="8284" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
</Server>
|