読者です 読者をやめる 読者になる 読者になる

decadence

個人のメモ帳

Tomcat: Configuration References 1

tomcat Java

Tomcat 8 Configuration Reference

  • server.xml
  • configs
    • Http Connector
    • Context
    • Engine
    • Host
  • Automatic Application Deployment

server.xml

  • Server
    • 1つ以上のServiceを持てる
  • Service
    • 1つのEngineと、1つ以上のConnectorを持ち、これらをまとめるもの
  • Engine
    • 1つのServiceに紐づく
  • Executor
    • Connectorより前に記述しなきゃだめ?
  • Connector
    • リクエストを待ち受けてEngineへ渡す
  • Realm
    • 認可
  • Host
    • Engineに紐づく仮想ホスト
    • DNSに紐付けられるもの
  • Context
    • Tomcat上で実行される1つのWebアプリケーションでservlet contextコンテナ
    • context.xml → web.xml(WatchedResource)
  • Valve
    • tomcat専用、リクエストに対するフィルタ (e.g. AccessLogValve)
Server (StandardServer)
  ├── Listener*
  ├── GlobalNamingResource (NamingResourcesImpl)
  └── Service* (StandardService)
        ├── Listener*
        ├── Executor (StandardThreadExecutor)
        ├── Connector*
        │     ├── Listener*
        │     ├── UpgradeProtocol (:Http2Protocol)
        │     └── SSLHostConfig
        │           └── Certificate
        └── Engine (StandardEngine)
              ├── Listener*
              ├── Realm
              ├── Valve
              └── Host (StandardHost)
                   ├── Realm
                   ├── Valve
                   ├── Cluster
                   └── Context (StandardContext)
                        ├── Cookie Processor
                        ├── Loader
                        ├── Manager: Configure the session manager
                        ├── Realm
                        ├── Resources
                        ├── WartchedResource: auto deployer will monitor this
                        └── JarScanner

適当にパラメータ眺める

maxThreadsとか、有名過ぎるのは除く

(大体、有名なチューニングパラメータ以外はデフォルトでよさげ)

HTTP Connector

http://tomcat.apache.org/tomcat-8.0-doc/config/http.html

enableLookups

Set to true if you want calls to request.getRemoteHost() to perform DNS lookups in order to return the actual host name of the remote client. Set to false to skip the DNS lookup and return the IP address in String form instead (thereby improving performance). By default, DNS lookups are disabled.

protocol

org.apache.coyote.http11.Http11Protocol - blocking Java connector org.apache.coyote.http11.Http11NioProtocol - non blocking Java NIO connector org.apache.coyote.http11.Http11Nio2Protocol - non blocking Java NIO2 connector org.apache.coyote.http11.Http11AprProtocol - the APR/native connector.

http://tomcat.apache.org/tomcat-8.0-doc/config/http.html#Connector_Comparison

connectionLinger

The number of seconds during which the sockets used by this Connector will linger when they are closed. The default value is -1 which disables socket linger.

server

Overrides the Server header for the http response. ... If the application does not specify a value then Apache-Coyote/1.1 is used.

Context

http://tomcat.apache.org/tomcat-8.0-doc/config/context.html

cross Context

Set to true if you want calls within this application to ServletContext.getContext() to successfully return a request dispatcher for other web applications running on this virtual host. Set to false (the default) in security conscious environments, to make getContext() always return null.

reloadable

Set to true if you want Catalina to monitor classes in /WEB-INF/classes/ and /WEB-INF/lib for changes, and automatically reload the web application if a change is detected. This feature is very useful during application development, but it requires significant runtime overhead and is not recommended for use on deployed production applications. That's why the default setting for this attribute is false. You can use the Manager web application, however, to trigger reloads of deployed applications on demand.

本番では使わないほうがいいって see also Manager

sessionCookieDomain

The domain to be used for all session cookies created for this context. If set, this overrides any domain set by the web application. If not set, the value specified by the web application, if any, will be used.

sessionCookieName

The name to be used for all session cookies created for this context. If set, this overrides any name set by the web application. If not set, the value specified by the web application, if any, will be used, or the name JSESSIONID if the web application does not explicitly set one.

sessionCookiePath

The path to be used for all session cookies created for this context. ... If not set, the value specified by the web application will be used, or the context path used if the web application does not explicitly set one. To configure all web application to use an empty path set this attribute to / in the global CATALINA_BASE/conf/context.xml file. Note: Once one web application using sessionCookiePath="/" obtains a session, all subsequent sessions for any other web application in the same host also configured with sessionCookiePath="/" will always use the same session ID. ...

Engine

http://tomcat.apache.org/tomcat-8.0-doc/config/engine.html

backgroundProcessorDelay

This value represents the delay in seconds between the invocation of the backgroundProcess method on this engine and its child containers, including all hosts and contexts. Child containers will not be invoked if their delay value is not negative (which would mean they are using their own processing thread). Setting this to a positive value will cause a thread to be spawn. After waiting the specified amount of time, the thread will invoke the backgroundProcess method on this engine and all its child containers. If not specified, the default value for this attribute is 10, which represent a 10 seconds delay.

startStopThreads

The number of threads this Engine will use to start child Host elements in parallel. The special value of 0 will result in the value of Runtime.getRuntime().availableProcessors() being used. Negative values will result in Runtime.getRuntime().availableProcessors() + value being used unless this is less than 1 in which case 1 thread will be used. If not specified, the default value of 1 will be used.

Host

http://tomcat.apache.org/tomcat-8.0-doc/config/host.html

see following Automatic Application Deployment

appBase

the default of webapps will be used.

xmlBase

the default of conf/<engine_name>/<host_name> will be used.

autoDeploy

This flag value indicates if Tomcat should check periodically for new or updated web applications while Tomcat is running. If true, Tomcat periodically checks the appBase and xmlBase directories and deploys any new web applications or context XML descriptors found. Updated web applications or context XML descriptors will trigger a reload of the web application. The flag's value defaults to true.

see also deployIgnore

deployOnStartup

This flag value indicates if web applications from this host should be automatically deployed when Tomcat starts. The flag's value defaults to true.

startStopThreads

see Engine.startStopThreads

undeployOldVersions

This flag determines if Tomcat, as part of the auto deployment process, will check for old, unused versions of web applications deployed using parallel deployment and, if any are found, remove them. This flag only applies if autoDeploy is true. If not specified the default value of false will be used.

Automatic Application Deployment

http://tomcat.apache.org/tomcat-8.0-doc/config/host.html#Automatic_Application_Deployment

試す

  • Hostに以下のパラメータ付ける(デフォルトでついてるもの含む)
<Host name="localhost" appBase="webapps"
      unpackWARs="true" autoDeploy="true"
      deployOnStartup="true">
  • conf/context.xml
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
  • 適当な war を webapps 以下に置く
  • 起動 bin/startup.sh
    • curl localhost:8080/pingok
  • war を入れ替えて webapps 以下に置く
    • WatchedResourceの対象外のため何も起こらない
  • touch conf/web.xml
    • WatchedResourceで見てるファイルを変更する
      • touchするだけで良かった安心
    • webapps以下のwar全部見るとかでも良いかも
  • tail -f logs/catalina.out してると勝手にリロードされてるのが分かる
24-Oct-2015 00:36:47.618 INFO [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.reload Reloading context []
24-Oct-2015 00:36:47.618 INFO [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.core.StandardContext.reload このコンテキストの再ロードを開始しました
...
  • 変わってる
    • curl localhost:8080/pingchanged

リロード中は、上記リクエストに対し、tomcatから404が返されるので、L7チェックでLBから外しながらローリングデプロイかな

広告を非表示にする