linux TOMCAT Error

java.lang.OutOfMemoryError: PermGen space at java.lang.ClassLoader.defineClass1( Native  Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:620) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
It’s usually happened when the Tomcat start and stop few times. It’s just funny, however you can fine tune it with some minor changes in the Tomcat configuration setting. By default, Tomcat assigned very little memory for the running process, you should increase the memory by make change in  catalina.sh  or  catalina.bat  file.
How to fix it?



1) Find where is Cataline.sh located. We need to make some changes in “catalina.sh” file. 
P.S Cataline.sh is located at \tomcat folder\bin\catalina.sh
2) Assign following line to JAVA_OPTS variable and add it into catalina.sh file.


JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 
-server -Xms1536m -Xmx1536m
-XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m 
-XX:MaxPermSize=256m -XX:+DisableExplicitGC"

example :------------------------------------------------------------------------------------------------------
Partial example of the  catalina.sh  file
#   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 -Xms1536m 
-Xmx1536m -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
case  "`uname`" in
CYGWIN*) cygwin= true ;;
OS400*) os400= true ;;
Darwin*) darwin= true ;;
esac

# resolve links - $0 may be a softlink
PRG="$0"
3) Done. Restart Tomcat. 
You should change the “Xms” and “PermSize” value base on your server capability. 
Tomcat needs excessive memory!



I get all the time PermGen and other memory errors while I start/run tomcat on a VPS (Virtual Private Server).
Solution: At least this has worked for me... Edit catalina.sh:
export CATALINA_OPTS="-XX:-DoEscapeAnalysis -XX:MaxPermSize=192m"

Tomcat error: "tomcat java.lang.OutOfMemoryError: PermGen space"

solution : edit catalina.sh and add at the beginning (minimum configuration): JAVA_OPTS="-Xmx1024m -XX:MaxPermSize=256m" 

Tomcat error: "java.lang.OutOfMemoryError: PermGen space"

Edit $CATALINA_HOME/bin/catalina.sh and add the comments in the beginning:
export CATALINA_OPTS="-XX:MaxPermSize=216m"
Comment: default PermGen size for tomcat is 128MB.


Tomcat start error: "Error occurred during initialization of VM"



Edit $CATALINA_HOME/bin/catalina.sh and add the comments in the beginning:
export CATALINA_OPTS="-Xms512m -Xmx512m"


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.


root@server [/]# 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”
or
export CATALINA_OPTS=”-Xms1024m -Xmx1024m”  


Then restart the tomcat service  :
root@server[~]# /usr/local/jakarta/tomcat/bin/./shutdown.sh
root@server[~]# /usr/local/jakarta/tomcat/bin/./startup.sh
root@server[~]# /usr/local/jakarta/tomcat/bin/./catalina.sh run

That’s all this will do it.
Howto: Tomcat 6 installation in Ubuntu



Install:
$ sudo apt-get install tomcat6 tomcat6-admin tomcat6-user
Start/stop:
$ sudo service tomcat6 stop
$ sudo service tomcat6 start
Handy paths:

  • /usr/share/tomcat6/bin/{startup.sh,shutdown.sh}

  • /usr/share/tomcat6/webapps

  • /usr/share/tomcat6-admin

  • tail -f /var/log/tomcat6/*

  • /etc/default/tomcat6
How to deploy a war

Manually

Copy foo.war into $CATALINA_BASE/webapps/. Then access the app on  http://localhost:8080/foo/
With Tomcat Manager

Make sure you enable the user of the Tomcat Manager...see relative post


Tomcat install in ubuntu: error "java.net.BindException: Permission denied :80"

catalina.out error:


Jan 7, 2012 12:52:59 AM org.apache.catalina.startup.Catalina start
SEVERE: Catalina.start: 
LifecycleException:  service.getName(): "Catalina";  Protocol handler start failed: java.net.BindException: Permission denied :80
at org.apache.catalina.connector.Connector.start(Connector.java:1087)
at org.apache.catalina.core.StandardService.start(StandardService.java:531)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:593)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Solution

Edit /etc/default/tomcat6 and set last line equal to:
# 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
What is authbind?

$ apt-cache show authbind
Allows non-root programs to bind() to low ports
This package allows a package to be started as non-root but
still bind to low ports, without any changes to the application.
Tomcat: enable Tomcat Manager



Tomcat 7.0.23

edit $TOMCAT_HOME/conf/tomcat-users.xml and add a user:
<tomcat-users>
  <role rolename="manager-gui" />
  <user username="myusername" password="mypassword" roles="manager-gui" />
</tomcat-users>
Access Tomcat Manager:  http://localhost:8080/manager/html
Tomcat 6

edit $TOMCAT_HOME/conf/tomcat-users.xml and add a user:
<tomcat-users>
  <role rolename="manager" />
  <user username="myusername" password="mypassword" roles="manager" />
</tomcat-users>
Access Tomcat Manager:  http://localhost:8080/manager/html


Tomcat: change default port 8080 into 80

Edit tomcat/conf/server.xml and change:
into:
And not restart tomcat:
$ sudo $TOMCAT_HOME/bin/startup.sh
$ sudo $TOMCAT_HOME/bin/shutdown.sh
Setup SSL on Tomcat using a Public Certificate

To create and configure a public certificate for your Tomcat installation:


  • Open a SSH Terminal to the server.

  • In Terminal, navigate to the Tomcat directory by typing the following command:
    cd /var/lib/tomcat/

  • Type the following command to generate the keystore:
    sudo keytool -genkey -alias Tomcat -keysize 2048 -keyalg RSA –keystore /var/lib/tomcat/.mykeystore


Enter keystore password:  changeit

  • What is your first and last name? [Unknown]: Danesh Manoharan

  • What is the name of your organizational unit? [Unknown]: IT

  • What is the name of your organization? [Unknown]: My Comp.

  • What is the name of your City or Locality? [Unknown]: KL

  • What is the name of your State or Province? [Unknown]: KL

  • What is the two-letter country code for this unit? [Unknown]: MY

  • US Is CN=Danesh Manoharan, OU=IT, O=”My Comp.”, L=KL, ST=KL, C=MY correct? [no]: yes

  • Enter key password for (RETURN if same as keystore password): Hit Enter.




Lastly we will  edit the /var/lib/tomcat/conf/server.xml file. Point the “keystoreFile” attribute to the location of the keystore, and include the “keystorePass” containing the password to your keystore.This is the part of the file that you should modify: 
<Connector port=”8443″ protocol=”HTTP/1.1″ SSLEnabled=”true”
   maxThreads=”150″ scheme=”https” secure=”true”
   clientAuth=”false” sslProtocol=”TLS”
   keystoreFile=”/var/lib/tomcat/.mykeystor
   keystorePass=”your keystore password” />
 
How-To clear the Tomcat ssl:

1.Open a SSH terminal session to Ubuntu.
2.Create a backup of the previous alias by typing the following command:
sudo keytool -export -alias Tomcat -keystore /var/lib/tomcat/.mykeystore -file MyBackup.cer
3.After a successful backup, type the following command to clear out the Tomcat alias:
sudo keytool -delete -alias Tomcat -keystore /var/lib/tomcat/.mykeystore

You should now be able to run the commands to create and import a new certificate.

I hope this makes quick work for somone out there.. 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值