Il y a 389 articles et 19 utilisateurs inscrits (ce bandeau est défini dans MediaWiki:Sitenotice)

« Tomcat » : différence entre les versions

De AJLSM
Aller à la navigation Aller à la recherche
Aucun résumé des modifications
 
(39 versions intermédiaires par 3 utilisateurs non affichées)
Ligne 1 : Ligne 1 :
{{notice|Si vous ne parvenez pas à trouver Tomcat, consulter la page [[Localiser Tomcat]]}}
{{notice|Si vous ne parvenez pas à trouver Tomcat, consulter la page [[Localiser Tomcat]]}}


== Allocation Mémoire (RAM) avec {{var|JAVA_OPTS}} ==
[[category:How To]]
On utilise la variable d'environnement {{var|JAVA_OPTS}}<ref>[http://publib.boulder.ibm.com/wasce/V2.0.0/en/javaopts.html The JAVA_OPTS environment variable] @ ibm.com</ref> pour définir l'allocation mémoire du processus Tomcat. On placera généralement cette variable dans {{path|{{Tomcat}}/bin/startup.sh}}. Elle peut cependant avoir été défini dans :
* {{path|{{Tomcat}}/bin/catalina.sh}}
* {{path|{{HOME}}/.bashrc}}
On définira la l'option comme suit :
<syntaxhighlight lang="bash">
JAVA_OPTS="-Dfile.encoding=UTF-8 -Xmx2500m -XX:MaxPermSize=128m -XX:NewSize=300m -Djava.awt.headless=true -server"
</syntaxhighlight>
C'est la valeur {{var|-Xmx2500m}} qui défini l'allocation, ici on alloue 2.5Go. On '''adaptera l'allocation en fonction du serveur et en fonction des besoins''' de publication.


=== Forcer la locale ===
== Arrêt et redémarrage automatique ==


Pour forcer la locale du Tomcat, on va rajouter les options {{cmd|-Duser.language&#61;fr}} et {{cmd|-Duser.region&#61;FR"}} dans la variable {{var|JAVA_OPTS}} du fichier {{path|{{tomcat}}/bin/catalina.sh}}.
<syntaxhighlight lang="bash">
JAVA_OPTS="-Dfile.encoding=UTF-8 -Xmx4000m -XX:MaxPermSize=256m -XX:NewSize=300m -Djava.awt.headless=true -server -Duser.language=fr -Duser.region=FR"
</syntaxhighlight>
== Arrêt et redémarrage automatique ==
Nous utiliserons un script {{cmd|init}} dans le cas d'une installation à partir des sources de {{tomcat}}.<ref>[http://ieg.ignou.ac.in/wiki/index.php/User:Ganesh.tamang/How_To_In_LINUX/How_To_Install_Tomcat6_on_Debian_or_Ubuntu#step_10:_Writing_Startup_Script_for_tomcat_6 Writing Startup Script for tomcat 6 ]</ref>
Nous utiliserons un script {{cmd|init}} dans le cas d'une installation à partir des sources de {{tomcat}}.<ref>[http://ieg.ignou.ac.in/wiki/index.php/User:Ganesh.tamang/How_To_In_LINUX/How_To_Install_Tomcat6_on_Debian_or_Ubuntu#step_10:_Writing_Startup_Script_for_tomcat_6 Writing Startup Script for tomcat 6 ]</ref>
{{remarque|Il est inutile de suivre cette procédure lors d'une installation via le gestionnaire de paquet de votre OS}}  
{{remarque|Il est inutile de suivre cette procédure lors d'une installation via le gestionnaire de paquet de votre OS}}  


=== Création du script ===
=== Création du script ===
{{important|Si vous avez plusieurs instance tomcat il faudra un script d'initialisation pour chaque instance}}
{{important|Si vous avez plusieurs instance tomcat il faudra un script d'initialisation pour chaque instance}}
{{notice|Penser à adapter le chemin vers le dossier de votre Tomcat (cf. {{var|$CATALINA_HOME}}) et le chemin vers la JVM ({{var|$JAVA_HOME}})}}
{{notice|Penser à adapter le chemin vers le dossier de votre Tomcat (cf. {{var|$CATALINA_HOME}}) et le chemin vers la JVM ({{var|$JAVA_HOME}})}}
Ligne 70 : Ligne 58 :


     esac
     esac
exit 0
exit 0</syntaxhighlight>
</syntaxhighlight>
 


=== Ajout du script init au système ===
=== Ajout du script init au système ===
Il faut d'abord rendre le script {{path|/etct/init.d/tomcat{{value|-front{{!}}back}}.sh}} executable par le système puis on l'ajoute aux scripts démarrer par défaut :
Il faut d'abord rendre le script {{path|/etct/init.d/tomcat{{value|-front{{!}}back}}.sh}} executable par le système puis on l'ajoute aux scripts démarrer par défaut :
<syntaxhighlight lang="bash">
 
chmod u=rwx,g=rx,o=x tomcat6*
<syntaxhighlight lang="bash">chmod u=rwx,g=rx,o=x tomcat6*
update-rc.d tomcat6-front.sh defaults
update-rc.d tomcat6-front.sh defaults</syntaxhighlight>
</syntaxhighlight>
 
On fait un petit test pour vérfier qu'il n'y a pas d'erreur :
On fait un petit test pour vérfier qu'il n'y a pas d'erreur :
<syntaxhighlight lang="bash">
 
/etc/init.d/tomcat6-front.sh restart
<syntaxhighlight lang="bash">/etc/init.d/tomcat6-front.sh restart</syntaxhighlight>
</syntaxhighlight>
 


=== Tâche cron journalière de redémarrage ===
=== Tâche cron journalière de redémarrage ===
{{important|La description ci-dessous considère que vous utiliser l'[[Arborescence de production]] et les '''scripts shell''' préconisé pour les installations.}}
{{important|La description ci-dessous considère que vous utiliser l'[[Arborescence de production]] et les '''scripts shell''' préconisé pour les installations.}}
On s'appuie sur la function {{cmd|flushAndRestart}} défini dans {{path|~/.bashrc}} ou {{path|~/.ajlsmrc}}
On s'appuie sur la function {{cmd|flushAndRestart}} défini dans {{path|~/.bashrc}} ou {{path|~/.ajlsmrc}}
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
@daily  flushAndRestart front
@daily  flushAndRestart front
Ligne 92 : Ligne 83 :
</syntaxhighlight>
</syntaxhighlight>


== Encodage des paramètres envoyés avec la méthode {{value|GET}} ==
 
La configuration de {{tomcat}}<ref>[https://wiki.apache.org/tomcat/FAQ/CharacterEncoding#Q2 Configuration de {{tomcat}}]</ref> peut également jouer un rôle dans ce genre de problème. Voici la configuration recommandée (dans {{path|./conf/server.xml}}) pour les connecteur {{value|HTTP}} et {{value|AJP}} :
= Tomcat7 =
<syntaxhighlight lang="xml" highlight="2,7">
Installation:
<Connector port="8080" protocol="HTTP/1.1"
apt-get install tomcat7 imagemagick
  URIEncoding="UTF-8"
 
  ⋮
Post-installation
/>
mkdir /usr/share/tomcat7/.fop
⋮
chown tomcat7:tomcat7 /usr/share/tomcat7/.fop
<Connector port="8009" protocol="AJP/1.3"
 
  URIEncoding="UTF-8"
Tests:
  ⋮
convert
/>
Publication
Recherche accentuée
Export PDF
 
== Exemple de configuration ==
 
Vider les welcome-file-list, afin que Tomcat 7 ne rajoute pas "index.html" à la fin de chaque url terminant par "/".
 
/etc/tomcat7/web.xml:4280
    <welcome-file-list>
    </welcome-file-list>
 
 
/etc/tomcat7/context.xml:
<syntaxhighlight lang="xml">
<Context sessionCookiePath="/">
  [...]
    <Resource name="jdbc/pleade_prod" auth="Container" type="javax.sql.DataSource"
        url="jdbc:mysql://localhost/pleade_prod?useEncoding=true&amp;characterEncoding=UTF-8"
        driverClassName="com.mysql.jdbc.Driver"
        username="sdxapp" password="sdxapp-pwd"
        maxTotal="25" maxIdle="10"
        defaultTransactionIsolation="READ_COMMITTED"
        validationQuery="Select 1"
    />
</syntaxhighlight>
</syntaxhighlight>


== Tomcat7 ==
/etc/tomcat7/server.xml:
=== Gestion des sessions ===
    <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443"
{{important|La gestion des sessions à changer dans Tomcat7<ref>[http://stackoverflow.com/questions/3980392/tomcat-7-session-cookie-path Tomcat 7 session cookie path] @ StackOverflow</ref>}}
              maxParameterCount="50000" maxPostSize="10000000"
L'attribut que {{attr|emptySessionPath}}="{{value|true}}" que l'on placer dans les connecteurs du fichier {{path|<tomcat'''6'''>/conf/server.xml}} ne sert plus.
              maxHttpHeaderSize="8192000" URIEncoding="UTF-8" />
Il faut maintenant éditer le fichier {{path|<tomcat'''7'''>/conf/context.xml}} et ajouter l'attribut {{attr|sessionCookiePath}}="{{value|/}}", puis redémarrer le serveur Tomcat.<ref>[https://tomcat.apache.org/migration-7.html#Session_cookie_configuration Session cookie configuration] @ Tomcat doc</ref>
    [...]
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443"
              maxParameterCount="50000" maxPostSize="10000000" maxThreads="50"
              packetSize="8192000" URIEncoding="UTF-8" />
 
/etc/default/tomcat7:
JAVA_OPTS="-Djava.awt.headless=true -Xmx2048m -XX:+UseConcMarkSweepGC -Duser.language=fr -Duser.region=FR -Dfile.encoding=UTF-8 -XX:PermSize=128m -XX:MaxPermSize=128m -XX:NewSize=256m -Djava.security.egd=file:/dev/./urandom"
 
Il faut également ajouter dans la configuration apache pour le serveur :
<syntaxhighlight lang="bash">
<VirtualHost *:80>
        LimitRequestFieldSize 81920
        ProxyIOBufferSize 81920
</syntaxhighlight>
 
=== AVEC APR ===
# Installer libtcnative-1
# Décommenter la ligne dans server.xml
Cf http://vincentdevillers.blogspot.fr/2013/09/installing-tomcat-7-on-debianubuntu.html
Pour CentOS/HEL: http://blogoless.blogspot.fr/2012/08/how-to-install-apache-tomcat-native.html
 
== Checklist ==
# '''sessionCookiePath="/"''' dans <Context de ''context.xml''
# '''?useEncoding=true&amp;characterEncoding=UTF-8''' dans la <Resource de ''context.xml''
# '''max*''' & '''URIEncoding="UTF-8"''' dans les <Connector de ''server.xml''
# ''-Xmx2048m -Duser.language=fr -Duser.region=FR -Dfile.encoding=UTF-8'' dans les JAVA_OPTS
# Le paramétrage Apache2, cf ci-dessus
 
= Tomcat 6 =
 
== Exemple de configuration ==
 
/etc/tomcat6/context.xml:
  [...]
    <Resource name="jdbc/pleade_prod" auth="Container" type="javax.sql.DataSource"
        maxActive="100" maxIdle="30" maxWait="10000"
        url="jdbc:mysql://localhost/pleade_prod?useEncoding=true&amp;characterEncoding=UTF-8"
        driverClassName="com.mysql.jdbc.Driver"
        username="sdxapp" password="sdxapp-pwd"/>
 
/etc/tomcat6/server.xml:
    <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443"
              maxParameterCount="50000" maxPostSize="10000000" emptySessionPath="true"
              maxHttpHeaderSize="8192000" URIEncoding="UTF-8" />
    [...]
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443"
              maxParameterCount="50000" maxPostSize="10000000"
              emptySessionPath="true" packetSize="8192000"
              maxThreads="50" URIEncoding="UTF-8" />
 
/etc/default/tomcat6:
JAVA_OPTS="-Djava.awt.headless=true -Xmx2048m -Duser.language=fr -Duser.region=FR -Dfile.encoding=UTF-8 -XX:+UseConcMarkSweepGC"
 
Il faut également ajouter dans la configuration apache pour le serveur :
<syntaxhighlight lang="bash">
<VirtualHost *:80>
        LimitRequestFieldSize 81920
        ProxyIOBufferSize 81920
</syntaxhighlight>
 
== Checklist ==
# '''?useEncoding=true&amp;characterEncoding=UTF-8''' dans la <Resource de ''context.xml''
# '''max*''' '''emptySessionPath="true"''' & '''URIEncoding="UTF-8"''' dans les <Connector de ''server.xml''
# ''-Xmx2048m -Duser.language=fr -Duser.region=FR -Dfile.encoding=UTF-8'' dans les JAVA_OPTS
# Le paramétrage Apache2, cf ci-dessus


== Arrêter Tomcat 6.0 à partir du PID ==
== Arrêter Tomcat 6.0 à partir du PID ==
Ligne 116 : Ligne 195 :
Arrêter Tomcat :
Arrêter Tomcat :


<syntaxhighlight lang="bash">$TOMCAT_HOME/bin/shutdown.sh</syntaxhighlight>
<syntaxhighlight lang="bash">$TOMCAT_HOME/bin/catalina.sh stop</syntaxhighlight>


Définir la variable d'environnement {{var|CATALINA_BASE}} dans {{path|~/.profile}} :
Définir la variable d'environnement {{var|CATALINA_BASE}} dans {{path|~/.profile}} :
Ligne 126 : Ligne 205 :
<syntaxhighlight lang="bash">CATALINA_PID="$CATALINA_BASE/bin/catalina.pid"</syntaxhighlight>
<syntaxhighlight lang="bash">CATALINA_PID="$CATALINA_BASE/bin/catalina.pid"</syntaxhighlight>


Modifier le fichier {{path|{{var|$TOMCAT_HOME}}/bin/shutdown.sh}},
Redémarrer Tomcat :
en ajoutant la ligne suivante :
 
<syntaxhighlight lang="bash">$TOMCAT_HOME/bin/catalina.sh start</syntaxhighlight>
 
Pour arrêter Tomcat :


<syntaxhighlight lang="bash">rm -f $CATALINA_BASE/bin/catalina.pid</syntaxhighlight>
<syntaxhighlight lang="bash">cat $TOMCAT_HOME/bin/catalina.pid | xargs kill -9</syntaxhighlight>


Redémarrer Tomcat :
== Erreurs à l'arrêt du serveur ==


<syntaxhighlight lang="bash">$TOMCAT_HOME/bin/startup.sh</syntaxhighlight>
<syntaxhighlight lang="bash">
$ catalina.sh stop
Using CATALINA_BASE:  /usr/local/apache-tomcat-6.0.36
Using CATALINA_HOME:  /usr/local/apache-tomcat-6.0.36
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-6.0.36/temp
Using JRE_HOME:        /usr/local/jdk1.6.0_39
Using CLASSPATH:      /usr/local/apache-tomcat-6.0.36/bin/bootstrap.jar
Using CATALINA_PID:    /usr/local/apache-tomcat-6.0.36/bin/catalina.pid
15 mars 2013 11:22:47 org.apache.catalina.startup.Catalina stopServer
GRAVE: Catalina.stop:
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)</syntaxhighlight>


Pour arrêter Tomcat :
Arrêter Tomcat :


<syntaxhighlight lang="bash">cat $TOMCAT_HOME/bin/catalina.pid | xargs kill -9</syntaxhighlight>
<syntaxhighlight lang="bash">cat $TOMCAT_HOME/bin/catalina.pid | xargs kill -9</syntaxhighlight>
Supprimer le fichier {{path|catalina.pid}} :
<syntaxhighlight lang="bash">rm -f $TOMCAT_HOME/bin/catalina.pid</syntaxhighlight>
Démarrer Tomcat :
<syntaxhighlight lang="bash">$TOMCAT_HOME/bin/catalina.sh start</syntaxhighlight>
== Démarrer Tomcat ==
On utilise soit le script $TOMCATcatalina.sh, soit le script startup.sh.
<syntaxhighlight lang="bash">netstat -a | grep "LISTEN"
tcp        0      0 localhost.localdom:7634 *:*                    LISTEN   
tcp        0      0 localhost.locald:domain *:*                    LISTEN   
tcp        0      0 *:ssh                  *:*                    LISTEN   
tcp        0      0 localhost.localdoma:ipp *:*                    LISTEN   
tcp        0      0 localhost.lo:postgresql *:*                    LISTEN   
tcp        0      0 localhost.localdom:smtp *:*                    LISTEN   
tcp        0      0 *:http                  *:*                    LISTEN   
tcp6      0      0 [::]:ssh                [::]:*                  LISTEN   
tcp6      0      0 ip6-localhost:ipp      [::]:*                  LISTEN   
tcp6      0      0 ip6-localhost:smtp      [::]:*                  LISTEN   
tcp6      0      0 localhost.localdom:8005 [::]:*                  LISTEN   
tcp6      0      0 [::]:8009              [::]:*                  LISTEN   
tcp6      0      0 [::]:http-alt          [::]:*                  LISTEN</syntaxhighlight>
== Les logs de tomcat ==
{{important|
Selon les serveurs et les distributions, le serveur {{Tomcat}} se trouve dans des répertoires différents. Il faut donc :
# [[Localiser Tomcat|localiser Tomcat]] ;
# définir la '''variable {{var|tomcatDir}}'''.
On peut ensuite executer les commandes ci-dessous}}
=== La journalisation de Tomcat ===
<syntaxhighlight lang="bash">tail -f $TOMCAT_HOME/logs/catalina.out</syntaxhighlight>
=== Supprimer les fichiers de journalisation de Tomcat ===
<syntaxhighlight lang="bash">
sudo service tomcat6 stop
sudo rm "$tomcatDir"/logs/*
sudo service tomcat6 start
</syntaxhighlight>
== APR ==
L'erreur suivante est indiquée dans les logs du fichier catalina.out:
<syntaxhighlight lang="bash">
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/local/jdk1.6.0_45/jre/lib/i386/server:/usr/local/jdk1.6.0_45/jre/lib/i386:/usr/local/jdk1.6.0_45/jre/../lib/i386:/usr/java/packages/lib/i386:/lib:/usr/lib</syntaxhighlight>
Pré-requis :
* les outils nécessaires pour compiler en C/C++; 
* un jdk 6 installé et la variable d'environnement JAVA_HOME configurée;
* un tomcat 6 installé et la variable d'environnement CATALINA_HOME configurée;
* éventuellement openssl.
<syntaxhighlight lang="bash">
apt-get update
apt-get install openssl gcc make
$JAVA_HOME/bin/java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) Server VM (build 20.45-b01, mixed mode)
echo $CATALINA_HOME
/usr/local/apache-tomcat-6.0.36
</syntaxhighlight>
<syntaxhighlight lang="bash">
apt-get install libapr1-dev libssl-dev
cd $CATALINA_HOME/bin
wget http://apache.websitebeheerjd.nl//tomcat/tomcat-connectors/native/1.1.27/source/tomcat-native-1.1.27-src.tar.gz
cp tomcat-native-1.1.27-src.tar.gz /usr/local/src/libs-tomcat-6.0.36/
tar -xvzf tomcat-native-1.1.27-src.tar.gz
cd tomcat-native-1.1.27-src/jni/native/
./configure --with-apr=/usr/bin/apr-1-config --with-java-home=$JAVA_HOME --with-ssl=yes --prefix=$CATALINA_HOME
make && make install
</syntaxhighlight>
{{path|/usr/bin/apr-1-config}} est le chemin par défaut du binaire APR. Ce chemin peut changer suivant la version de la librairie APR.
La fin de l'installation doit se terminer par les lignes suivantes :
<syntaxhighlight lang="bash">
----------------------------------------------------------------------
Libraries have been installed in:
  /usr/local/apache-tomcat-6.0.36/lib
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
  - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
    during execution
  - add LIBDIR to the `LD_RUN_PATH' environment variable
    during linking
  - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
  - have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
</syntaxhighlight>
Et enfin ajouter dans {{path|/etc/init.d/tomcat}} ou par exemple dans {{path|~/.profile}},
la variable d'environnement LD_LIBRARY_PATH des librairies de Tomcat :
<syntaxhighlight lang="bash">
{{path|LD_LIBRARY_PATH=$CATALINA_HOME/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH}}
</syntaxhighlight>
Dans le cas de l'utilisation du fichier {{path|~/.profile}},
le shell courant prendra en charge la nouvelle configuration de ce fichier
grace à la commande :
<syntaxhighlight lang="bash">
source ~/.profile
</syntaxhighlight>
On vérifie la prise en charge de l'APR par Tomcat :
On redémarre Tomcat :
<syntaxhighlight lang="bash">
$CATALINA_HOME/bin/catalina.sh stop
$CATALINA_HOME/bin/catalina.sh start
</syntaxhighlight>
Le fichier de log $CATALINA_HOME/logs/catalina.out doit contenir les lignes suivantes :
<syntaxhighlight lang="bash">
25 avr. 2013 14:43:59 org.apache.catalina.core.AprLifecycleListener init
INFO: Loaded APR based Apache Tomcat Native library 1.1.27 using APR version 1.4.2.
25 avr. 2013 14:43:59 org.apache.catalina.core.AprLifecycleListener init
INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
25 avr. 2013 14:43:59 org.apache.catalina.core.AprLifecycleListener initializeSSL
INFO: OpenSSL successfully initialized with version OpenSSL 0.9.8o 01 Jun 2010
</syntaxhighlight>
Note : il est aussi possible d'installer la librairie APR manuellement.
<syntaxhighlight lang="bash">
cd /usr/local/src
wget http://wwwftp.ciril.fr/pub/apache//apr/apr-1.4.6.tar.gz
tar -xvzf apr-1.4.6.tar.gz
cd apr-1.4.6
./configure --prefix=/usr/local/apache-tomcat-6.0.36/lib/apr
make
make test
make install
</syntaxhighlight>
Pour Tomcat 6.0, la documentation de l'APR est sur [[Apache Portable Runtime (APR) based Native library for Tomcat|http://tomcat.apache.org/tomcat-6.0-doc/apr.html#Installation]] et les sources sont disponibles sur [[Apache Portable Runtime| http://apr.apache.org/download.cgi]].
Pour plus de détails, voir [[Installer la Apache Tomcat native library|http://quickfix.free.fr/?p=350]].
== Localiser Tomcat ==
Voici la liste des emplacement où j'ai pu rencontrer (ou placer) {{Tomcat}} :
* {{path|/opt/}}
* {{path|~/apps/tomcat-*}}
* {{path|~/apps/apache-tomcat-*}}
* {{path|/mnt/data/apps/tomcat-*}}
* {{path|/mnt/data/apps/apache-tomcat-*}}




== References ==
== References ==
# [https://wiki.apache.org/tomcat/FAQ/Memory FAQ / Memory] @ Tomcat wiki
# [https://wiki.apache.org/tomcat/FAQ/Memory FAQ / Memory] @ Tomcat wiki
<references/>
<references/>
Ligne 148 : Ligne 425 :
[[category:Java]]
[[category:Java]]
[[category:Ville-Dole]]
[[category:Ville-Dole]]
== Voir la version de tomcat ==
<syntaxhighlight lang="bash">
java -cp /usr/share/tomcat6/lib/catalina.jar org.apache.catalina.util.ServerInfo
</syntaxhighlight>

Dernière version du 21 mai 2016 à 20:59

Notice :
Si vous ne parvenez pas à trouver Tomcat, consulter la page Localiser Tomcat.

Arrêt et redémarrage automatique

[modifier | modifier le wikicode]

Nous utiliserons un script init dans le cas d'une installation à partir des sources de Apache Tomcat.<ref>Writing Startup Script for tomcat 6 </ref>

Remarques : Il est inutile de suivre cette procédure lors d'une installation via le gestionnaire de paquet de votre OS.


Création du script

[modifier | modifier le wikicode]
Important :
Si vous avez plusieurs instance tomcat il faudra un script d'initialisation pour chaque instance.
Notice :
Penser à adapter le chemin vers le dossier de votre Tomcat (cf. $CATALINA_HOME) et le chemin vers la JVM ($JAVA_HOME).

Il faut placer le contenu du script ci-dessous dans /etc/init.d/tomcat-front|back.sh

#!/bin/sh
###BEGIN INIT INFO
# Provides:          tomcat
# Required-Start:    $local_fs $remote_fs $network
# Required-Stop:     $local_fs $remote_fs $network
# Should-Start:      $named
# Should-Stop:       $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start Tomcat.
# Description:       Start the Tomcat servlet engine.
### END INIT INFO
# Tomcat 6 init-script

# ATTENTION ! Si vous avez plusieurs instance tomcat il faudra plusieurs script d'initialisation
CATALINA_HOME=/opt/tomcat6-front
JAVA_HOME=/usr/lib/jvm/java-6-sun
#JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.13

export CATALINA_HOME
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
case $1 in
     start)
          sh "$CATALINA_HOME"/bin/startup.sh
          echo "tomcat6 started successfully"
          ;;
     stop)
          sh "$CATALINA_HOME"/bin/shutdown.sh
          echo "tomcat6 stoped successfully"
          ;;
     restart)
          sh "$CATALINA_HOME"/bin/shutdown.sh
          sh "$CATALINA_HOME"/bin/startup.sh
          echo "tomcat6 restarted successfully"
          ;;
       *)
          sh "$CATALINA_HOME"/bin/startup.sh
          echo "tomcat6 started successfully"
   ;;

     esac
exit 0


Ajout du script init au système

[modifier | modifier le wikicode]

Il faut d'abord rendre le script /etct/init.d/tomcat-front|back.sh executable par le système puis on l'ajoute aux scripts démarrer par défaut :

chmod u=rwx,g=rx,o=x tomcat6*
update-rc.d tomcat6-front.sh defaults

On fait un petit test pour vérfier qu'il n'y a pas d'erreur :

/etc/init.d/tomcat6-front.sh restart


Tâche cron journalière de redémarrage

[modifier | modifier le wikicode]
Important :
La description ci-dessous considère que vous utiliser l'Arborescence de production et les scripts shell préconisé pour les installations..

On s'appuie sur la function flushAndRestart défini dans ~/.bashrc ou ~/.ajlsmrc

@daily  flushAndRestart front
#@daily flushAndRestart back


Installation:

apt-get install tomcat7 imagemagick 

Post-installation

mkdir /usr/share/tomcat7/.fop
chown tomcat7:tomcat7 /usr/share/tomcat7/.fop

Tests:

convert
Publication
Recherche accentuée
Export PDF

Exemple de configuration

[modifier | modifier le wikicode]

Vider les welcome-file-list, afin que Tomcat 7 ne rajoute pas "index.html" à la fin de chaque url terminant par "/".

/etc/tomcat7/web.xml:4280

   <welcome-file-list>
   </welcome-file-list>


/etc/tomcat7/context.xml:

 <Context sessionCookiePath="/">
  [...]
    <Resource name="jdbc/pleade_prod" auth="Container" type="javax.sql.DataSource"
        url="jdbc:mysql://localhost/pleade_prod?useEncoding=true&amp;characterEncoding=UTF-8"
        driverClassName="com.mysql.jdbc.Driver"
        username="sdxapp" password="sdxapp-pwd"
        maxTotal="25" maxIdle="10"
        defaultTransactionIsolation="READ_COMMITTED"
        validationQuery="Select 1"
    />

/etc/tomcat7/server.xml:

   <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443"
              maxParameterCount="50000" maxPostSize="10000000"
              maxHttpHeaderSize="8192000" URIEncoding="UTF-8" />
   [...]
   <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" 
              maxParameterCount="50000" maxPostSize="10000000" maxThreads="50" 
              packetSize="8192000" URIEncoding="UTF-8" />

/etc/default/tomcat7:

JAVA_OPTS="-Djava.awt.headless=true -Xmx2048m -XX:+UseConcMarkSweepGC -Duser.language=fr -Duser.region=FR -Dfile.encoding=UTF-8 -XX:PermSize=128m -XX:MaxPermSize=128m -XX:NewSize=256m -Djava.security.egd=file:/dev/./urandom"

Il faut également ajouter dans la configuration apache pour le serveur :

<VirtualHost *:80>
        LimitRequestFieldSize 81920
        ProxyIOBufferSize 81920
  1. Installer libtcnative-1
  2. Décommenter la ligne dans server.xml

Cf http://vincentdevillers.blogspot.fr/2013/09/installing-tomcat-7-on-debianubuntu.html Pour CentOS/HEL: http://blogoless.blogspot.fr/2012/08/how-to-install-apache-tomcat-native.html

  1. sessionCookiePath="/" dans <Context de context.xml
  2. ?useEncoding=true&characterEncoding=UTF-8 dans la <Resource de context.xml
  3. max* & URIEncoding="UTF-8" dans les <Connector de server.xml
  4. -Xmx2048m -Duser.language=fr -Duser.region=FR -Dfile.encoding=UTF-8 dans les JAVA_OPTS
  5. Le paramétrage Apache2, cf ci-dessus

Exemple de configuration

[modifier | modifier le wikicode]

/etc/tomcat6/context.xml:

 [...]
   <Resource name="jdbc/pleade_prod" auth="Container" type="javax.sql.DataSource"
       maxActive="100" maxIdle="30" maxWait="10000"
       url="jdbc:mysql://localhost/pleade_prod?useEncoding=true&characterEncoding=UTF-8"
       driverClassName="com.mysql.jdbc.Driver"
       username="sdxapp" password="sdxapp-pwd"/>

/etc/tomcat6/server.xml:

   <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443"
              maxParameterCount="50000" maxPostSize="10000000" emptySessionPath="true"
              maxHttpHeaderSize="8192000" URIEncoding="UTF-8" />
   [...]
   <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" 
              maxParameterCount="50000" maxPostSize="10000000" 
              emptySessionPath="true" packetSize="8192000" 
              maxThreads="50" URIEncoding="UTF-8" />

/etc/default/tomcat6:

JAVA_OPTS="-Djava.awt.headless=true -Xmx2048m -Duser.language=fr -Duser.region=FR -Dfile.encoding=UTF-8 -XX:+UseConcMarkSweepGC"

Il faut également ajouter dans la configuration apache pour le serveur :

<VirtualHost *:80>
        LimitRequestFieldSize 81920
        ProxyIOBufferSize 81920
  1. ?useEncoding=true&characterEncoding=UTF-8 dans la <Resource de context.xml
  2. max* emptySessionPath="true" & URIEncoding="UTF-8" dans les <Connector de server.xml
  3. -Xmx2048m -Duser.language=fr -Duser.region=FR -Dfile.encoding=UTF-8 dans les JAVA_OPTS
  4. Le paramétrage Apache2, cf ci-dessus

Arrêter Tomcat 6.0 à partir du PID

[modifier | modifier le wikicode]

Arrêter Tomcat :

$TOMCAT_HOME/bin/catalina.sh stop

Définir la variable d'environnement CATALINA_BASE dans ~/.profile :

CATALINA_BASE=/usr/local/apache-tomcat-6.0.36

Créer le fichier $TOMCAT_HOME/bin/setenv.sh :

CATALINA_PID="$CATALINA_BASE/bin/catalina.pid"

Redémarrer Tomcat :

$TOMCAT_HOME/bin/catalina.sh start

Pour arrêter Tomcat :

cat $TOMCAT_HOME/bin/catalina.pid | xargs kill -9

Erreurs à l'arrêt du serveur

[modifier | modifier le wikicode]
$ catalina.sh stop
Using CATALINA_BASE:   /usr/local/apache-tomcat-6.0.36
Using CATALINA_HOME:   /usr/local/apache-tomcat-6.0.36
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-6.0.36/temp
Using JRE_HOME:        /usr/local/jdk1.6.0_39
Using CLASSPATH:       /usr/local/apache-tomcat-6.0.36/bin/bootstrap.jar
Using CATALINA_PID:    /usr/local/apache-tomcat-6.0.36/bin/catalina.pid
15 mars 2013 11:22:47 org.apache.catalina.startup.Catalina stopServer
GRAVE: Catalina.stop: 
java.net.ConnectException: Connection refused
	at java.net.PlainSocketImpl.socketConnect(Native Method)

Arrêter Tomcat :

cat $TOMCAT_HOME/bin/catalina.pid | xargs kill -9

Supprimer le fichier catalina.pid :

rm -f $TOMCAT_HOME/bin/catalina.pid

Démarrer Tomcat :

$TOMCAT_HOME/bin/catalina.sh start


Démarrer Tomcat

[modifier | modifier le wikicode]

On utilise soit le script $TOMCATcatalina.sh, soit le script startup.sh.


netstat -a | grep "LISTEN"
tcp        0      0 localhost.localdom:7634 *:*                     LISTEN     
tcp        0      0 localhost.locald:domain *:*                     LISTEN     
tcp        0      0 *:ssh                   *:*                     LISTEN     
tcp        0      0 localhost.localdoma:ipp *:*                     LISTEN     
tcp        0      0 localhost.lo:postgresql *:*                     LISTEN     
tcp        0      0 localhost.localdom:smtp *:*                     LISTEN     
tcp        0      0 *:http                  *:*                     LISTEN     
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN     
tcp6       0      0 ip6-localhost:ipp       [::]:*                  LISTEN     
tcp6       0      0 ip6-localhost:smtp      [::]:*                  LISTEN     
tcp6       0      0 localhost.localdom:8005 [::]:*                  LISTEN     
tcp6       0      0 [::]:8009               [::]:*                  LISTEN     
tcp6       0      0 [::]:http-alt           [::]:*                  LISTEN


Les logs de tomcat

[modifier | modifier le wikicode]
Important :

Selon les serveurs et les distributions, le serveur Apache Tomcat se trouve dans des répertoires différents. Il faut donc :

  1. localiser Tomcat ;
  2. définir la variable tomcatDir.
On peut ensuite executer les commandes ci-dessous.


La journalisation de Tomcat

[modifier | modifier le wikicode]
tail -f $TOMCAT_HOME/logs/catalina.out

Supprimer les fichiers de journalisation de Tomcat

[modifier | modifier le wikicode]
sudo service tomcat6 stop
sudo rm "$tomcatDir"/logs/*
sudo service tomcat6 start


L'erreur suivante est indiquée dans les logs du fichier catalina.out:

INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/local/jdk1.6.0_45/jre/lib/i386/server:/usr/local/jdk1.6.0_45/jre/lib/i386:/usr/local/jdk1.6.0_45/jre/../lib/i386:/usr/java/packages/lib/i386:/lib:/usr/lib

Pré-requis :

  • les outils nécessaires pour compiler en C/C++;
  • un jdk 6 installé et la variable d'environnement JAVA_HOME configurée;
  • un tomcat 6 installé et la variable d'environnement CATALINA_HOME configurée;
  • éventuellement openssl.
apt-get update
apt-get install openssl gcc make

$JAVA_HOME/bin/java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) Server VM (build 20.45-b01, mixed mode)

echo $CATALINA_HOME
/usr/local/apache-tomcat-6.0.36
apt-get install libapr1-dev libssl-dev
cd $CATALINA_HOME/bin
wget http://apache.websitebeheerjd.nl//tomcat/tomcat-connectors/native/1.1.27/source/tomcat-native-1.1.27-src.tar.gz
cp tomcat-native-1.1.27-src.tar.gz /usr/local/src/libs-tomcat-6.0.36/
tar -xvzf tomcat-native-1.1.27-src.tar.gz
cd tomcat-native-1.1.27-src/jni/native/
./configure --with-apr=/usr/bin/apr-1-config --with-java-home=$JAVA_HOME --with-ssl=yes --prefix=$CATALINA_HOME
make && make install

/usr/bin/apr-1-config est le chemin par défaut du binaire APR. Ce chemin peut changer suivant la version de la librairie APR.

La fin de l'installation doit se terminer par les lignes suivantes :

----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/apache-tomcat-6.0.36/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Et enfin ajouter dans /etc/init.d/tomcat ou par exemple dans ~/.profile, la variable d'environnement LD_LIBRARY_PATH des librairies de Tomcat :

{{path|LD_LIBRARY_PATH=$CATALINA_HOME/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH}}

Dans le cas de l'utilisation du fichier ~/.profile, le shell courant prendra en charge la nouvelle configuration de ce fichier grace à la commande :

source ~/.profile

On vérifie la prise en charge de l'APR par Tomcat :

On redémarre Tomcat :

$CATALINA_HOME/bin/catalina.sh stop
$CATALINA_HOME/bin/catalina.sh start

Le fichier de log $CATALINA_HOME/logs/catalina.out doit contenir les lignes suivantes :

25 avr. 2013 14:43:59 org.apache.catalina.core.AprLifecycleListener init
INFO: Loaded APR based Apache Tomcat Native library 1.1.27 using APR version 1.4.2.
25 avr. 2013 14:43:59 org.apache.catalina.core.AprLifecycleListener init
INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
25 avr. 2013 14:43:59 org.apache.catalina.core.AprLifecycleListener initializeSSL
INFO: OpenSSL successfully initialized with version OpenSSL 0.9.8o 01 Jun 2010

Note : il est aussi possible d'installer la librairie APR manuellement.

cd /usr/local/src
wget http://wwwftp.ciril.fr/pub/apache//apr/apr-1.4.6.tar.gz
tar -xvzf apr-1.4.6.tar.gz
cd apr-1.4.6
./configure --prefix=/usr/local/apache-tomcat-6.0.36/lib/apr
make 
make test
make install


Pour Tomcat 6.0, la documentation de l'APR est sur http://tomcat.apache.org/tomcat-6.0-doc/apr.html#Installation et les sources sont disponibles sur http://apr.apache.org/download.cgi.

Pour plus de détails, voir http://quickfix.free.fr/?p=350.


Localiser Tomcat

[modifier | modifier le wikicode]

Voici la liste des emplacement où j'ai pu rencontrer (ou placer) Apache Tomcat :

  • /opt/
  • ~/apps/tomcat-*
  • ~/apps/apache-tomcat-*
  • /mnt/data/apps/tomcat-*
  • /mnt/data/apps/apache-tomcat-*



  1. FAQ / Memory @ Tomcat wiki

<references/>

Voir la version de tomcat

[modifier | modifier le wikicode]
java -cp /usr/share/tomcat6/lib/catalina.jar org.apache.catalina.util.ServerInfo