[英]Tomcat 8 on CentOS 7 does not start as service (but it starts manually ....)
I've installed Tomcat (apache-tomcat-8.5.37), on a CentOS VM (using bento/centos-7).我已经在 CentOS 虚拟机(使用 Bento/centos-7)上安装了 Tomcat (apache-tomcat-8.5.37)。
Tomcat is installed in Tomcat安装在
/opt/tomcat/apache-tomcat-8.5.37
and Java 8 is installed in并且 Java 8 安装在
/usr/java/jre1.8.0_192-amd64
Before to install Tomcat I've created a tomcat
user in this way在安装Tomcat之前我以这种方式创建了一个
tomcat
用户
sudo useradd tomcat
sudo passwd tomcat
sudo mkdir /opt/tomcat
sudo chown -R tomcat:tomcat /opt/tomcat
su – tomcat
If I try to start Tomcat manually using如果我尝试使用手动启动Tomcat
/opt/tomcat/apache-tomcat-8.5.37/bin/startup.sh
all works fine and I can test Tomcat ad its examples from the url一切正常,我可以从 url 测试 Tomcat 广告它的示例
http://192.168.33.10:8080
(note: 192.168.33.10 is the IP of my virtual machine ...) (注:192.168.33.10是我虚拟机的IP...)
I can also shutdown Tomcat using我也可以使用关闭Tomcat
/opt/tomcat/apache-tomcat-8.5.37/bin/shutdown.sh
I'd like to start Tomcat like e service so I've stopped Tomcat and then I've edited a file我想像 e 服务一样启动 Tomcat,所以我停止了 Tomcat,然后我编辑了一个文件
/etc/systemd/system/tomcat.service
with this content有了这个内容
[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
Then然后
sudo systemctl daemon-reload
and和
sudo systemctl start tomcat
Tomcat does not responding now invoking the url Tomcat 现在没有响应调用 url
http://192.168.33.10:8080
and the output of和输出
sudo systemctl status tomcat
is the follow是跟随
● 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.
The output of的输出
journalctl -xe
is the follow是跟随
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
The output of catalina.out is the follow catalina.out 的输出如下
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"]
???? ???
Suggestions are appreciated!!建议表示赞赏!!
NOTE : As of OCT 2019
注意:截至 2019 年 10 月
kill -9
and then start the tomcat service using systemctl
as mentioned below, it works like charm.kill -9
然后使用systemctl
启动 tomcat 服务,如下所述,它也像魅力一样工作。 I am using Ubuntu 16.04, tomcat 8.5.37, Java 1.8.0_222我使用的是Ubuntu 16.04、tomcat 8.5.37、Java 1.8.0_222
I used below systemd script, kept it at location: /etc/systemd/system/
我使用了下面的systemd脚本,将其保存在以下位置:
/etc/systemd/system/
# 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
and ran below command sequentially并按顺序运行以下命令
systemctl daemon-reload
systemctl start tomcat
systemctl status tomcat
Below is output for status of tomcat service.下面是 tomcat 服务状态的输出。
● 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.
IMPORTANT :
WorkingDirectory
,ExecStart
,ExecStop
must be taken care with, their values are crucial.重要提示:
WorkingDirectory
、ExecStart
、ExecStop
必须小心,它们的值至关重要。
A common problem, when you start tomcat once manually (using your own user account), the temporary files, logs etc. are owned by you, not by the daemon user (tomcat, according to the quoted tomcat.service file. Subsequent starts with the daemon user can't overwrite those files due to missing permissions - this might also prevent proper logging of those problems.一个常见的问题,当你手动启动一次tomcat(使用你自己的用户账号)时,临时文件、日志等都是你所有的,而不是守护进程用户的(tomcat,根据引用的tomcat.service文件。后续以由于缺少权限,守护程序用户无法覆盖这些文件 - 这也可能会阻止正确记录这些问题。
Fix those permissions (or rather: file ownerships) and try again.修复这些权限(或者更确切地说:文件所有权)并重试。 My daemon start scripts typically have a
chown
for the relevant files, just to make sure that I'm not running into those problems in case someone has manually started using a wrong user account.我的守护进程启动脚本通常有相关文件的
chown
,只是为了确保我不会遇到这些问题,以防有人手动启动使用错误的用户帐户。
delete pid file as said in your error message删除错误消息中所述的pid文件
Existing PID file found during start.启动期间找到现有的 PID 文件。
/opt/tomcat/apache-tomcat-8.5.37/temp/tomcat.pid /opt/tomcat/apache-tomcat-8.5.37/temp/tomcat.pid
I've solved changing this line我已经解决了改变这条线
ExecStop=/bin/kill -15 $MAINPID
in在
ExecStop=sudo /bin/kill -15 $MAINPID
in my /etc/systemd/system/tomcat.service
file.在我的
/etc/systemd/system/tomcat.service
文件中。
Its new content is now它的新内容现在是
[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
Now tomcat service start with现在tomcat服务以
sudo systemctl start tomcat
and the output of和输出
sudo systemctl status tomcat
is是
[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)
Some time it would be your java heap memory exceed as your current server memory.有时您的 Java 堆内存会超过您当前的服务器内存。 You can set it in your setenv.sh file in tomcat8 and then restart the server.
您可以在 tomcat8 的 setenv.sh 文件中设置它,然后重新启动服务器。
I have face same kind of issue when I have downgrade the system configuration after that tomcat could't be restart so I have just adjust the heap memory in tomcat/bin/setenv.sh file and /etc/systemd/system/tomcat.service file according to system configuration then I have restart the tomcat.在无法重新启动 tomcat 之后降级系统配置时,我遇到了同样的问题,所以我刚刚调整了 tomcat/bin/setenv.sh 文件和 /etc/systemd/system/tomcat.service 中的堆内存根据系统配置文件然后我重新启动了tomcat。 Now it's working fine.
现在它工作正常。
at an old CentOS 6.10 the solution was changing /etc/init.d/tomcat8在旧的 CentOS 6.10 中,解决方案正在改变 /etc/init.d/tomcat8
to use runuser instead of su or sudo so changing使用 runuser 而不是 su 或 sudo 所以改变
/bin/su $TOMCAT_USER -c $CATALINA_HOME/bin/startup.sh
to到
/sbin/runuser -s /bin/sh $TOMCAT_USER $CATALINA_HOME/bin/startup.sh
maybe you can try this:也许你可以试试这个:
[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
it is crucial to specify apr/lib
指定
apr/lib
至关重要
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.