2
votes

Tomcat 8 sur CentOS 7 ne démarre pas en tant que service (mais il démarre manuellement ....)

J'ai installé Tomcat (apache-tomcat-8.5.37), sur une VM CentOS (en utilisant bento / centos-7).

Tomcat est installé dans

01-Jan-2019 09:09:21.585 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
01-Jan-2019 09:09:21.602 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
01-Jan-2019 09:09:21.614 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 2829 ms
01-Jan-2019 09:09:21.697 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
01-Jan-2019 09:09:21.697 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.37
01-Jan-2019 09:09:21.738 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/opt/tomcat/apache-tomcat-8.5.37/webapps/ROOT]
01-Jan-2019 09:09:22.777 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/opt/tomcat/apache-tomcat-8.5.37/webapps/ROOT] has finished in [1,038] ms
01-Jan-2019 09:09:22.795 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/opt/tomcat/apache-tomcat-8.5.37/webapps/docs]
01-Jan-2019 09:09:22.847 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/opt/tomcat/apache-tomcat-8.5.37/webapps/docs] has finished in [70] ms
01-Jan-2019 09:09:22.847 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/opt/tomcat/apache-tomcat-8.5.37/webapps/examples]
01-Jan-2019 09:09:23.468 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/opt/tomcat/apache-tomcat-8.5.37/webapps/examples] has finished in [621] ms
01-Jan-2019 09:09:23.469 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/opt/tomcat/apache-tomcat-8.5.37/webapps/host-manager]
01-Jan-2019 09:09:23.522 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/opt/tomcat/apache-tomcat-8.5.37/webapps/host-manager] has finished in [54] ms
01-Jan-2019 09:09:23.522 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/opt/tomcat/apache-tomcat-8.5.37/webapps/manager]
01-Jan-2019 09:09:23.569 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/opt/tomcat/apache-tomcat-8.5.37/webapps/manager] has finished in [47] ms
01-Jan-2019 09:09:23.592 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
01-Jan-2019 09:09:23.601 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
01-Jan-2019 09:09:23.604 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 1990 ms
01-Jan-2019 09:12:38.830 INFO [main] org.apache.catalina.core.StandardServer.await A valid shutdown command was received via the shutdown port. Stopping the Server instance.
01-Jan-2019 09:12:38.831 INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["http-nio-8080"]
01-Jan-2019 09:12:38.870 INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["ajp-nio-8009"]
01-Jan-2019 09:12:38.878 INFO [main] org.apache.catalina.core.StandardService.stopInternal Stopping service [Catalina]
01-Jan-2019 09:12:39.117 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-nio-8080"]
01-Jan-2019 09:12:39.123 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["ajp-nio-8009"]
01-Jan-2019 09:12:39.131 INFO [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["http-nio-8080"]
01-Jan-2019 09:12:39.137 INFO [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["ajp-nio-8009"]

et Java 8 est installé dans

Jan 01 09:34:46 localhost.localdomain sudo[14418]:   tomcat : TTY=pts/0 ; PWD=/opt/tomcat/apache-tomcat-8.5.37/temp ; USER=root ; COMMAND=/bin/systemctl start tomcat
Jan 01 09:34:46 localhost.localdomain polkitd[635]: Registered Authentication Agent for unix-process:14419:1135902 (system bus name :1.85 [/usr/bin/pkttyagent --notify-fd 5 --fallb
Jan 01 09:34:46 localhost.localdomain systemd[1]: Starting Apache Tomcat Web Application Container...
-- Subject: Unit tomcat.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit tomcat.service has begun starting up.
Jan 01 09:34:46 localhost.localdomain startup.sh[14425]: Existing PID file found during start.
Jan 01 09:34:46 localhost.localdomain startup.sh[14425]: Removing/clearing stale PID file.
Jan 01 09:34:46 localhost.localdomain startup.sh[14425]: Tomcat started.
Jan 01 09:34:46 localhost.localdomain polkitd[635]: Unregistered Authentication Agent for unix-process:14419:1135902 (system bus name :1.85, object path /org/freedesktop/PolicyKit1
Jan 01 09:34:46 localhost.localdomain systemd[1]: Started Apache Tomcat Web Application Container.
-- Subject: Unit tomcat.service has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit tomcat.service has finished starting up.
--
-- The start-up result is done.
Jan 01 09:34:46 localhost.localdomain kill[14438]: Usage:
Jan 01 09:34:46 localhost.localdomain kill[14438]: kill [options] <pid|name> [...]
Jan 01 09:34:46 localhost.localdomain kill[14438]: Options:
Jan 01 09:34:46 localhost.localdomain kill[14438]: -a, --all              do not restrict the name-to-pid conversion to processes
Jan 01 09:34:46 localhost.localdomain kill[14438]: with the same uid as the present process
Jan 01 09:34:46 localhost.localdomain kill[14438]: -s, --signal <sig>     send specified signal
Jan 01 09:34:46 localhost.localdomain kill[14438]: -q, --queue <sig>      use sigqueue(2) rather than kill(2)
Jan 01 09:34:46 localhost.localdomain kill[14438]: -p, --pid              print pids without signaling them
Jan 01 09:34:46 localhost.localdomain kill[14438]: -l, --list [=<signal>] list signal names, or convert one to a name
Jan 01 09:34:46 localhost.localdomain kill[14438]: -L, --table            list signal names and numbers
Jan 01 09:34:46 localhost.localdomain kill[14438]: -h, --help     display this help and exit
Jan 01 09:34:46 localhost.localdomain kill[14438]: -V, --version  output version information and exit
Jan 01 09:34:46 localhost.localdomain kill[14438]: For more details see kill(1).
Jan 01 09:34:46 localhost.localdomain systemd[1]: tomcat.service: control process exited, code=exited status=1
Jan 01 09:34:46 localhost.localdomain systemd[1]: Unit tomcat.service entered failed state.
Jan 01 09:34:46 localhost.localdomain systemd[1]: tomcat.service failed.
Jan 01 09:34:59 localhost.localdomain sudo[14451]:   tomcat : TTY=pts/0 ; PWD=/opt/tomcat/apache-tomcat-8.5.37/temp ; USER=root ; COMMAND=/bin/systemctl status tomcat
Jan 01 09:48:45 localhost.localdomain sudo[15115]:   tomcat : TTY=pts/0 ; PWD=/opt/tomcat/apache-tomcat-8.5.37/bin ; USER=root ; COMMAND=/bin/systemctl status tomcat

Avant d'installer Tomcat, j'ai créé un utilisateur tomcat de cette manière

XXX

Si j'essaie de démarrer Tomcat manuellement en utilisant

journalctl -xe

tout fonctionne bien et je peux tester Tomcat et ses exemples à partir de l'url p >

● tomcat.service - Apache Tomcat Web Application Container
   Loaded: loaded (/etc/systemd/system/tomcat.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2019-01-01 09:34:46 UTC; 13min ago
  Process: 14438 ExecStop=/bin/kill -15 $MAINPID (code=exited, status=1/FAILURE)
  Process: 14425 ExecStart=/opt/tomcat/apache-tomcat-8.5.37/bin/startup.sh (code=exited, status=0/SUCCESS)
 Main PID: 14436 (code=exited, status=0/SUCCESS)

Jan 01 09:34:46 localhost.localdomain systemd[1]: Starting Apache Tomcat Web Application Container...
Jan 01 09:34:46 localhost.localdomain startup.sh[14425]: Existing PID file found during start.
Jan 01 09:34:46 localhost.localdomain startup.sh[14425]: Removing/clearing stale PID file.
Jan 01 09:34:46 localhost.localdomain systemd[1]: Started Apache Tomcat Web Application Container.
Jan 01 09:34:46 localhost.localdomain systemd[1]: tomcat.service: control process exited, code=exited status=1
Jan 01 09:34:46 localhost.localdomain systemd[1]: Unit tomcat.service entered failed state.
Jan 01 09:34:46 localhost.localdomain systemd[1]: tomcat.service failed.

(note: 192.168.33.10 est l'adresse IP de ma machine virtuelle ...)

Je peux aussi arrêter Tomcat en utilisant

sudo systemctl status tomcat

J'aimerais démarrer Tomcat comme un service e donc j'ai arrêté Tomcat et ensuite j'ai édité un fichier

http://192.168.33.10:8080

avec ce contenu

sudo systemctl start tomcat

Puis

sudo systemctl daemon-reload

et

[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/java/jre1.8.0_192-amd64
Environment=CATALINA_PID=/opt/tomcat/apache-tomcat-8.5.37/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat/apache-tomcat-8.5.37/
Environment=CATALINA_BASE=/opt/tomcat/apache-tomcat-8.5.37/
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

ExecStart=/opt/tomcat/apache-tomcat-8.5.37/bin/startup.sh
ExecStop=/bin/kill -15 $MAINPID

User=tomcat
Group=tomcat
UMask=0007

[Install]
WantedBy=multi-user.target

Tomcat ne répond pas maintenant en appelant l'url

/etc/systemd/system/tomcat.service

et la sortie de

/opt/tomcat/apache-tomcat-8.5.37/bin/shutdown.sh

est la suivante

http://192.168.33.10:8080

????

Les suggestions sont appréciées !!


4 commentaires

Quel est le contenu des fichiers journaux de tomcat?


J'ai mis dans la question originale le contenu de catalina.out .... merci!


Les heures de vos différents fichiers journaux ne correspondent pas - je ne pense pas que le contenu de catalina.out provienne du début du système à partir duquel vous avez publié les fichiers journaux.


Veuillez regarder ma réponse. Cela fonctionne comme du charme. Acceptez la réponse pour aider la communauté à obtenir une meilleure réponse.


8 Réponses :


0
votes

Un problème courant, lorsque vous démarrez tomcat une fois manuellement (en utilisant votre propre compte utilisateur), les fichiers temporaires, les journaux, etc. vous appartiennent, et non l'utilisateur du démon (tomcat, selon le fichier tomcat.service cité. Les démarrages suivants avec l'utilisateur du démon ne peuvent pas écraser ces fichiers en raison d'autorisations manquantes - cela peut également empêcher une journalisation appropriée de ces problèmes.

Corrigez ces autorisations (ou plutôt: la propriété des fichiers) et réessayez. Mes scripts de démarrage de démon ont généralement un chown pour les fichiers concernés, juste pour m'assurer que je ne rencontre pas ces problèmes au cas où quelqu'un aurait manuellement commencé à utiliser un mauvais compte d'utilisateur.


3 commentaires

J'ai ajouté quelques détails dans ma question initiale sur l'utilisateur tomcat que j'ai créé et utilisé pour installer Tomcat. Vérifier sur ma VM CentOS 7 tous les répertoires Tomcat (donc, bin, longs, temp, ecc ..), appartiennent à cet utilisateur et à ce groupe tomcat . Est-ce juste ou je dois changer quelque chose quelque part et où? Merci!


Les fichiers binaires et les répertoires n'ont pas besoin d'appartenir à l'utilisateur tomcat - en fait, si vous obtenez des vulnérabilités d'accès aux fichiers à distance avec l'une de vos applications, il est préférable que cet utilisateur ne puisse pas écraser ces fichiers binaires - mais pour le temp , le travail et les fichiers journaux c'est essentiel.


Ok ... j'ai suivi ces instructions. linuxize.com/post/how-to-install-tomcat-8-5-on-centos-7 ...



0
votes

supprimez le fichier pid comme indiqué dans votre message d'erreur

Fichier PID existant trouvé au démarrage.

/opt/tomcat/apache-tomcat-8.5.37/temp/tomcat.pid


0 commentaires

0
votes

J'ai résolu de changer cette ligne

[vagrant@localhost system]$ sudo systemctl status tomcat
● tomcat.service - Apache Tomcat Web Application Container
   Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: disabled)
   Active: activating (auto-restart) since Tue 2019-01-08 20:28:25 UTC; 1s ago
  Process: 14447 ExecStart=/opt/tomcat/apache-tomcat-8.5.37/bin/startup.sh (code=exited, status=0/SUCCESS)
 Main PID: 14458 (code=exited, status=0/SUCCESS)

dans

sudo systemctl status tomcat

dans mon / etc / systemd / system / tomcat Fichier .service .

Son nouveau contenu est maintenant

sudo systemctl start tomcat

Le service tomcat commence maintenant par

[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/java/jre1.8.0_192-amd64
Environment=CATALINA_PID=/opt/tomcat/apache-tomcat-8.5.37/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat/apache-tomcat-8.5.37/
Environment=CATALINA_BASE=/opt/tomcat/apache-tomcat-8.5.37/
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

ExecStart=/opt/tomcat/apache-tomcat-8.5.37/bin/startup.sh
ExecStop=sudo /bin/kill -15 $MAINPID

User=tomcat
Group=tomcat
UMask=0007

[Install]
WantedBy=multi-user.target

et la sortie sur

ExecStop=sudo /bin/kill -15 $MAINPID

est

ExecStop=/bin/kill -15 $MAINPID


0 commentaires

2
votes

J'ai trouvé des rapports de bogues associés:

Bogue 63063

Bogue 63041

Ce bogue sera corrigé dans la prochaine version.


2 commentaires

Bien que ce ne soit pas une "solution" en soi, c'est l'explication de nombreuses questions SO liées à cela. Merci pour les indices, car j'ai perdu de nombreuses heures à essayer de déboguer ce problème.


Ce problème n'est pas résolu comme on dit. Après avoir appliqué cette solution, le service Tomcat semble démarré, mais il a été bloqué en interne. Le problème existe toujours dans 9.x également.



0
votes

À un moment donné, la mémoire de votre tas java serait supérieure à la mémoire actuelle de votre serveur. Vous pouvez le définir dans votre fichier setenv.sh dans tomcat8, puis redémarrer le serveur.

J'ai le même type de problème lorsque je rétrograde la configuration du système après que tomcat ne puisse pas être redémarré, je viens donc d'ajuster la mémoire du tas dans le fichier tomcat / bin / setenv.sh et / etc / systemd / system / fichier tomcat.service selon la configuration du système, puis j'ai redémarré le tomcat. Maintenant ça marche bien.


0 commentaires

0
votes

dans un ancien CentOS 6.10, la solution changeait /etc/init.d/tomcat8

pour utiliser runuser au lieu de su ou sudo, donc en changeant

/sbin/runuser -s /bin/sh $TOMCAT_USER $CATALINA_HOME/bin/startup.sh

en

/bin/su $TOMCAT_USER -c $CATALINA_HOME/bin/startup.sh


0 commentaires

3
votes

REMARQUE : à partir d'octobre 2019

  1. J'ai suivi le BUG https://bz.apache.org/bugzilla /show_bug.cgi?id=63063 , cela n'a toujours pas résolu le problème.
  2. J'ai fait peu d'essais et d'erreurs et j'ai résolu le problème. Cela fonctionne bien et fonctionne parfaitement selon les normes. Même si vous tuez le service tomcat gracieusement ou en utilisant kill -9 , puis démarrez le service tomcat en utilisant systemctl comme mentionné ci-dessous, cela fonctionne comme un charme.

J'utilise Ubuntu 16.04, tomcat 8.5.37, Java 1.8.0_222

J'ai utilisé ci-dessous le script systemd , conservé il à l'emplacement: /etc/systemd/system/

● tomcat.service - Apache Tomcat Web Application Container for ShopWorx
   Loaded: loaded (/etc/systemd/system/tomcat.service; disabled; vendor preset: enabled)
   Active: active (running) since Wed 2019-10-09 14:52:08 IST; 1min 46s ago
  Process: 3713 ExecStart=/bin/bash /usr/local/tomcat/bin/catalina.sh start (code=exited, status=0/SUCCESS)
 Main PID: 3720 (bash)
   CGroup: /system.slice/tomcat.service
           ├─3720 /bin/bash /usr/local/tomcat/bin/catalina.sh start
           └─3722 /usr/lib/jvm/java-8-openjdk-amd64/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.

Oct 09 14:52:08 ubuntu systemd[1]: Starting Apache Tomcat Web Application Container ...
Oct 09 14:52:08 ubuntu bash[3713]: Tomcat started.
Oct 09 14:52:08 ubuntu systemd[1]: Started Apache Tomcat Web Application Container.

et a exécuté la commande ci-dessous séquentiellement

systemctl daemon-reload

systemctl start tomcat

systemctl status tomcat

Voici la sortie pour l'état du service tomcat.

# Systemd unit file for tomcat
[Unit]
Description=Apache Tomcat Web Application Container for ShopWorx
After=syslog.target network.target

[Service]
Type=forking
WorkingDirectory=/usr/local/tomcat/bin

ExecStart=/bin/bash /usr/local/tomcat/bin/catalina.sh start
ExecStop=/bin/bash /usr/local/tomcat/bin/catalina.sh stop

User=emgda
Group=emgda

[Install]
WantedBy=multi-user.target

IMPORTANT : WorkingDirectory , ExecStart , ExecStop doivent être pris en compte, leurs valeurs sont cruciales.

/ p>


1 commentaires

Je vous remercie. Je crois que le WorkingDirectory était la seule partie qui me manquait. J'utilise RedHat 7.6 et j'ai enfin un service Tomcat 9 systemd fonctionnel!



0
votes

peut-être que vous pouvez essayer ceci:

[Unit]
Description=Tomcat
After=network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/local/jdk1.8.0_251
Environment=LD_LIBRARY_PATH=/usr/local/apr/lib
Environment=LD_RUN_PATH=/usr/local/apr/lib
PIDFile=/usr/local/apache-tomcat-9.0.36/bin/tomcat_8080.pid
ExecStart=/usr/local/apache-tomcat-9.0.36/bin/startup.sh
ExecReload=/usr/local/apache-tomcat-9.0.36/bin/catalina.sh restart
ExecStop=/usr/local/apache-tomcat-9.0.36/bin/shutdown.sh
PrivateTmp=true

User=root
Group=root

[Install]
WantedBy=multi-user.target

il est crucial de spécifier apr/lib


0 commentaires