|
|
(3 intermediate revisions by the same user not shown) |
Line 16: |
Line 16: |
| |width="20%"| [[Tomcat users management|Users management]] | | |width="20%"| [[Tomcat users management|Users management]] |
| |width="20%"| [[Tomcat MySQL datasource|MySQL datasource]] | | |width="20%"| [[Tomcat MySQL datasource|MySQL datasource]] |
− | |width="20%"| Apache 2 proxy | + | |width="20%"| [[Apache 2 - proxy]] |
| |- | | |- |
| | [[Tomcat linux manual setup|Linux manual setup]] | | | [[Tomcat linux manual setup|Linux manual setup]] |
− | || [[Tomcat UTF-8|UTF-8]] | + | || [[Tomcat UTF-8|UTF-8]] || || |
− | || | |
− | || | |
| |- | | |- |
| | [[Tomcat Linux startup|Linux Tomcat on boot]] | | | [[Tomcat Linux startup|Linux Tomcat on boot]] |
− | || [[Tomcat IPv4 over IPv6|IPv4 over IPv6]] | + | || [[Tomcat IPv4 over IPv6|IPv4 over IPv6]] || || |
− | || Example || Example | |
| |- | | |- |
− | | [[Tomcat windows setup|Windows setup]] | + | | [[Tomcat windows setup|Windows setup]] |
− | || [[Tomcat JMX|JMX configuration]] | + | || [[Tomcat security restricted access|Server access restriction]] || || |
− | || Example || Example | |
| |- | | |- |
− | | || [[Tomcat increase PermGen|Increase PermGen]] || Example || Example | + | | || [[Tomcat JMX|JMX configuration]] || || |
| |- | | |- |
− | | | [[Tomcat war deployment through manager|War deployment through manager]] || Example || Example | + | | || [[Tomcat increase PermGen|Increase PermGen]] || || |
| + | |- |
| + | | || [[Tomcat war deployment through manager|War deployment through manager]] || || |
| |} | | |} |
| | | |
| | | |
− |
| |
− |
| |
− |
| |
− | =Server configuration=
| |
− |
| |
− |
| |
− | ==War deployment==
| |
− | There is 2 ways to deploy a war:
| |
− | * By pushing the target war into ${Tomcat root} / webapps
| |
− | * By using the graphical tool http://localhost:8080/manager
| |
− |
| |
− |
| |
− | If you plan to use the graphical tool then you have to adjust the war file max size.
| |
− | Edit:
| |
− | <syntaxhighlight lang="bash">
| |
− | ${Tomcat root} / webapps / manager / WEB-INF / web.xml
| |
− | </syntaxhighlight>
| |
− |
| |
− |
| |
− | Adjust following values ~line 54 :
| |
− | <syntaxhighlight lang="bash">
| |
− | <multipart-config>
| |
− | <max-file-size>104857600</max-file-size>
| |
− | <max-request-size>104857600</max-request-size>
| |
− | <file-size-threshold>0</file-size-threshold>
| |
− | </multipart-config>
| |
− | </syntaxhighlight>
| |
− |
| |
− |
| |
− |
| |
− | =Add MySQL datasource=
| |
− |
| |
− | ==Setup MySQL JDBC connector==
| |
− |
| |
− | 1. Download MySQL JDBC driver
| |
− | http://dev.mysql.com/downloads/connector/j/
| |
− |
| |
− | 2. Decompress content and extract mysql-connector-java-XXX-bin.jar
| |
− |
| |
− | 3. Copy this file into $TOMCAT/libs
| |
− | Automatic install: /usr/share/tomcat7/lib
| |
− |
| |
− | ==Declare MySQL datasource==
| |
− |
| |
− | ===Server.xml===
| |
− | Automatic install: /etc/tomcat7/server.xml
| |
− |
| |
− | <syntaxhighlight lang="bash">
| |
− | $TOMCAT/server.xml
| |
− | </syntaxhighlight>
| |
− |
| |
− | Add
| |
− | <syntaxhighlight lang="bash">
| |
− | <host>
| |
− | ...
| |
− | <GlobalNamingResources>
| |
− | ...
| |
− |
| |
− | <!-- ####################################################################### -->
| |
− | <!-- MySQL datasource -->
| |
− | <!-- ####################################################################### -->
| |
− |
| |
− | <!-- maxActive: Maximum number of database connections in pool. Set to -1 for no limit. -->
| |
− | <!-- maxIdle: Maximum number of idle database connections to retain in pool. Set to -1 for no limit. -->
| |
− | <!-- maxWait: Maximum time to wait for a database connection to become available in ms. Set to -1 to wait indefinitely. -->
| |
− | <!-- driverClassName: Class name for the official MySQL Connector/J driver is com.mysql.jdbc.Driver. -->
| |
− |
| |
− | <Resource name="jdbc/myDataSource"
| |
− | auth="Container" type="javax.sql.DataSource"
| |
− | username="user" password="password"
| |
− | url="jdbc:mysql://localhost:3306/mySchema"
| |
− | maxActive="50" maxIdle="30" maxWait="10000"
| |
− | driverClassName="com.mysql.jdbc.Driver"
| |
− | factory="org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory"
| |
− | removeAbandoned="true"
| |
− | validationQuery="select 1" validationInterval="30000"
| |
− | testOnBorrow="true" testWhileIdle="true"
| |
− | timeBetweenEvictionRunsMillis="60000"
| |
− | numTestsPerEvictionRun="5"
| |
− | poolPreparedStatements="true"
| |
− | />
| |
− |
| |
− | </GlobalNamingResources>
| |
− | </syntaxhighlight>
| |
− |
| |
− | * Tomcat 8 : factory="org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory"
| |
− | * Tomcat 7 >= 7.0.52 : factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
| |
− | * Tomcat 6,7 < 7.0.52 : factory="org.apache.commons.dbcp.BasicDataSourceFactory"
| |
− |
| |
− |
| |
− |
| |
− | ===Context.xml===
| |
− | Edit:
| |
− | <syntaxhighlight lang="bash">
| |
− | $TOMCAT/context.xml
| |
− | </syntaxhighlight>
| |
− |
| |
− | Add the following declaration
| |
− | <syntaxhighlight lang="bash">
| |
− | <!-- ####################################################################### -->
| |
− | <!-- MySQL datasource -->
| |
− | <!-- ####################################################################### -->
| |
− | <ResourceLink name="jdbc/myDataSource"
| |
− | global="jdbc/myDataSource"
| |
− | type="javax.sql.datasource" />
| |
− | </syntaxhighlight>
| |
− |
| |
− |
| |
− | ===web.xml===
| |
− | Edit
| |
− | <syntaxhighlight lang="bash">
| |
− | $TOMCAT/web.xml
| |
− | </syntaxhighlight>
| |
− |
| |
− | Add the following declaration
| |
− | <syntaxhighlight lang="bash">
| |
− | <!-- ####################################################################### -->
| |
− | <!-- MySQL datasource -->
| |
− | <!-- ####################################################################### -->
| |
− |
| |
− | <resource-ref>
| |
− | <description>RTD database</description>
| |
− | <res-ref-name>jdbc/VehcoData</res-ref-name>
| |
− | <res-type>javax.sql.DataSource</res-type>
| |
− | <res-auth>Container</res-auth>
| |
− | </resource-ref>
| |
− | </syntaxhighlight>
| |
− |
| |
− |
| |
− | ===Take changes into account===
| |
− | Restart tomcat
| |
− | <syntaxhighlight lang="bash">
| |
− | service tomcat7 restart
| |
− | </syntaxhighlight>
| |
− |
| |
− | Check result:
| |
− | http://localhost:8080/manager/text/resources
| |
− |
| |
− |
| |
− | ==Use datasource==
| |
− | To use the datasource with a JNDI name you must prefix it with: java:comp/env/
| |
− |
| |
− | <syntaxhighlight lang="bash">
| |
− | java:comp/env/jdbc/myDataSource
| |
− | </syntaxhighlight>
| |
− |
| |
− |
| |
− | ==Datasource improvements==
| |
− | You can tweak the datasource using some specific config parameters.
| |
− | Edit:
| |
− | <syntaxhighlight lang="bash">
| |
− | $TOMCAT/server.xml
| |
− | </syntaxhighlight>
| |
− |
| |
− | Edit your JDBC resource:
| |
− | <syntaxhighlight lang="bash">
| |
− | <Resource auth="Container"
| |
− | name="jdbc/APP_NAME"
| |
− | username="user"
| |
− | password="password"
| |
− | type="javax.sql.DataSource"
| |
− |
| |
− | url="jdbc:oracle:thin:@server.domain:1521:development" → ORACLE database
| |
− | driverClassName="oracle.jdbc.driver.OracleDriver"
| |
− |
| |
− | url="jdbc:mysql://localhost:3306/rtd" → MySQL database
| |
− | driverClassName="com.mysql.jdbc.Driver"
| |
− |
| |
− | maxActive="50" maxIdle="30" maxWait="10000" → Connection pool
| |
− | maxIdle="10"
| |
− | maxWait="5000"
| |
− | maxActive="30" → To remove none close connections
| |
− |
| |
− | logAbandoned="true" To report the stacktrace of the faulty code
| |
− | removeAbandoned="true" To remedy connection starvation while leaky code is not fixed
| |
− | removeAbandonedTimeout="60" Interval for fixing connection starvation
| |
− |
| |
− | validationQuery="select 1 from dual" custom query to perform regular checks
| |
− | validationInterval="30000" To be adjusted! Interval in ms.
| |
− | testOnBorrow="true"
| |
− | testOnReturn="false"
| |
− | testWhileIdle="true"
| |
− | timeBetweenEvictionRunsMillis="5000"
| |
− | numTestsPerEvictionRun="3"
| |
− | minEvictableIdleTimeMillis="30000"
| |
− | />
| |
− | </syntaxhighlight>
| |
− |
| |
− | More tweaks: http://commons.apache.org/proper/commons-dbcp/configuration.html
| |
| | | |
| | | |
Line 231: |
Line 40: |
| | | |
| ==Files location== | | ==Files location== |
| + | |
| The applications files are in $Tomcat/webapps | | The applications files are in $Tomcat/webapps |
| * Automatic installation: /var/lib/tomcat/webapps | | * Automatic installation: /var/lib/tomcat/webapps |
| + | * Manual installation (tomcat instance): /opt/tomcat-base/webapps |
| + | |
| | | |
| ==Remove old temp files== | | ==Remove old temp files== |
| + | |
| In case of bugs, you can remove the working directory: $Tomcat/work/Catalina/localhost/* | | In case of bugs, you can remove the working directory: $Tomcat/work/Catalina/localhost/* |
| + | |
| <syntaxhighlight lang="bash"> | | <syntaxhighlight lang="bash"> |
| + | # Package installation |
| rm -Rf /var/lib/tomcat7/work/Catalina/localhost/* | | rm -Rf /var/lib/tomcat7/work/Catalina/localhost/* |
| + | |
| + | # Manual installation, Tomcat instance |
| + | rm -Rf /opt/tomcat-base/work/Catalina/localhost/* |
| </syntaxhighlight> | | </syntaxhighlight> |
− |
| |
− | ==Server access==
| |
− | http://server:8080
| |