Arquivo da categoria: Tomcat

How to change Tomcat to use JDK 7

The current environment is using Tomcat 7 + JDK 6. How to configure Tomcat to use JDK 7?

Environment

  1. Tomcat 7 (apt-get install)
  2. Debian 7.5
  3. JDK 6 and JDK 7

P.S Tomcat 7 is installed via apt-get

Note
You may interest at this tutorial – Apache Tomcat 8 + JDK 8 on Debian

1. Solution

Update the JAVA_HOME in this file /etc/default/tomcat7

1.1 Edit /etc/default/tomcat7, update JAVA_HOME

$ sudo vim /etc/default/tomcat7
/etc/default/tomcat7
#...

# The home directory of the Java development kit (JDK). You need at least
# JDK version 1.5. If JAVA_HOME is not set, some common directories for
# OpenJDK, the Sun JDK, and various J2SE 1.5 versions are tried.
#JAVA_HOME=/usr/lib/jvm/openjdk-6-jdk
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64

#...

1.2 Restart Tomcat, done.

$ sudo service tomcat7 restart

1.3 Check this article to find out which JDK is used by Tomcat.

No SPACE, What the F!
Make sure there is no extra space between the equal symbol “=”, it will cause “JAVA_HOME no found”, I spent hours fixing this bug!For example

/etc/default/tomcat7
#...Wrong, SPACE
JAVA_HOME = /usr/lib/jvm/java-7-openjdk-amd64

#...Correct
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64

How to change Tomcat to use JDK 7

How to fix Tomcat WARNING: An attempt was made to authenticate the locked user?

The warning above means that you fail to authenticate the user tomcat more than once. Tomcat suspects that it is brute force attack on the user tomcat.

What authentication you use in your application? What login-config you use in web.xml of the application?

The default configuration of resourceName “UserDatabase” is the file conf/tomcat-users.xml. Did you change the configuration of resourceName “UserDatabase”?

You can find the configuration of the resource UserDatabase in the file server.xml:

<Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />

By default all users are commented. To be able to work with users from the XML file you should uncomment. Then, you will be able to login with user tomcat:

<tomcat-users>
  <role rolename="tomcat"/>
  <user username="tomcat" password="tomcat" roles="tomcat"/>
</tomcat-users>

https://stackoverflow.com/questions/15337296/how-to-fix-tomcat-warning-an-attempt-was-made-to-authenticate-the-locked-user

Trocando porta do Tomcat da 8080 para 80 no Linux

1) Vá na pasta “conf” no diretório de instalação do tomcat.
Exemplo de caminho:

/var/lib/tomcat7/conf

2) Abra o arquvivo “server.xml”.

3) Troque a port=8080 para port=80.

4) Salve o arquivo.

5) Edite as configurações do Tomcat.
Exemplo de caminho:

sudo vi /etc/default/tomcat7

6) Remova o # que simboliza um comentário e troque o NO por YES.

AUTHBIND=yes

7) Instale o Authbind.

sudo apt-get install authbind

8) Execute esses comandos para fazer o Tomcat executar na porta 80:

sudo touch /etc/authbind/byport/80
sudo chmod 500 /etc/authbind/byport/80
sudo chown tomcat7 /etc/authbind/byport/80

9) Restart o Tomcat.

sudo service tomcat7 restart

Referência: http://stackoverflow.com/questions/4756039/how-to-change-the-port-of-tomcat-from-8080-to-80

Script Shell de serviço no linux

O script vai ficar na pasta “/etc/init.d” e depois basta dar um:

sudo nano tomcat7

Depois que abrir o editor basta colar isso:

#!/bin/sh
#
# description: Tomcat Server basic start/shutdown script
# processname: tomcat
 
# Source function library.
if [ -f /etc/rc.d/init.d/functions ];
then
    . /etc/rc.d/init.d/functions
fi
 
 
JAVA_HOME=/usr/java/latest
export JAVA_HOME
 
TOMCAT_HOME=/opt/tomcat/bin
START_TOMCAT=/opt/tomcat/bin/startup.sh
STOP_TOMCAT=/opt/tomcat/bin/shutdown.sh
VERSION_TOMCAT=/opt/tomcat/bin/version.sh
 
 start() {
     echo -n "Starting tomcat: "
     cd $TOMCAT_HOME
     ${START_TOMCAT}
     echo "done."
 }
 
 stop() {
     echo -n "Shutting down tomcat: "
     cd $TOMCAT_HOME
     ${STOP_TOMCAT}
     echo "done."
 }
 
 case "$1" in
          start)
             start
           ;;
 
          stop)
             stop
           ;;
 
         restart)
           stop
           sleep 10
           start
           ;;
         *)
           echo "Usage: $0 {start|stop|restart}"
 esac
 exit 0

Site de referência: http://askubuntu.com/questions/223944/how-to-automatically-restart-tomcat7-on-system-reboots/224402