Installing Tomcat 7 on Debian/Ubuntu

First, a simple apt-get:
apt-get install tomcat7 libtcnative-1 tomcat7-user tomcat7-docs tomcat7-admin


Wait, "libtcnative-1"?

Tomcat can use the Apache Portable Runtime to provide superior scalability, performance, and better integration with native server technologies. The Apache Portable Runtime is a highly portable library that is at the heart of Apache HTTP Server 2.x. APR has many uses, including access to advanced IO functionality (such as sendfile, epoll and OpenSSL), OS level functionality (random number generation, system status, etc), and native process handling (shared memory, NT pipes and Unix sockets). These features allows making Tomcat a general purpose webserver, will enable much better integration with other native web technologies, and overall make Java much more viable as a full fledged webserver platform rather than simply a backend focused technology.

(http://packages.debian.org/wheezy/libtcnative-1)


/etc/tomcat7/server.xml


-Uncomment the APR library loader:

<!--APR library loader. Documentation at /docs/apr.html -->
   <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />

-Change the port of the connector for 80/443 and changes params:

<Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               URIEncoding="UTF-8"
               redirectPort="443" maxKeepAliveRequests="1000" />

The maximum number of HTTP requests per TCP connection (maxKeepAliveRequests) defaults to 100 in Apache. In production, a higher value (e.g., 1,000) often provides better performance. A value of zero allows unlimited requests.

/etc/default/tomcat7

-Allow Tomcat to run on port numbers lower than 1023
AUTHBIND=yes

-Define correct JVM options and specify a heap dump path
JAVA_OPTS="-server -Xms4G -Xmx4G -XX:MaxPermSize=128m -XX:+DisableExplicitGC -XX:-HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/tomcat7/dump -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+UseTLAB -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing -XX:CMSIncrementalDutyCycleMin=0 -XX:CMSIncrementalDutyCycle=10 -XX:MaxTenuringThreshold=0 -XX:SurvivorRatio=256 -XX:CMSInitiatingOccupancyFraction=60 -Djava.net.preferIPv4Stack=true"

/etc/tomcat7/web.xml

-Edit org.apache.jasper.servlet.JspServlet parameters:
        <init-param>
                <param-name>development</param-name>
                <param-value>false</param-value>
                </init-param>
        <init-param>
                <param-name>genStringAsCharArray</param-name>
                <param-value>true</param-value>
        </init-param>
        <init-param>
                <param-name>trimSpaces</param-name>
                <param-value>true</param-value>
        </init-param>

        Why do this?

development: When using Jasper 2 in a production Tomcat server, set development to “false.” Set it to “true” in the development environment. One caveat: Sometimes this cannot be done, for example, with dynamic generation of JSPs.

genStringAsCharArray: set genStringAsCharArray to “true” to produce more efficient char arrays.

trimSpaces: set trimSpaces to “true” to remove useless bytes from the response.

/etc/tomcat7/tomcat-users.xml

<tomcat-users>

<role rolename="manager-gui"/>
<user username="a_user" password="a_password" roles="manager-gui"/>
</tomcat-users>



Labels: ,