`
Donald_Draper
  • 浏览: 950562 次
社区版块
存档分类
最新评论

Tomcat7,启动过程(BootStrap、Catalina)

阅读更多
Tomcat 系统架构与设计模式,工作原理:http://www.ibm.com/developerworks/cn/java/j-lo-tomcat1/
Tomcat 系统架构与设计模式,设计模式分析:http://www.ibm.com/developerworks/cn/java/j-lo-tomcat2/
Tomcat启动脚本catalina.sh:http://www.xuebuyuan.com/1361490.html
Tomcat学习笔记之catalina.sh:http://www.tuicool.com/articles/fuAnEn3
查看Tomcat的启动过程,我们首先从startup.sh开始看起:
首先查看startup.sh
####解决catalina.sh目录问题
# resolve links - $0 may be a softlink
PRG="$0"
while [ -h "$PRG" ] ; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : '.*-> \(.*\)$'`
  if expr "$link" : '/.*' > /dev/null; then
    PRG="$link"
  else
    PRG=`dirname "$PRG"`/"$link"
  fi
done
PRGDIR=`dirname "$PRG"`
###############shell 脚本文件
EXECUTABLE=catalina.sh
# Check that target executable exists
if $os400; then
  # -x will Only work on the os400 if the files are: 
  # 1. owned by the user
  # 2. owned by the PRIMARY group of the user
  # this will not work if the user belongs in secondary groups
  eval
else
  if [ ! -x "$PRGDIR"/"$EXECUTABLE" ]; then
    echo "Cannot find $PRGDIR/$EXECUTABLE"
    echo "The file is absent or does not have execute permission"
    echo "This file is needed to run this program"
    exit 1
  fi
fi 
###############执行shell脚本文件
exec "$PRGDIR"/"$EXECUTABLE" start "$@"


查看catalina.sh脚本文件:
# +----------------------------------------------------+
# |  ......当执行catalina.sh的参数是start的时候......  |
# |  在新窗口中启动tomcat服务器!!!                  |
# +----------------------------------------------------+

elif [ "$1" = "start" ] ; then

  # 把参数start去掉

  shift
  
  # 创建一个文件(如果文件不存在的话)$CATALINA_BASE/logs/catalina.out  
  #catalina.sh start -security
  # 如果参数是start -security,则启动Security Manager
  if [ "$1" = "-security" ] ; then
    echo "Using Security Manager"
    shift
    "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \
      -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
      -Djava.security.manager \
      -Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \
      -Dcatalina.base="$CATALINA_BASE" \
      -Dcatalina.home="$CATALINA_HOME" \
      -Djava.io.tmpdir="$CATALINA_TMPDIR" \
      org.apache.catalina.startup.Bootstrap "$@" start \
      >> "$CATALINA_BASE"/logs/catalina.out 2>&1 &
      if [ ! -z "$CATALINA_PID" ]; then
        echo $! > $CATALINA_PID
      fi
  # 如果参数是孤单的start,那么在新窗口中启动tomcat
   #catalina.sh start
  else
    "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \
      -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
      -Dcatalina.base="$CATALINA_BASE" \
      -Dcatalina.home="$CATALINA_HOME" \
      -Djava.io.tmpdir="$CATALINA_TMPDIR" \
      org.apache.catalina.startup.Bootstrap "$@" start \
      >> "$CATALINA_BASE"/logs/catalina.out 2>&1 &
      if [ ! -z "$CATALINA_PID" ]; then
        echo $! > $CATALINA_PID
      fi      
  fi

关键在这一句: org.apache.catalina.startup.Bootstrap "$@" start
此句的意义在于启动tomcat的类是org.apache.catalina.startup.Bootstrap.main("start");
下面我们来看Bootstrap :
public final class Bootstrap {
    /**
     * Daemon object used by main.
     */
    private static Bootstrap daemon = null;
     /**
     * Daemon reference.Catalian实例
     */
    private Object catalinaDaemon = null;
    ClassLoader commonLoader = null;
    ClassLoader catalinaLoader = null;
    ClassLoader sharedLoader = null;
 public static void main(String args[]) {

        if (daemon == null) {
            // Don't set daemon until init() has completed
            Bootstrap bootstrap = new Bootstrap();
            try {
	       //初始化
                bootstrap.init();
            } catch (Throwable t) {
	        //处理异常
                handleThrowable(t);
                t.printStackTrace();
                return;
            }
            daemon = bootstrap;
        } else {
            // When running as a service the call to stop will be on a new
            // thread so make sure the correct class loader is used to prevent
            // a range of class not found exceptions.
            Thread.currentThread().setContextClassLoader(daemon.catalinaLoader);
        }

        try {
            String command = "start";
            if (args.length > 0) {
                command = args[args.length - 1];
            }

            if (command.equals("startd")) {
                args[args.length - 1] = "start";
                daemon.load(args);
                daemon.start();
            } else if (command.equals("stopd")) {
                args[args.length - 1] = "stop";
                daemon.stop();
            } else if (command.equals("start")) {
	        //实际上调用catalina.setAwait方法,设置为等待状态标识
                daemon.setAwait(true);
                //调用catalina.load函数,初始化Server,目录,命名空间等
                daemon.load(args);
		//调用catalina.start函数启动Server
                daemon.start();
            } else if (command.equals("stop")) {
                daemon.stopServer(args);
            } else if (command.equals("configtest")) {
                daemon.load(args);
                if (null==daemon.getServer()) {
                    System.exit(1);
                }
                System.exit(0);
            } else {
                log.warn("Bootstrap: command \"" + command + "\" does not exist.");
            }
        } catch (Throwable t) {
            // Unwrap the Exception for clearer error reporting
            if (t instanceof InvocationTargetException &&
                    t.getCause() != null) {
                t = t.getCause();
            }
            handleThrowable(t);
            t.printStackTrace();
            System.exit(1);
        }
    }
    //初始化BootStrap
    public void init()
        throws Exception
    {

        // Set Catalina path
        setCatalinaHome();
        setCatalinaBase();
        initClassLoaders();
	//设置当前线程的类加载器
        Thread.currentThread().setContextClassLoader(catalinaLoader);
        SecurityClassLoad.securityClassLoad(catalinaLoader);
        // Load our startup class and call its process() method
        if (log.isDebugEnabled())
            log.debug("Loading startup class");
        Class<?> startupClass =
            catalinaLoader.loadClass
            ("org.apache.catalina.startup.Catalina");
	//创建Catalina实例
        Object startupInstance = startupClass.newInstance();

        // Set the shared extensions class loader
        if (log.isDebugEnabled())
            log.debug("Setting startup class properties");
        String methodName = "setParentClassLoader";
        Class<?> paramTypes[] = new Class[1];
        paramTypes[0] = Class.forName("java.lang.ClassLoader");
        Object paramValues[] = new Object[1];
        paramValues[0] = sharedLoader;
	//获取Catalina.setParentClassLoader函数
            startupInstance.getClass().getMethod(methodName, paramTypes);
       
	method.invoke(startupInstance, paramValues);
        catalinaDaemon = startupInstance;
    }
    //设置catalina.home System property to the current  
    private void setCatalinaHome() {

        if (System.getProperty(Globals.CATALINA_HOME_PROP) != null)
            return;
        File bootstrapJar =
            new File(System.getProperty("user.dir"), "bootstrap.jar");
        if (bootstrapJar.exists()) {
            try {
                System.setProperty
                    (Globals.CATALINA_HOME_PROP,
                     (new File(System.getProperty("user.dir"), ".."))
                     .getCanonicalPath());
            } catch (Exception e) {
                // Ignore
                System.setProperty(Globals.CATALINA_HOME_PROP,
                                   System.getProperty("user.dir"));
            }
        } else {
            System.setProperty(Globals.CATALINA_HOME_PROP,
                               System.getProperty("user.dir"));
        }
    }
    //设置catalina.base System property to the current  
    private void setCatalinaBase() {

        if (System.getProperty(Globals.CATALINA_BASE_PROP) != null)
            return;
        if (System.getProperty(Globals.CATALINA_HOME_PROP) != null)
            System.setProperty(Globals.CATALINA_BASE_PROP,
                               System.getProperty(Globals.CATALINA_HOME_PROP));
        else
            System.setProperty(Globals.CATALINA_BASE_PROP,
                               System.getProperty("user.dir"));

    }
    //初始化ClassLoaders
     private void initClassLoaders() {
        try {
            commonLoader = createClassLoader("common", null);
            if( commonLoader == null ) {
                // no config file, default to this loader - we might be in a 'single' env.
                commonLoader=this.getClass().getClassLoader();
            }
            catalinaLoader = createClassLoader("server", commonLoader);
            sharedLoader = createClassLoader("shared", commonLoader);
        } catch (Throwable t) {
            handleThrowable(t);
            log.error("Class loader creation threw exception", t);
            System.exit(1);
        }
    }
    //创建ClassLoader加载器
     private ClassLoader createClassLoader(String name, ClassLoader parent)
        throws Exception {

        String value = CatalinaProperties.getProperty(name + ".loader");
        if ((value == null) || (value.equals("")))
            return parent;
        value = replace(value);
        List<Repository> repositories = new ArrayList<Repository>();
        StringTokenizer tokenizer = new StringTokenizer(value, ",");
        while (tokenizer.hasMoreElements()) {
            String repository = tokenizer.nextToken().trim();
            if (repository.length() == 0) {
                continue;
            }
            // Check for a JAR URL repository
            try {
                @SuppressWarnings("unused")
                URL url = new URL(repository);
                repositories.add(
                        new Repository(repository, RepositoryType.URL));
                continue;
            } catch (MalformedURLException e) {
                // Ignore
            }
            // Local repository
            if (repository.endsWith("*.jar")) {
                repository = repository.substring
                    (0, repository.length() - "*.jar".length());
                repositories.add(
                        new Repository(repository, RepositoryType.GLOB));
            } else if (repository.endsWith(".jar")) {
                repositories.add(
                        new Repository(repository, RepositoryType.JAR));
            } else {
                repositories.add(
                        new Repository(repository, RepositoryType.DIR));
            }
        }
        return ClassLoaderFactory.createClassLoader(repositories, parent);
    }
     //实际上调用catalina.setAwait方法,设置为等待状态标识
    public void setAwait(boolean await)
        throws Exception {

        Class<?> paramTypes[] = new Class[1];
        paramTypes[0] = Boolean.TYPE;
        Object paramValues[] = new Object[1];
        paramValues[0] = Boolean.valueOf(await);
        Method method =
            catalinaDaemon.getClass().getMethod("setAwait", paramTypes);
        method.invoke(catalinaDaemon, paramValues);
    }
    //调用catalina.load方法
    private void load(String[] arguments)
        throws Exception {

        // Call the load() method
        String methodName = "load";
        Object param[];
        Class<?> paramTypes[];
        if (arguments==null || arguments.length==0) {
            paramTypes = null;
            param = null;
        } else {
            paramTypes = new Class[1];
            paramTypes[0] = arguments.getClass();
            param = new Object[1];
            param[0] = arguments;
        }
        Method method =
            catalinaDaemon.getClass().getMethod(methodName, paramTypes);
        if (log.isDebugEnabled())
            log.debug("Calling startup class " + method);
        method.invoke(catalinaDaemon, param);
    }
    //调用catalina.start函数启动Server
      public void start()
        throws Exception {
        if( catalinaDaemon==null ) init();

        Method method = catalinaDaemon.getClass().getMethod("start", (Class [] )null);
        method.invoke(catalinaDaemon, (Object [])null);

    }
    //异常处理
      private static void handleThrowable(Throwable t) {
        if (t instanceof ThreadDeath) {
            throw (ThreadDeath) t;
        }
        if (t instanceof VirtualMachineError) {
            throw (VirtualMachineError) t;
        }
        // All other instances of Throwable will be silently swallowed
    }

}

//Catalina
public class Catalina {
    protected String configFile = "conf/server.xml";
    protected Server server = null;
    public void start() {
        if (getServer() == null) {
	    //加载Server实例
            load();
        }
        long t1 = System.nanoTime();
        try {
	    //启动Server
            getServer().start();
        } catch (LifecycleException e) {   
            try {
                getServer().destroy();
            } 
        }
        long t2 = System.nanoTime();
        if(log.isInfoEnabled()) {
            log.info("Server startup in " + ((t2 - t1) / 1000000) + " ms");
        }
        // Register shutdown hook
        if (useShutdownHook) {
            if (shutdownHook == null) {
                shutdownHook = new CatalinaShutdownHook();
            }
            Runtime.getRuntime().addShutdownHook(shutdownHook);
            // If JULI is being used, disable JULI's shutdown hook since
            // shutdown hooks run in parallel and log messages may be lost
            // if JULI's hook completes before the CatalinaShutdownHook()
            LogManager logManager = LogManager.getLogManager();
            if (logManager instanceof ClassLoaderLogManager) {
                ((ClassLoaderLogManager) logManager).setUseShutdownHook(
                        false);
            }
        }
        if (await) {
            await();
            stop();
        }
    }
       //新建一个Server实例
    public void load() {
        initDirs();
        // Before digester - it may be needed
        initNaming();
        // Create and execute our Digester
        Digester digester = createStartDigester();
        InputSource inputSource = null;
        InputStream inputStream = null;
        File file = null;
	//加载"conf/server.xml"文件
        try {
            try {
                file = configFile();
                inputStream = new FileInputStream(file);
                inputSource = new InputSource(file.toURI().toURL().toString());
		} 
            }
            if (inputStream == null) {
                try {
                    inputStream = getClass().getClassLoader()
                        .getResourceAsStream(getConfigFile());
                    inputSource = new InputSource
                        (getClass().getClassLoader()
                         .getResource(getConfigFile()).toString());
                } 
            }

            // This should be included in catalina.jar
            // Alternative: don't bother with xml, just create it manually.
            if( inputStream==null ) {
                try {
                    inputStream = getClass().getClassLoader()
                            .getResourceAsStream("server-embed.xml");
                    inputSource = new InputSource
                    (getClass().getClassLoader()
                            .getResource("server-embed.xml").toString());
                } catch (Exception e) {
                    if (log.isDebugEnabled()) {
                        log.debug(sm.getString("catalina.configFail",
                                "server-embed.xml"), e);
                    }
                }
            }
            if (inputStream == null || inputSource == null) {
                if  (file == null) {
                    log.warn(sm.getString("catalina.configFail",
                            getConfigFile() + "] or [server-embed.xml]"));
                } else {
                    log.warn(sm.getString("catalina.configFail",
                            file.getAbsolutePath()));
                    if (file.exists() && !file.canRead()) {
                        log.warn("Permissions incorrect, read permission is not allowed on the file.");
                    }
                }
                return;
            }
            try {
                inputSource.setByteStream(inputStream);
                digester.push(this);
		//解析conf/server.xml文件
                digester.parse(inputSource);
            } 
        } 
        getServer().setCatalina(this);
        // Stream redirection
        initStreams();
        try {
	    //启动Server
            getServer().init();} 
    }
    //初始化目录环境
     protected void initDirs() {
        //CATALINA_HOME
        String catalinaHome = System.getProperty(Globals.CATALINA_HOME_PROP);
        if (catalinaHome == null) {
            // Backwards compatibility patch for J2EE RI 1.3
            String j2eeHome = System.getProperty("com.sun.enterprise.home");
            if (j2eeHome != null) {
                catalinaHome=System.getProperty("com.sun.enterprise.home");
            } else if (System.getProperty(Globals.CATALINA_BASE_PROP) != null) {
                catalinaHome = System.getProperty(Globals.CATALINA_BASE_PROP);
            }
        }
        // last resort - for minimal/embedded cases.
        if(catalinaHome==null) {
            catalinaHome=System.getProperty("user.dir");
        }
        if (catalinaHome != null) {
            File home = new File(catalinaHome);
            if (!home.isAbsolute()) {
                try {
                    catalinaHome = home.getCanonicalPath();
                } catch (IOException e) {
                    catalinaHome = home.getAbsolutePath();
                }
            }
            System.setProperty(Globals.CATALINA_HOME_PROP, catalinaHome);
        }

        if (System.getProperty(Globals.CATALINA_BASE_PROP) == null) {
            System.setProperty(Globals.CATALINA_BASE_PROP,
                               catalinaHome);
        } else {
            String catalinaBase = System.getProperty(Globals.CATALINA_BASE_PROP);
            File base = new File(catalinaBase);
            if (!base.isAbsolute()) {
                try {
                    catalinaBase = base.getCanonicalPath();
                } catch (IOException e) {
                    catalinaBase = base.getAbsolutePath();
                }
            }
            System.setProperty(Globals.CATALINA_BASE_PROP, catalinaBase);
        }
        String temp = System.getProperty("java.io.tmpdir");
        if (temp == null || (!(new File(temp)).exists())
                || (!(new File(temp)).isDirectory())) {
            log.error(sm.getString("embedded.notmp", temp));
        }
    }
    //初始化Out,Err流
     protected void initStreams() {
        // Replace System.out and System.err with a custom PrintStream
        System.setOut(new SystemLogHandler(System.out));
        System.setErr(new SystemLogHandler(System.err));
    }
    //初始化命名属性
    protected void initNaming() {
        // Setting additional variables
        if (!useNaming) {
            log.info( "Catalina naming disabled");
            System.setProperty("catalina.useNaming", "false");
        } else {
            System.setProperty("catalina.useNaming", "true");
            String value = "org.apache.naming";
            String oldValue =
                System.getProperty(javax.naming.Context.URL_PKG_PREFIXES);
            if (oldValue != null) {
                value = value + ":" + oldValue;
            }
            System.setProperty(javax.naming.Context.URL_PKG_PREFIXES, value);
            if( log.isDebugEnabled() ) {
                log.debug("Setting naming prefix=" + value);
            }
            value = System.getProperty
                (javax.naming.Context.INITIAL_CONTEXT_FACTORY);
            if (value == null) {
                System.setProperty
                    (javax.naming.Context.INITIAL_CONTEXT_FACTORY,
                     "org.apache.naming.java.javaURLContextFactory");
            } else {
                log.debug( "INITIAL_CONTEXT_FACTORY already set " + value );
            }
        }
    }
    //实际调用的为load()
    public void load(String args[]) {

        try {
            if (arguments(args)) {
                load();
            }
        } 
    }
    //根据参数,转化Catalina状态
    protected boolean arguments(String args[]) {

        boolean isConfig = false;

        if (args.length < 1) {
            usage();
            return (false);
        }

        for (int i = 0; i < args.length; i++) {
            if (isConfig) {
                configFile = args[i];
                isConfig = false;
            } else if (args[i].equals("-config")) {
                isConfig = true;
            } else if (args[i].equals("-nonaming")) {
                setUseNaming( false );
            } else if (args[i].equals("-help")) {
                usage();
                return (false);
            } else if (args[i].equals("start")) {
	        //设置为运行状态
                starting = true;
                stopping = false;
            } else if (args[i].equals("configtest")) {
                starting = true;
                stopping = false;
            } else if (args[i].equals("stop")) {
                starting = false;
                stopping = true;
            } else {
                usage();
                return (false);
            }
        }
        return (true);
    }

}

//Digester
public class Digester extends DefaultHandler2 {
   //解析conf/server.xml文件
 public Object parse(InputSource input) throws IOException, SAXException {
 
        configure();
        getXMLReader().parse(input);
        return (root);

    }
    //设置配置状态
     protected void configure() {

        // Do not configure more than once
        if (configured) {
            return;
        }
        log = LogFactory.getLog("org.apache.tomcat.util.digester.Digester");
        saxLog = LogFactory.getLog("org.apache.tomcat.util.digester.Digester.sax");

        //执行懒加载,留给子类扩展
        initialize(); 
        //解析,设置配置状态为true
        configured = true;
    }
     //执行懒加载,留给子类扩展
    protected void initialize() {
    }   
}

总结:
从以上分析,可以得出startup.sh实际,确定catalina.sh的目录,及是否有执行权限,在执行catalina.sh;而Catalina.sh所做的事情实际上是,初始化Catalina,home以及base目录,初始化JVM参数,执行Bootstrap的main(String[]{start))函数,Bootstrap的main函数,也就是tomcat的启动入口。Bootstrap的main(),执行初始化类加载器,设置catalina,home和base目录,设置当前线程的ClassLoader,新建Catalina实例,设置Catalina的父加载器(setParentClassLoader);通过反射获取Catalina的catalina.setAwait方法,设置为等待状态标识(daemon.setAwait(true);),调用catalina.load函数,初始化Server,目录,命名空间等(daemon.load(args);),调用catalina.start函数启动Server。后面Catalina.start()所做的事情(StandardServer,StandardService,
StandardEngin,StandardHost,Wrapper(StandardWrapper),StandardContext,StandardContainer,Connector),我们在后续文章中,再分析。

Tomcat的Server初始化及启动过程:http://donald-draper.iteye.com/admin/blogs/2327060
附:Serve.xml
<?xml version='1.0' encoding='utf-8'?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- Note:  A "Server" is not itself a "Container", so you may not
     define subcomponents such as "Valves" at this level.
     Documentation at /docs/config/server.html
 -->
<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!--APR library loader. Documentation at /docs/apr.html -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
  <Listener className="org.apache.catalina.core.JasperListener" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <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>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->


    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL HTTP/1.1 Connector on port 8080
    -->
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->
    <!-- Define a SSL HTTP/1.1 Connector on port 8443
         This connector uses the BIO implementation that requires the JSSE
         style configuration. When using the APR/native implementation, the
         OpenSSL style configuration is required as described in the APR/native
         documentation -->
    <!--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
               maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" />
    -->

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />


    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine name="Catalina" defaultHost="localhost">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <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>
0
0
分享到:
评论

相关推荐

    Tomcat启动顺序

    Bootstrap--&gt;System --&gt;Common--&gt;Catalina/Shared--&gt;WebApp

    tomcat组件启动时序图.vsdx

    对于tomcat的启动流程分析,从主流程Bootstrap -&gt; Catalina -&gt; Server -&gt; service -&gt; engine,connector;和分流程1.engine-&gt;host-&gt;context-&gt;wrapper ;2.connector -&gt; ProtocolHandler-&gt;Endpoint;之中的方法调用进行...

    Tomcat Using CLASSPATH:报错和启动成功无法访问情况解决方案

    Using CLASSPATH: /www/apache-tomcat-10.0.0-M3-src/bin/bootstrap.jar:/www/apache-tomcat-10.0.0-M3-src/bin/tomcat-juli.jar touch: cannot touch ‘/www/apache-tomcat-10.0.0-M3-src/logs/catalina.out’: No ...

    apache-tomcat-8.5.78 源码 maven 版本

    apache-tomcat-8.5.78 源码 maven 版本,配置都已经搞定,开箱即用。是学习tomcat的不二之选。启动类 org.apache.catalina.startup.Bootstrap

    apache tomcat 8.5.34 源码

    apache tomcat 8.5.34 源码 Mark Directory as Sources Root: java/ Main: org.apache.catalina.startup.Bootstrap.main

    tomcat-src整理的Eclipse项目

    该文件解压后就是Eclipse项目,可直接导入Eclipse 为我们研究tomcat源码提供了方便,运行org.apache.catalina.startup.Bootstrap类的main方法即可启动tomcat。

    cronolog-1.6.2.tar.gz

    要想分割tomcat的catalina.out,需作如下工作: 修改tomcat bin目录下的catalina.sh文件中的 org.apache.catalina.startup.Bootstrap “$@” start \ &gt;&gt; “$CATALINA_BASE”/logs/catalina.out 2&gt;&1 & 为 org....

    带注释的Bootstrap.java

    //catalina.home在运行Bootstrap时已设置(Tomcat的根目录) String home = System.getProperty(Globals.CATALINA_HOME_PROP); File homeFile = null; //获取Tomcat的绝对路径 if (home != null) { File f ...

    tomcat6.0源码(eclipse工程)

    使用SVN 在Apache官网checkout下来的tomcat源码,加入了4个依赖jar包,将ant工程改变成了直接可以导入eclipse的Java工程,org.apache.catalina.startup.Bootstrap是启动类,直接运行里边的main方法即可启动,方便...

    Tomcat6.0.41源代码,可直接导入Eclipse

    可成功编译的Apache Tomcat 6.0.41源代码,可直接导入Eclipse编译运行,入口类为org.apache.catalina.startup.Bootstrap。

    how-tomcat-works

    第17章 启动tomcat 133 17.1 概述 133 17.2 Catalina类 133 17.2.1 start方法 134 17.2.2 stop方法 135 17.2.3 启动Digester 135 17.2.4 关闭Digester 135 17.3 Bootstrap类 136 第18章 部署器 137 18.1 概述 137 ...

    apache-tomcat-7.0.57:关于Apache-tomcat-7.0.57的研究来源

    tomcat-7.0.57====================/org/apache/catalina/startup/Bootstrap---2014/11/28/org/apache/catalina/startup/Catalina---2014/11/28当Bootstrap启动入口传入"startd"指令时,daemon.load(args);...

    apache-tomcat-9.0.8-src可直接导入eclipse的源码

    apache-tomcat-9.0.8-src,官方原版,已经ant过的。可直接导入eclipse 使用。调试入口为org.apache.catalina.startup.Bootstrap

    tomcat8.5:Tomcat8.5源码解析-源码解析

    主类:org.apache.catalina.startup.Bootstrap 参数配置 虚拟机选项: -Dcatalina.home = catalina-home -Dcatalina.base = catalina-home -Djava.endorsed.dirs = catalina-home /认可-Djava.io.tmpdir = catalina...

    How Tomcat Works: A Guide to Developing Your Own Java Servlet Container

    第17章 启动tomcat 133 17.1 概述 133 17.2 Catalina类 133 17.2.1 start方法 134 17.2.2 stop方法 135 17.2.3 启动Digester 135 17.2.4 关闭Digester 135 17.3 Bootstrap类 136 第18章 部署器 137 18.1 概述 137 ...

    tomcat-source-code:tomcat8.x原始码-tomcat source code

    Tomcat的源代码 tomcat8.5.x的源码可以直接导入IDEA中,启动时需要在IDEA添加VM option参数: ...设置Main class : org.apache.catalina.startup.Bootstrap立即直接启动。 IDEA引入Tomcat原始码遇到的问题参考连接:

    tomcat8.0-source-research:这是一个库,我使用Intellij IDEA研究了tomcat8.0的源代码-tomcat source code

    介绍 我得到了tomcat 8.0的源代码,并由avenj在Intellij IDEA 14.1中对其进行了编译。 现在,如果您想阅读源代码,可以将其直接... 查找tomcat-code/java/org/apache/catalina/startup/Bootstrap.java 运行main()方法

    TomcatSourceCode:Tomcat原始码解析与调试-tomcat source code

    调试tomcat原始码添加注释 1.添加调试参数 -Dcatalina.home = C:/用户/ missb / IdeaProjects / tomcat_src / home -Dcatalina.base = C:/ Users / missb / IdeaProjects / ...org.apache.catalina.startup.Bootstrap

    myTomcat:WebServer + Tomcat源码分析总结

    org.apache.catalina.startup.Bootstrap启动startup.sh/bat来启动其main(),main()调用Catalina的process() org.apache.catalina.startup.Catalina类的process():创建Digester对象,注册关闭钩子和调用...

    看透springMvc源代码分析与实践

    7.1.2 Bootstrap的启动过程45 7.1.3 Catalina的启动过程47 7.1.4 Server的启动过程48 7.1.5 Service的启动过程50 7.2 Tomcat的生命周期管理52 7.2.1 Lifecycle接口52 7.2.2 LifecycleBase53 7.3 Container...

Global site tag (gtag.js) - Google Analytics