Home‎ > ‎Server‎ > ‎

Tomcat

Setting up Tomcat7 on Ubuntu.

Setup Tomcat

Setting up Tomcat 7 on ubuntu. 
sudo apt-get install tomcat7 tomcat7-admin tomcat7-docs tomcat7-user tomcat7-examples
sudo service tomcat7 restart

Tomcat Users

Setting up tomcat users with access to the admin and managers.
<!-- Located: /etc/tomcat7/tomcat-users.xml -->
 
<role rolename="admin-gui"/>
 
<role rolename="admin-script"/>
 
<role rolename="manager-script"/>
 
<role rolename="manager-gui"/>
 
<role rolename="manager-script"/>
 
<role rolename="manager-jmx"/>
 
<role rolename="manager-status"/>
 
<user username="branflake" password="Change" roles="admin-gui,admin-script,manager-gui,manager-script,manager-jmx,manager-status"/>

Virtual Hosts Directories

Setup the webapps virtual host directories in /var/lib/tomcat/webapps* or some other location of your choosing and change the permissions on the directory for owner and group to tomcat7.

This is an example of my directory.

Virtual Hosts

Add virtual hosts by changing the name and appbase and then copying the Catalina included apps like host manager to the directory which is show below in Virtual Host Manager.
      <!-- Located: /etc/tomcat7/server.xml -->
     
<Host name="gonevertical.org"  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 &quot;%r&quot; %s %b" />
     
</Host>

     
<Host name="teamcity.gonevertical.org" appBase="webapps_teamcity"
           
unpackWARs="true" autoDeploy="true">
       
<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>

Virtual Host Manager

Setting up the virtual host manager, docs and admin for your virtual hosts. Copying the manager.xml, examples.xml, host-manager.xml and docs.xml to each virtual host will allow you to use the apps with your virtual host. 
cd /etc/tomcat7/Catalina/localhost
sudo cp
* ../gonevertical.org
sudo cp
* ../teamcity.gonevertical.org


Fixing Problems

Ubuntu Tomcat 7 Port Denied

When installing and setting up Tomcat7 and you get a port permissions error goto /etc/default/tomcat7 and set AUTHBIND=yes.
#Located: /etc/default/tomcat7

# If you run Tomcat on port numbers that are all higher than 1023, then you
# do not need authbind.  It is used for binding Tomcat to lower port numbers.
# NOTE: authbind works only with IPv4.  Do not enable it when using IPv6.
# (yes/no, default: no)
AUTHBIND
=yes

Then configure authbind.
sudo touch /etc/authbind/byport/80
sudo chmod
500 /etc/authbind/byport/80
sudo chown tomcat7
/etc/authbind/byport/80
sudo touch
/etc/authbind/byport/443
sudo chmod
500 /etc/authbind/byport/443
sudo chown tomcat7
/etc/authbind/byport/443
sudo service tomcat7 restart

The error that appears in the tomcat7 logs.
EVERE: Failed to initialize end point associated with ProtocolHandler ["http-bio-80"]
java
.net.BindException: Permission denied <null>:80
        at org
.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:391)
        at org
.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:554)
        at org
.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:409)
        at org
.apache.coyote.http11.AbstractHttp11JsseProtocol.init(AbstractHttp11JsseProtocol.java:119)
        at org
.apache.catalina.connector.Connector.initInternal(Connector.java:956)
        at org
.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
        at org
.apache.catalina.core.StandardService.initInternal(StandardService.java:559)
        at org
.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
        at org
.apache.catalina.core.StandardServer.initInternal(StandardServer.java:815)
        at org
.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
        at org
.apache.catalina.startup.Catalina.load(Catalina.java:594)
        at org
.apache.catalina.startup.Catalina.load(Catalina.java:619)
        at sun
.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun
.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun
.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java
.lang.reflect.Method.invoke(Method.java:616)
        at org
.apache.catalina.startup.Bootstrap.load(Bootstrap.java:281)
        at org
.apache.catalina.startup.Bootstrap.main(Bootstrap.java:449)
Caused by: java.net.BindException: Permission denied
        at java
.net.PlainSocketImpl.socketBind(Native Method)
        at java
.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:353)
        at java
.net.ServerSocket.bind(ServerSocket.java:336)
        at java
.net.ServerSocket.<init>(ServerSocket.java:202)
        at java
.net.ServerSocket.<init>(ServerSocket.java:158)
        at org
.apache.tomcat.util.net.DefaultServerSocketFactory.createSocket(DefaultServerSocketFactory.java:49)
        at org
.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:378)
       
... 17 more

Manager Deploying Large War Problem

When using the manager to deploy large war files bigger than 50MB. The max size has to be adjusted. 

      <!-- Located: /usr/share/tomcat7-admin/manager/WEB-INF/web.xml -->
     
<multipart-config>
       
<!-- 1000MB max -->
       
<max-file-size>1048576000</max-file-size>
       
<max-request-size>1048576000</max-request-size>
       
<file-size-threshold>0</file-size-threshold>
     
</multipart-config>

Manager War Upload Permission Denied

When uploading a war and getting permission denied tells you the directories that hold the webapps do not have owner and group set to 'tomcat7' and need to be changed.

Fix the error by changing the owner and group with something like this:
cd /var/lib/tomcat7
sudo chown tomcat7 webapps_gonevertical
/
sudo chgrp tomcat7 webapps_gonevertical
/
The error that occurs in /var/log/tomcat/catalina[date] log.
SEVERE: HTMLManager: FAIL - Deploy Upload Failed, Exception: java.io.FileNotFoundException: /var/lib/tomcat7/webapps_teamcity/ROOT.war (Permission denied)
java
.io.IOException: java.io.FileNotFoundException: /var/lib/tomcat7/webapps_teamcity/ROOT.war (Permission denied)
        at org
.apache.catalina.core.ApplicationPart.write(ApplicationPart.java:123)
        at org
.apache.catalina.manager.HTMLManagerServlet.upload(HTMLManagerServlet.java:332)
        at org
.apache.catalina.manager.HTMLManagerServlet.doPost(HTMLManagerServlet.java:211)
        at javax
.servlet.http.HttpServlet.service(HttpServlet.java:641)
        at javax
.servlet.http.HttpServlet.service(HttpServlet.java:722)

Tomcat Heap Size

Setting up more memory for Tomcat
Located: /etc/defaults/tomcat7
# Use "-XX:+UseConcMarkSweepGC" to enable the CMS garbage collector (improved
# response time). If you use that option and you run Tomcat on a machine with
# exactly one CPU chip that contains one or two cores, you should also add
# the "-XX:+CMSIncrementalMode" option.
JAVA_OPTS
="-Djava.awt.headless=true -Xmx2048m -XX:MaxPermSize=256M -XX:+UseConcMarkSweepGC"
Lower left of the screen shot shows the memory usage. domain.tld/manager/status





















































Subpages (1): Tomcat War Deployment
Comments