yum安装
- tomcat官网:tomcat.apache.org
yum -y install java
mkdir /soft && cd /soft
wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-9/v9.0.76/bin/apache-tomcat-9.0.76.tar.gz
tar xf apache-tomcat-9.0.59.tar.gz
ln -s /soft/apache-tomcat-9.0.59 /soft/tomcat
二进制安装
mkdir /soft/
tar xf jdk-8u60-linux-64.tar.gz -C /app/
ln -s /soft/jdk1.8.0_60 soft/jdk
cat >> /etc/profile << ok
export JAVA_HOME=/soft/jdk
export PATH=$JAVA_HOME/bin:$JAVA_HOME=/jre/bin:$PATH
export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar
ok
tar xf apache-tomcat-9.0.59.tar.gz -C /soft
ln -s /soft/apache-tomcat-9.2.59/ /soft/tomcat
/soft/apache-tomcat/bin/startup.sh
systemctls管理tomcat
vim /etc/systemd/system/tomcat.service
[Unit]
Description=Apache Tomcat Server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/soft/tomcat/bin/startup.sh
ExecStop=/soft/tomcat/bin/shutdown.sh
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable tomcat
Tomcat【配置文件】
[root@nginx tomcat]# ll /soft/tomcat/
total 128
drwxr-x--- 2 root root 4096 Jun 16 16:20 bin :启动、停止脚本
drwx------ 3 root root 254 Jun 16 16:24 conf :配置文件
drwxr-x--- 2 root root 4096 Jun 16 16:20 lib :依赖的jar包
drwxr-x--- 2 root root 197 Jun 16 16:24 logs :日志
drwxr-x--- 2 root root 30 Jun 16 16:20 temp :临时目录
drwxr-x--- 7 root root 81 Jun 5 15:17 webapps :默认站点路径
drwxr-x--- 3 root root 22 Jun 16 16:24 work :缓存文件
[root@nginx tomcat]# vim /soft/tomcat/conf/server.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--关闭tomcat时使用的端口-->
<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="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
maxParameterCount="1000"
/>
<!--引擎,连接器发送的请求,默认给locahost处理-->
<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>