tomcat 部署与实例

简单部署到tomcat

  1. 直接把war包放在 webapps 目录下
  2. 配置server.xml


其中,docBase为设置项目的路径。

  1. 新建 context

运行多份 tomcat

  1. 解压到不同的目录



<Server port="38005" 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="38080" protocol="HTTP/1.1"
                   connectionTimeout="20000"
                   redirectPort="38443" />

        
        <Connector protocol="AJP/1.3"
                   address="::1"
                   port="38009"
                   redirectPort="38443"
                   secretRequired="" />
        <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>

修改conf/logging.properties
修改
java.util.logging.ConsoleHandler.encoding = UTF-8

java.util.logging.ConsoleHandler.encoding = GBK

  1. tomcat-user 配饰
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="admin" password="admin" roles="manager-gui,manager-script,manager-jmx,manager-status"/>

tomcat 单机多实例

  1. 创建目录
[root@laolang tomcat-instance]# pwd
/opt/tomcat-instance
[root@laolang tomcat-instance]# l
total 8.0K
drwxr-xr-x. 7 root root 4.0K Sep 29 09:47 mstudy.com/
drwxr-xr-x. 7 root root 4.0K Sep 29 09:49 tstudy.com/
[root@laolang tomcat-instance]# 
  1. 复制文件
    将conf、logs、webapp、temp、work目录拷贝到你新建的目录中
[root@laolang tomcat-instance]# tree -L 2
.
├── mstudy.com
│   ├── conf
│   ├── logs
│   ├── start.sh
│   ├── stop.sh
│   ├── temp
│   ├── webapps
│   └── work
└── tstudy.com
    ├── conf
    ├── logs
    ├── start.sh
    ├── stop.sh
    ├── temp
    ├── webapps
    └── work

12 directories, 4 files
[root@laolang tomcat-instance]# 
  1. war
    将 war 文件复制到相应的 webapps 目录

  2. 端口
    修改每个tomcat实例中 conf/server.xml中的端口
    tomcat 部署与实例_第1张图片

  3. 脚本
    在每个tomcat实中添加如下两个脚本
    startg

#!/bin/sh
 # tomcat实例目录
export CATALINA_BASE="$PWD"
# tomcat安装目录
export CATALINA_HOME="/opt/tomcat"
echo "S 8251"
echo "C 8200"
cd $CATALINA_HOME
./bin/catalina.sh start

stop

#!/bin/sh
 # tomcat实例目录
export CATALINA_BASE="$PWD"
# tomcat安装目录
export CATALINA_HOME="/opt/tomcat"
echo "S 8251"
echo "C 8200"
cd $CATALINA_HOME
./bin/catalina.sh stop

你可能感兴趣的:(km)