Showing posts with label tomcat. Show all posts
Showing posts with label tomcat. Show all posts

Configure Log4j logger with Tomcat 6

By default tomcat uses "java.util.logging" for all internal logging in tomcat. If you want to use log4j with tomcat for logging then follow below steps.
So before we start lets remove tomcat's default java.util.logging configuration and add log4j.

You will have to download log4j jar file from here. Apart from log4j jar file you need to get tomcat-juli.jar and tomcat-juli-adapters.jar files from this location according to your tomcat version.

So after downloading log4j jar, tomcat-juli.jar and tomcat-juli-adapters.jar files follow below steps.
1. Copy tomcat-juli-adapters.jar file into tomcat/lib folder.
2. Create log4j.properties file in tomcat/lib folder with below content.

3. Now copy downloaded tomcat-juli.jar into tomcat/bin directory. You need to replace existing tomcat-juli.jar file.
4. Then remove tomcat/conf/logging.properties file.

Alfresco start error : internal error: ObjID already in use

You may come across below error. That happens due to hostname which does not resolved through any IP.




Solution: Make hosts file entry so that your hostname resolves IP address of your IP address.
filename: /etc/hosts


org.apache.solr.common.SolrException: Internal Server Error

I have done integration of Solr with Liferay. May colleague informed me that he was getting below error frequently. So I was looking for a solution of below error since last few days. But could not find the solution. I tried tuning parameters of Solr configuration, ran load test. But as usual could not reproduce error. But at last after 2 weeks, I found the clue.

Solution:
Of course,   I saw log file at Solr too when above error occurred in Liferay. But I did not notice the time zone difference, which both applications were running. Anyway, now I checked for the error at Solr side and found below error at Solr.

Finally I got some clue. It may happened that Solr was busy running any commit operation and at the same time another commit operation has been fired by Liferay. Bydefault "writeLockTimeout" value is 1 second. So already running transaction took more than 1 sec and hence Liferay generated error saying "Internal Server Error".
So now I have set "writeLockTimeout" value to 10 sec. I hope none of the commit transaction will take atleast 10 secs.


Apache Solr Logging through Log4j



Bydefault Solr uses slf4j for logging. Follow below mentioned steps to configure Solr with log4j.

  1. First delete slf4j-jdk14-1.5.5.jar file from $CATALINA_HOME/webapps/solr/WEB-INF/lib/slf4j-jdk14-1.5.5.jar location.
  2. Now download slf4j source from http://www.slf4j.org/dist/slf4j-1.5.5.tar.gz and extract it.
  3. Now copy slf4j-log4j12-1.5.5.jar from extracted location to $CATALINA_HOME/webapps/solr/WEB-INF/lib folder.
  4. Now download http://mirrors.dcarsat.com.ar/apache/logging/log4j/1.2.17/log4j-1.2.17.tar.gz and extract it.
  5. Now copy log4j-1.2.17.jar from extracted location to $CATALINA_HOME/webapps/solr/WEB-INF/lib folder.
  6. Now create $CATALINA_HOME/webapps/solr/WEB-INF/classes directory and add file “log4j.properties” with below content.

log4j.rootLogger=ERROR, CONSOLE

log4j.logger.org.apache.solr=INFO

log4j.appender.CONSOLE=org.apache.log4j.RollingFileAppender
log4j.appender.CONSOLE.File=${catalina.base}/logs/catalina.out
log4j.appender.CONSOLE.MaxFileSize=200MB
log4j.appender.CONSOLE.MaxBackupIndex=10
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{DATE} %x %-5p [%c{3}] %m%n

  1. Now rename $CATALINA_HOME/conf/logging.properties file to $CATALINA_HOME/conf/logging.properties.bak.
  2. Now restart tomcat.


Above configuration will keep writing logs in catalina.out file until it reaches 200MB size. Once it cross 200MB it will be renamed with catalina.out.1 and new after that new logs will be written to catalina.out file. MaxBackupIndex parameter will retain those many number of catalina.out files. Once it cross MaxBackupIndex limit, the old file (ex: catalina.out.10) will be removed.  

Enable Caching in Tomcat

Caching helps when you do not want some particular files to be download each time. Sometimes you may required to put extra header so that cached content get expires it self after sometime. 

So here is a post, how you can implement a Caching mechanism on Tomcat.

1. First You will have to download "Cache Filter" jar file from the below location.
http://code.google.com/p/cache-filter/downloads/list

2. Once you are done with download, put that jar file in tomcat/webapps/ROOT/WEB-INF/lib location.

3. Now open tomcat/webapps/ROOT/WEB-INF/web.xml file and add filter and filter-mapping properties as mentioned below.
4. Once you done with changes, you can restart Tomcat and check the expires header through firebug.

Hope this helps!!!

Monitoring JMX port in Amazon EC2 hosted server

Recently I have started work on Amazon EC2 servers. At some point I got requirement to monitor JMX port of server which was hosted on Amazon EC2. I followed the steps which was previously posted in my blog. But it did not help. I tried changing CATALINA_OPTS parameters as well as I opened all ports in Amazon "Security Group". After all I got help from Feil Figg blog. So below are steps to achieve it.

(1) First download catalina-jmx-remote.jar file as per tomcat's version and keep it in tomcat\lib folder.

(2) Now open tomcat/conf/server.xml file and add below line into it.

<Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener" rmiRegistryPortPlatform="8999" rmiServerPortPlatform="8999"/>



(3) Now open tomcat/bin/setenv.sh file and add below java parameters.



JAVA_OPTS="${JAVA_OPTS} -Djava.rmi.server.hostname=ec2-xx-xxx-x-xxx.compute-1.amazonaws.com -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"

(4) Now restart tomcat. You need to open port 8999 in Amazon "Security Group".

Hope this will help.