Tomcat【安装、配置、使用教程】

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 &quot;%r&quot; %s %b" />
      </Host>
    </Engine>
  </Service>
</Server>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

梦有一把琐

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值