UnixServerAdmin

Server Administration & Management

Protected: tomcat_httpsd.conf_virtual-hosting-Secure for Java + PHP

This content is password protected. To view it please enter your password below:

April 10, 2014 Posted by | Apache, Tomcat | , | Enter your password to view comments.

Protected: tomcat_httpd.conf_virtual-hosting for Java + PHP

This content is password protected. To view it please enter your password below:

March 30, 2014 Posted by | Apache, Tomcat | , | Enter your password to view comments.

Protected: worker.properties_virtual-hosting

This content is password protected. To view it please enter your password below:

March 20, 2014 Posted by | Apache, Tomcat | , | Enter your password to view comments.

How to hide web server version in Tomcat

Add the following attributes to the <Connector> in Tomcat’s server.xml to hide web server version in Tomcat at line no- 73 :-

# vim apache-tomcat/conf/server.xml

<Connector port=”8080″ protocol=”HTTP/1.1″
connectionTimeout=”20000″
redirectPort=”8443″
server=”Tomcat” />

April 7, 2013 Posted by | Security, Tips & Tricks, Tomcat | , , , , | 1 Comment

How to enable gzip compression in Tomcat

Add the following attributes to the <Connector> in Tomcat’s server.xml to enable gzip compression of responses at line no.- 70 :-

# vim apache-tomcat/conf/server.xml

    compression=”on” compressionMinSize=”2048″
    compressableMimeType=”text/html,text/xml,text/csv,text/css,text/javascript”

Before

<Connector port=”8080″ protocol=”HTTP/1.1″
                 connectionTimeout=”20000″
                 redirectPort=”8443″ /

After

<Connector port=”8080″ protocol=”HTTP/1.1″
               connectionTimeout=”20000″
               redirectPort=”8443″
               compression=”on” compressionMinSize=”2048″
               compressableMimeType=”text/html,text/xml,text/csv,text/css,text/javascript” />

March 23, 2013 Posted by | Tomcat | , | 1 Comment

How to enable Tomcat for a domain in cPanel

To enable .jsp pages for a domain

# /scripts/addservlets –domain=example.com

To disable .jsp pages for a domain

# /scripts/remservelets –domain=example.com

In some cases, these scripts won’t work. Manually check the setting for the domain.

1. Open up the Apache configuration file /usr/local/apache/conf/httpd.conf

# vim /usr/local/apache/conf/httpd.conf

2. Check if the directive given below in the virtual host entry of domain, if not add it.

———————————————————————————————————————–
Include “/usr/local/apache/conf/userdata/std/2/username/domainname/*.conf”
———————————————————————————————————————–

3. Now navigate to the directory

# cd /usr/local/apache/conf/userdata/std/2/

4. check whether the folder named username(replace username with appropriate username) exist if not, create it.

# mkdir username
# cd username
# cd example

5. If the directory “example” is not present, create it

6. Check for the file cp_jkmount.conf here, if it is not present, create it with the following contents
——————————————–
 <IfModule mod_jk.c>
      JkMount /*.jsp ajp13
      JkMount /servlet/* ajp13
    JkMount /servlets/* ajp13
    JkMount /*.do ajp13
 </IfModule>
——————————————–

7. Check the file /usr/local/jakarta/tomcat/conf/server.xml Add the entry for host http://www.example.com

# vim /usr/local/jakarta/tomcat/conf/server.xml

——————————————————————————————————-
 <Host name=”example” appBase=”/home/username/public_html”>
    <Alias>www.example</Alias>
      <Context path=”” reloadable=”true”
               docBase=”/home/username/public_html” debug=”1″/>
      <Context path=”/manager” debug=”0″ privileged=”true”
        docBase=”/usr/local/jakarta/tomcat/server/webapps/manager”>
      </Context>
     </Host>
——————————————————————————————————-

8. Restart the services

# /usr/local/jakarta/tomcat/bin/shutdown.sh

# /usr/local/jakarta/tomcat/bin/startup.sh

# /scripts/restartsrv_tomcat

9. Restart Apache

October 19, 2012 Posted by | cPanel, Tomcat | , , | Leave a comment

Protected: tomcat_service.sh

This content is password protected. To view it please enter your password below:

June 16, 2012 Posted by | Shell Script, Tomcat | , | Enter your password to view comments.

index.jsp for tomcat cluster with HA

<%@ page language=”java” %>
<HTML>
<HEAD>
<TITLE>Login using jsp</TITLE>
</HEAD>
<BODY>
<h1><font color=”red”>Index Page by Tomcat-2 Node-2</font></h1>
<h2><font color=”blue”>This is test page of Tomcat-2 of NODE-2</font></h2>
<table> align=”centre” border=”1″
<h2>></h2>
<tr>
<td>Session ID –> </td>
<td><%= session.getId() %></td>
</tr>
<tr>
<td>Created on –> </td>
<td><%= session.getCreationTime() %></td>
</tr>
</table>
</BODY>
</HTML>

March 23, 2012 Posted by | Apache, Cluster, Tomcat | , , | Leave a comment

Protected: worker.properties_cluster

This content is password protected. To view it please enter your password below:

March 19, 2012 Posted by | Apache, Cluster, Tomcat | , , | Enter your password to view comments.

Protected: tomcat_ssl.conf_cluster

This content is password protected. To view it please enter your password below:

March 17, 2012 Posted by | Apache, Cluster, Tomcat | , , | Enter your password to view comments.

Protected: tomcat_httpd.conf_cluster

This content is password protected. To view it please enter your password below:

March 15, 2012 Posted by | Apache, Cluster, Tomcat | , , | Enter your password to view comments.

Protected: Tomcat Configuration Cluster

This content is password protected. To view it please enter your password below:

March 13, 2012 Posted by | Cluster, Tomcat | , | Enter your password to view comments.

How to rotate tomcat logs

# cat /etc/logrotate.d/tomcat

/usr/local/tomcat/logs/catalina.out {
compress
copytruncate
create 644 root root
rotate 30
size 1024M
}

/usr/local/tomcat/logs/localhost.*.log {
compress
copytruncate
create 644 root root
rotate 30
size 1024M
}

/usr/local/tomcat/logs/localhost.*.log {
compress
copytruncate
create 644 root root
rotate 30
size 128M
}

/usr/local/tomcat/logs/host-manager.*.log {
compress
copytruncate
create 644 root root
rotate 30
size 1M
}

/usr/local/tomcat/logs/catalina.*.log {
compress
copytruncate
create 644 root root
rotate 30
size 1M
}

/usr/local/tomcat/logs/localhost_access_log.*.txt {
compress
copytruncate
create 644 root root
rotate 30
size 24M
}

daily :- rotates the catalina.out daily
rotate 7 :- keeps at most 7 log files
compress :- compresses the rotated files
size 10M :- rotates if the size of catalina.out is bigger than 10M
copytruncate :- Truncate the original log file in place after creating a copy, instead of moving the old log file and optionally creating a new one, It can be used when some program can not be told to close its logfile and thus might continue writing (appending) to the previous log file forever. Note that there is a very small time slice between copying the file and truncating it, so some logging data might be lost. When this option is used, the create option will have no effect, as the old log file stays in place.

January 17, 2012 Posted by | Tips & Tricks, Tomcat | , , | 1 Comment

Protected: How to configure Tomcat to run as a Service

This content is password protected. To view it please enter your password below:

December 3, 2011 Posted by | Java, Shell Script, Tips & Tricks, Tomcat | , , , , | Enter your password to view comments.

Tomcat Application Server

Apache Tomcat (or Jakarta Tomcat or simply Tomcat) is an open source servlet container developed by the Apache Software Foundation (ASF). Tomcat implements the Java Servlet and the JavaServer Pages (JSP) specifications from Oracle Corporation, and provides a “pure Java” HTTP web server environment for Java code to run.

Tomcat should not be confused with the Apache web server, which is a C implementation of an HTTP web server; these two web servers are not bundled together, although they are frequently used together as part of a server application stack. Apache Tomcat includes tools for configuration and management, but can also be configured by editing XML configuration files.

Components :- Tomcat was released with Catalina (a servlet container), Coyote (an HTTP connector) and Jasper (a JSP engine).

Catalina :–> is Tomcat’s servlet container. Catalina implements Sun Microsystems’ specifications for servlet and JavaServer Pages (JSP). In Tomcat, a Realm element represents a “database” of usernames, passwords, and roles (similar to Unix groups) assigned to those users. Different implementations of Realm allow Catalina to be integrated into environments where such authentication information is already being created and maintained, and then utilize that information to implement Container Managed Security as described in the Servlet Specification.

Coyote :–> is Tomcat’s HTTP Connector component that supports the HTTP 1.1 protocol for the web server or application container. Coyote listens for incoming connections on a specific TCP port on the server and forwards the request to the Tomcat Engine to process the request and send back a response to the requesting client.

Jasper :–> is Tomcat’s JSP Engine. Tomcat 5.x uses Jasper 2, which is an implementation of the Sun Microsystems’s JavaServer Pages 2.0 specification. Jasper parses JSP files to compile them into Java code as servlets (that can be handled by Catalina). At runtime, Jasper detects changes to JSP files and recompiles them.

November 9, 2011 Posted by | Java, Tomcat | , , | Leave a comment

Application Servers

An application server is a software framework that provides an environment in which applications can run, no matter what the applications are or what they do.It is dedicated to the efficient execution of procedures (programs, routines, scripts) for supporting the construction of applications.

The term was originally used when discussing early client–server systems to differentiate servers that run SQL services and middleware servers from file servers.

Later, the term took on the meaning of Web applications, but has since evolved further into that of a comprehensive service layer. An application server acts as a set of components accessible to the software developer through an API defined by the platform itself. For Web applications, these components are usually performed in the same machine where the Web server is running, and their main job is to support the construction of dynamic pages.

However, present-day application servers target much more than just Web page generation: they implement services like clustering, fail-over, and load-balancing, so developers can focus on implementing the business logic.

Normally the term refers to Java application servers. When this is the case, the application server behaves like an extended virtual machine for the running applications, transparently handling connections to the database on one side, and connections to the Web client on the other. Other uses of the term may refer to the services that a server makes available or the  computer hardware on which the services run.

Java Application Servers

The Web modules include servlets, JavaServer Pages and Enterprise JavaBeans. Business logic resides in Enterprise JavaBeans – a modular server component providing many features, mostly improving application scalability. The Hibernate project offers an EJB-3 container implementation for the JBoss application server. Tomcat from Apache,The EAServer is from Sybase inc.

A Java Server Page (JSP) (a servlet from Java – the Java equivalent of a CGI script) executes in a Web container. JSPs provide a way to create HTML pages by embedding references to the server logic within the page. HTML coders and Java programmers can work side by side by referencing each other’s code from within their own.

The application servers mentioned above mainly serve Web applications. Some application servers target networks other than web-based ones: Session Initiation Protocol servers, for instance, target telephony networks.

Web Server is a sub set but the Application server is a super set and hence encompasses the past server information that is been stored in database.

Microsoft .NET Framework

Microsoft positions their middle-tier applications and services infrastructure in the Windows Server operating system and the .NET Framework technologies in the role of an application server.

Advantages of application servers

Data and code integrity :–> By centralizing business logic on an individual server or on a small number of server machines, updates and upgrades to the application for all users can be guaranteed. There is no risk of old versions of the application accessing or manipulating data in an older, incompatible manner.

Centralized configuration :–> Changes to the application configuration, such as a move of database server, or system settings, can take place centrally.

Security :–> A central point through which service-providers can manage access to data and portions of the application itself counts as a security benefit, devolving responsibility for authentication away from the potentially insecure client layer without exposing the database layer.

Performance :–> By limiting the network traffic to performance-tier traffic the client–server model improves the performance of large applications in heavy usage environments.

Total Cost of Ownership (TCO) :–> In combination, the benefits above may result in cost savings to an organization developing enterprise applications. In practice, however, the technical challenges of writing software that conforms to that paradigm, combined with the need for software distribution to distribute client code, somewhat negate these benefits.

Transaction Support :–> A transaction represents a unit of activity in which many updates to resources (on the same or distributed data sources) can be made atomic (as an indivisible unit of work). End-users can benefit from a system-wide standard behaviour, from reduced time to develop, and from reduced costs. As the server does a lot of the tedious code-generation, developers can focus on business logic.

November 8, 2011 Posted by | Apache, Java, Tomcat | , , , | Leave a comment

Servlets and Applets

Servlets executes on Servers and have no graphical user interface.

Applets executes on browser, have graphical user interface. An applet is a small server side application that can be loaded and controlled on the browser by the client application. An applet has limited access to resources in order to ensure security.

November 7, 2011 Posted by | Java, Tomcat | , , , | Leave a comment

java.lang.OutOfMemoryError: PermGen space

While accessing the .jsp pages or restarting tomcat on the server you face the error “java.lang.OutOfMemoryError: PermGen space”.  The error occurs due to the memry outage for  the tomcat service on the server. By default the tomcat uses 128 MB of memroy. You can increase the memory with the steps below and get rid off the errors.

HTTP Status 500 –
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Servlet execution threw an exception
root cause
java.lang.OutOfMemoryError: PermGen space
note The full stack trace of the root cause is available in the Apache Tomcat/
Apache Tomcat

1) Edit file /usr/local/jakarta/tomcat/bin/catalina.sh

# vi /usr/local/jakarta/tomcat/bin/catalina.sh

2) Add following line into the catalina.sh file.

JAVA_OPTS=”-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms512m -Xmx1024m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m -XX:MaxPermSize=256m -XX:+DisableExplicitGC”

Which will look like

=======================================================================
# JSSE_HOME (Optional) May point at your Java Secure Sockets Extension
# (JSSE) installation, whose JAR files will be added to the
# system class path used to start Tomcat.
#
# CATALINA_PID (Optional) Path of the file which should contains the pid
# of catalina startup java process, when start (fork) is used
#
# $Id: catalina.sh 609438 2008-01-06 22:14:28Z markt $
# —————————————————————————–

JAVA_OPTS=”-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms512m -Xmx1024m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m -XX:MaxPermSize=256m -XX:+DisableExplicitGC”

# OS specific support. $var _must_ be set to either true or false.
cygwin=false
os400=false
darwin=false
=======================================================================

3) Save and exit

4) Restart Tomcat

October 30, 2011 Posted by | Tomcat | | Leave a comment

Error occurred during initialization of VM Could not reserve enough space for object heap Could not create the Java virtual machine

The following error is occur due to memory size assigned to Tomcat service is full.

———————————————————————————————————————–
Error occurred during initialization of VM Could not reserve enough space for object heap Could not create the Java virtual machine.
———————————————————————————————————————–

You need to run following commands from Shell

# cd /usr/local/jakarta/tomcat/bin/

# export _JAVA_OPTIONS=”-Xms20m -Xmx64m -XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=40 -XX:NewSize=10m -XX:MaxNewSize=10m -XX:SurvivorRatio=6 -XX:TargetSurvivorRatio=80 -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled”

Once you run above command restart the Tomcat service

#./shutdown.sh

#./startup.sh

#./catalina.sh

October 8, 2011 Posted by | Java, Tomcat | , | Leave a comment

workers.properties

A file that describes the host(s) and port(s) used by the workers (Tomcat processes). A sample workers.properties can be found under the /etc/httpd/conf/ directory.

# vi /etc/httpd/conf/workers.properties

worker.list=jetty
worker.jetty.port=8009
worker.jetty.host=localhost “OR” X.X.X.X
worker.jetty.type=ajp13
worker.jetty.lbfactor=1

September 21, 2011 Posted by | Java, Tomcat | , , | Leave a comment