tomcat 7 ubuntu


root@ubuntu:/etc/init.d# apt-get install tomcat7*
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
 libservlet3.0-java libtomcat7-java tomcat7-common
Suggested packages:
 tomcat7-user libtcnative-1
The following packages will be upgraded:
 libservlet3.0-java libtomcat7-java tomcat7 tomcat7-common
4 upgraded, 0 newly installed, 0 to remove and 132 not upgraded.
Need to get 3,998 kB of archives.
After this operation, 1,024 B disk space will be freed.
Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu/ vivid-updates/main libservlet3.0-java all 7.0
.56-2ubuntu0.1 [303 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu/ vivid-updates/main libtomcat7-java all 7.0.56
-2ubuntu0.1 [3,610 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu/ vivid-updates/main tomcat7-common all 7.0.56-
2ubuntu0.1 [48.1 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu/ vivid-updates/main tomcat7 all 7.0.56-2ubuntu
0.1 [36.8 kB]
Fetched 3,998 kB in 1min 4s (61.7 kB/s)                                                
Preconfiguring packages ...
(Reading database ... 145576 files and directories currently installed.)
Preparing to unpack .../libservlet3.0-java_7.0.56-2ubuntu0.1_all.deb ...
Unpacking libservlet3.0-java (7.0.56-2ubuntu0.1) over (7.0.56-2) ...
Preparing to unpack .../libtomcat7-java_7.0.56-2ubuntu0.1_all.deb ...
Unpacking libtomcat7-java (7.0.56-2ubuntu0.1) over (7.0.56-2) ...
Preparing to unpack .../tomcat7-common_7.0.56-2ubuntu0.1_all.deb ...
Unpacking tomcat7-common (7.0.56-2ubuntu0.1) over (7.0.56-2) ...
Preparing to unpack .../tomcat7_7.0.56-2ubuntu0.1_all.deb ...
Unpacking tomcat7 (7.0.56-2ubuntu0.1) over (7.0.56-2) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (219-7ubuntu3) ...
Setting up libservlet3.0-java (7.0.56-2ubuntu0.1) ...
Setting up libtomcat7-java (7.0.56-2ubuntu0.1) ...
Setting up tomcat7-common (7.0.56-2ubuntu0.1) ...
Setting up tomcat7 (7.0.56-2ubuntu0.1) ...
root@ubuntu:/etc/init.d#

root@ubuntu:/etc/init.d# apt-get install tomcat7-docs tomcat7-examples            
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be upgraded:
 tomcat7-docs tomcat7-examples
2 upgraded, 0 newly installed, 0 to remove and 129 not upgraded.
Need to get 740 kB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu/ vivid-updates/main tomcat7-docs all 7.0.56-2u
buntu0.1 [556 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu/ vivid-updates/main tomcat7-examples all 7.0.5
6-2ubuntu0.1 [184 kB]
Fetched 740 kB in 9s (76.6 kB/s)                                                       
(Reading database ... 145576 files and directories currently installed.)
Preparing to unpack .../tomcat7-docs_7.0.56-2ubuntu0.1_all.deb ...
Unpacking tomcat7-docs (7.0.56-2ubuntu0.1) over (7.0.56-2) ...
Preparing to unpack .../tomcat7-examples_7.0.56-2ubuntu0.1_all.deb ...
Unpacking tomcat7-examples (7.0.56-2ubuntu0.1) over (7.0.56-2) ...
Setting up tomcat7-docs (7.0.56-2ubuntu0.1) ...
Setting up tomcat7-examples (7.0.56-2ubuntu0.1) ...
dpkg -l | grep tomcat
ii  libtomcat7-java                               7.0.56-2ubuntu0.1                          all          Servlet and JSP engine -- core libraries
ii  tomcat7                                       7.0.56-2ubuntu0.1                          all          Servlet and JSP engine
ii  tomcat7-admin                                 7.0.56-2ubuntu0.1                          all          Servlet and JSP engine -- admin web applications
ii  tomcat7-common                                7.0.56-2ubuntu0.1                          all          Servlet and JSP engine -- common files
ii  tomcat7-docs                                  7.0.56-2ubuntu0.1                          all          Servlet and JSP engine -- documentation
ii  tomcat7-examples                              7.0.56-2ubuntu0.1                          all          Servlet and JSP engi
root@ubuntu:/etc/init.d#  apt-get install libapache2-mod-jk  

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
 libapache-mod-jk-doc tomcat8
The following NEW packages will be installed:
 libapache2-mod-jk
0 upgraded, 1 newly installed, 0 to remove and 129 not upgraded.
Need to get 150 kB of archives.
After this operation, 452 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu/ vivid-updates/universe libapache2-mod-jk amd6
4 1:1.2.37-4+deb8u1build0.15.04.1 [150 kB]
Fetched 150 kB in 9s (16.5 kB/s)                                                       
Selecting previously unselected package libapache2-mod-jk.
(Reading database ... 145576 files and directories currently installed.)
Preparing to unpack .../libapache2-mod-jk_1%3a1.2.37-4+deb8u1build0.15.04.1_amd64.deb ..
.
Unpacking libapache2-mod-jk (1:1.2.37-4+deb8u1build0.15.04.1) ...
Setting up libapache2-mod-jk (1:1.2.37-4+deb8u1build0.15.04.1) ...
apache2_invoke: Enable module jk
create a webapp
root@ubuntu:/etc/init.d# cd /var/lib/tomcat7/webapps

root@ubuntu:/var/lib/tomcat7/webapps# mkdir tomcat-demo

root@ubuntu:/var/lib/tomcat7/webapps# mkdir tomcat-demo/helloworld

root@ubuntu:/var/lib/tomcat7/webapps# vim tomcat-demo/helloworld/index.jsp  
<HTML>
 <HEAD>
  <TITLE>Hello World</TITLE>
 </HEAD>
 <BODY>
  <H1>Hello World</H1>
  Today is: <%= new java.util.Date().toString() %>
 </BODY>
</HTML>


root@ubuntu:/etc/init.d# vim /etc/tomcat7/server.xml  
<Connector port="8009"protocol="AJP/1.3"redirectPort="8443" />

root@ubuntu:/etc/init.d# vim /etc/apache2/workers.properties
# Define 1 real worker using ajp13
worker.list=worker1
# Set properties for worker (ajp13)

worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009
 root@ubuntu:/usr/share/tomcat7/bin# vi /etc/apache2/mods-enabled/jk.conf

root@ubuntu:/etc/init.d# vim /etc/apache2/mods-available/jk.conf
  JkWorkersFile /etc/apache2/workers.properties
root@ubuntu:/usr/share/tomcat7/bin# vi /etc/apache2/mods-enabled/jk.load
root@ubuntu:/etc/init.d# vim /etc/apache2/mods-available/jk.load
LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so

root@ubuntu:/etc/init.d# vi /etc/apache2/sites-enabled/000-default.conf

JkMount /tomcat-demo* worker1

root@ubuntu:/var/lib/tomcat7/webapps# service apache2 restart
root@ubuntu:/var/lib/tomcat7/webapps# service tomcat7 restart

vi /etc/tomcat7/tomcat-users.xml  


<role rolename="admin"/>
 <role rolename="admin-gui"/>
 <role rolename="admin-script"/>
 <role rolename="manager"/>
 <role rolename="manager-gui"/>
 <role rolename="manager-script"/>
 <role rolename="manager-jmx"/>
 <role rolename="manager-status"/>
 <user name="admin" password="admin" roles="admin,manager,admin-
gui,admin-script,manager-gui,manager-script,manager-jmx,manager-status”/>

root@ubuntu:/etc/init.d# ./tomcat7 restart  
                            
[
ok ] Restarting tomcat7 (via systemctl): tomcat7.service.



JAVA parameters

root@ubuntu:/usr/share/tomcat7/bin# vi /usr/share/tomcat7/bin/catalina.sh


root@ubuntu:/usr/share/tomcat7/bin# vi catalina.sh

export JAVA_OPTS="-Xms512m -Xmx1024m"
 export CATALINA_OPTS="-Xms512m -Xmx1024m"

root@ubuntu:/usr/share/tomcat7/bin# chmod a+x setenv.sh

setenv.sh
1
2
3
export CATALINA_OPTS="$CATALINA_OPTS -Xms512m"
export CATALINA_OPTS="$CATALINA_OPTS -Xmx8192m"
export CATALINA_OPTS="$CATALINA_OPTS -XX:MaxPermSize=256m"

root@ubuntu:/usr/share/tomcat7/bin# ./catalina.sh run
Using CATALINA_BASE:   /usr/share/tomcat7
Using CATALINA_HOME:   /usr/share/tomcat7
Using CATALINA_TMPDIR: /usr/share/tomcat7/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar
Nov 08, 2015 5:01:34 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat7/common/classes], exists: [false], isDirectory: [false], canRead: [false]
Nov 08, 2015 5:01:34 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat7/common], exists: [false], isDirectory: [false], canRead: [false]
Nov 08, 2015 5:01:34 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat7/server/classes], exists: [false], isDirectory: [false], canRead: [false]
Nov 08, 2015 5:01:34 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat7/server], exists: [false], isDirectory: [false], canRead: [false]
Nov 08, 2015 5:01:34 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat7/shared/classes], exists: [false], isDirectory: [false], canRead: [false]
Nov 08, 2015 5:01:34 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat7/shared], exists: [false], isDirectory: [false], canRead: [false]
Nov 08, 2015 5:01:34 PM org.apache.catalina.startup.Catalina initDirs
SEVERE: Cannot find specified temporary folder at /usr/share/tomcat7/temp
Nov 08, 2015 5:01:34 PM org.apache.catalina.startup.Catalina load
WARNING: Unable to load server configuration from [/usr/share/tomcat7/conf/server.xml]
Nov 08, 2015 5:01:34 PM org.apache.catalina.startup.Catalina initDirs
SEVERE: Cannot find specified temporary folder at /usr/share/tomcat7/temp
Nov 08, 2015 5:01:34 PM org.apache.catalina.startup.Catalina load
WARNING: Unable to load server configuration from [/usr/share/tomcat7/conf/server.xml]
Nov 08, 2015 5:01:34 PM org.apache.catalina.startup.Catalina start
SEVERE: Cannot start server. Server instance is not configured.


root@ubuntu:/usr/share/tomcat7/bin# /etc/init.d/tomcat7 restart
[ ok ] Restarting tomcat7 (via systemctl): tomcat7.service.


root@ubuntu:/usr/share/tomcat7/bin# tail /var/log/tomcat7/localhost_access_log.2015-11-08.txt
0:0:0:0:0:0:0:1 - - [08/Nov/2015:13:39:00 +0530] "GET / HTTP/1.1" 304 -
0:0:0:0:0:0:0:1 - - [08/Nov/2015:13:39:00 +0530] "GET /favicon.ico HTTP/1.1" 404 991
0:0:0:0:0:0:0:1 - - [08/Nov/2015:13:46:51 +0530] "GET /manager/html?org.apache.catalina.filters.CSRF_NONCE=5B6F7EF172D4AA721C510241F2B89ECD HTTP/1.1" 401 2474
0:0:0:0:0:0:0:1 - admin [08/Nov/2015:13:46:53 +0530] "GET /manager/html?org.apache.catalina.filters.CSRF_NONCE=5B6F7EF172D4AA721C510241F2B89ECD HTTP/1.1" 200 17581
root@ubuntu:/usr/share/tomcat7/bin# ps aux | grep java
tomcat7    4107  1.7  5.4 9378560 219708 ?      Sl   17:01   0:05 /usr/lib/jvm/default-java/bin/java -Djava.util.logging.config.file=/var/lib/tomcat7/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xms512m -Xmx1024m -Xms512m -Xmx1024m -Xms512m -Xmx8192m -XX:MaxPermSize=256m -Djava.endorsed.dirs=/usr/share/tomcat7/endorsed -classpath /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar -Dcatalina.base=/var/lib/tomcat7 -Dcatalina.home=/usr/share/tomcat7 -Djava.io.tmpdir=/tmp/tomcat7-tomcat7-tmp org.apache.catalina.startup.Bootstrap start
root       4196  0.0  0.0   9492  2276 pts/2    S+   17:06   0:00 grep --color=auto java
root@ubuntu:/usr/share/tomcat7/bin# vi /usr/share/tomcat7/bin/setenv.sh
root@ubuntu:/usr/share/tomcat7/bin#

If you may get an error java.lang.OutOfMemoryError: PermGen space in both windows or linux system,

Configure the MaxPermSize value in  setenv.sh or catalina.sh like,
1
2
export JAVA_OPTS="-Xms256m -Xmx512m -XX:MaxPermSize=128m"



set CATALINA_OPTS=%CATALINA_OPTS% -Djava.library.path=”C:\Program Files\Documentum\shared” -Xms256m -Xmx256m -XX:NewSize=64m -XX:MaxNewSize=64m -XX:SurvivorRatio=14 -verbose:gc

 -Xms Starting heap size (default is 256m)

-Xmx Maximum Heap size (default is 256m)

YoungGen

-XX:NewSize Starting NewSize memory allocation (default is 64)

-XX:MaxNewSize Maximum NewSize allocation (default is 64)

-XX:SurvivorRatio Fraction of NewSize reserved for survivor (not GC) space (default is 14)

ou just need to...

  - add -XX:PermSize and -XX:MaxPermSize to CATALINA_OPTS to configure PermGen to be 512M.

  - add -XX:NewSize and -XX:MaxNewSize to CATALINA_OPTS to configure YoungGen to be 200M.

  - restart your Tomcat instance

 java -Xms128m -Xmx2g MyApp

It is useful to know that both -Xms and -Xmx are only shortcuts which are internally mapped to -XX:InitialHeapSize and -XX:MaxHeapSize. These two XX flags may also be used directly, to the same effect:

java -XX:InitialHeapSize=128m -XX:MaxHeapSize=2g MyApp

 java -XX:PermSize=128m -XX:MaxPermSize=256m MyApp

XX:+UseCodeCacheFlushing

-XX:InitialCodeCacheSize=n Defines the initial size of the Code Cache.
-XX:ReservedCodeCacheSize=n Defines the maximum size of the Code Cache.

-XX:ReservedCodeCacheSize=32m Reserved code cache size (in bytes) - maximum code cache size. [Solaris 64-bit, amd64, and -server x86: 2048m; in 1.5.0_06 and earlier, Solaris 64-bit and and64: 1024m.]

https://developer.opentext.com/webaccess/#url=%2Fawd%2Fresources%2Farticles%2F6123%2Ftomcat%2Bconfiguration%2Bmemory%2B%2Bheap%2Band%2Bpermgen

Java Garbage Collection

In java, garbage means unreferenced objects.
Garbage Collection is process of reclaiming the runtime unused memory automatically. In other words, it is a way to destroy the unused objects.
To do so, we were using free() function in C language and delete() in C++. But, in java it is performed automatically. So, java provides better memory management.

Advantage of Garbage Collection

  • It makes java memory efficient because garbage collector removes the unreferenced objects from heap memory.
  • It is automatically done by the garbage collector(a part of JVM) so we don't need to make extra efforts.


http://jpbempel.blogspot.in/2012/11/the-usefull-jvm-options.html

GC Settings/Tuning
 For configuring GC, there is tons of options, specially for the CMS ! But at the end few are really usefull. I will not enter into fine tuning of CMS.

-XX:+UseSerialGC Activates classic monothreaded young GC
-XX:+UseParallelGC Activates multi-threaded young GC
-XX:+UseParNewGC Activates another multi-threaded young GC but required for CMS.
-XX:+UseParalelOldGC Activates multi-threaded Old GC.
-XX:+UseConcMarkSweepGC Activates Concurrent GC
-XX:+UseG1GC Activates Garbage First GC
-XX:ParallelGCThreads=n Fixes number of threads for Parallel*GC Usefull for multiple JVM on same machine to avoid GC threads disturb other JVM threads
-XX:CMSInitiatingOccupancyFraction=n Fixes fraction in percentage of the old when CMS start. Usefull when allocation rate is not very predictable.
-XX:+UseCMSInitiatingOccupancyOnly CMS only start based on the previous parameter and not on the internal heuristic.
-XX:+CMSClassUnloadingEnabled Enables to unload classes from PermGen during CMS GC. Otherwise you need to wait the FullGC.

Comments