初始安装后,tomcat 8将无法启动


18

我正在尝试在新的CentOS 7虚拟机上安装tomcat。我成功安装了apache httpd,并且在网络中另一台计算机上的网络浏览器中键入虚拟机的ip时能够获得apache测试页。但是当我键入时,我收到以下错误消息systemctl start tomcat

Job for tomcat.service failed. See 'systemctl status tomcat.service' and 'journalctl -xn' for details.  

这是安装Java和tomcat的命令的完整历史记录:

我首先使用本教程中的指令安装Java 因为tomcat指令(下面的第二个块)希望我使用openjdk,并且我需要使用真正的Java:

//Install Java
# cd /opt/
# yum install wget
# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u60-b27/jdk-8u60-linux-x64.tar.gz"

# tar xzf jdk-8u60-linux-x64.tar.gz

# cd /opt/jdk1.8.0_60/
# alternatives --install /usr/bin/java java /opt/jdk1.8.0_60/bin/java 2
# alternatives --config java
(Select the version you want)
# alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_60/bin/jar 2
# alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_60/bin/javac 2
# alternatives --set jar /opt/jdk1.8.0_60/bin/jar
# alternatives --set javac /opt/jdk1.8.0_60/bin/javac
# java -version (checks to see you install correct version)
# export JAVA_HOME=/opt/jdk1.8.0_60
# export JRE_HOME=/opt/jdk1.8.0_60/jre
# export PATH=$PATH:/opt/jdk1.8.0_60/bin:/opt/jdk1.8.0_60/jre/bin

请注意,前面的教程没有解释如何将环境变量放入中/etc/environment,因此我在该命令之前停了下来。

以下命令来自该其他教程。我从安装Java之后开始:

//Install Tomcat
Login as sudo user, not root.
# sudo groupadd tomcat
# sudo useradd -M -s /bin/nologin -g tomcat -d /opt/tomcat tomcat
# cd ~
# wget http://mirrors.gigenet.com/apache/tomcat/tomcat-8/v8.0.27/bin/apache-tomcat-8.0.27.tar.gz
# sudo mkdir /opt/tomcat
# sudo tar xvf apache-tomcat-8*tar.gz -C /opt/tomcat --strip-components=1
# cd /opt/tomcat
# sudo chgrp -R tomcat conf
# sudo chmod g+rwx conf
# sudo chmod g+r conf/*
# sudo chown -R tomcat work/ temp/ logs/
# sudo vi /etc/systemd/system/tomcat.service
Cut and paste the following file contents:
##################################################
# Systemd unit file for tomcat
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/lib/jvm/jre
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

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

User=tomcat
Group=tomcat

[Install]
WantedBy=multi-user.target
##################################################
# sudo systemctl daemon-reload

# sudo systemctl start tomcat
Job for tomcat.service failed. See 'systemctl status tomcat.service' and 'journalctl -xn' for details.
# sudo systemctl start tomcat.service

tomcat.service的作业失败。有关详细信息,请参见“ systemctl状态tomcat.service”和“ journalctl -xn”。#sudo systemctl启用tomcat.service ln -s'/etc/systemd/system/tomcat.service''/etc/systemd/system/multi-user.target.wants/tomcat.service'#sudo systemctl启用tomcat

# sudo systemctl status tomcat.service
tomcat.service - Apache Tomcat Web Application Container
   Loaded: loaded (/etc/systemd/system/tomcat.service; enabled)
   Active: failed (Result: exit-code) since Tue 2015-10-13 11:05:31 PDT; 47s ago

Oct 13 11:05:31 localhost.localdomain kill[20887]: -q, --queue <sig>      use sigqueue(2) rather than kill(2)
Oct 13 11:05:31 localhost.localdomain kill[20887]: -p, --pid              print pids without signaling them
Oct 13 11:05:31 localhost.localdomain kill[20887]: -l, --list [=<signal>] list signal names, or convert one to a name
Oct 13 11:05:31 localhost.localdomain kill[20887]: -L, --table            list signal names and numbers
Oct 13 11:05:31 localhost.localdomain kill[20887]: -h, --help     display this help and exit
Oct 13 11:05:31 localhost.localdomain kill[20887]: -V, --version  output version information and exit
Oct 13 11:05:31 localhost.localdomain kill[20887]: For more details see kill(1).
Oct 13 11:05:31 localhost.localdomain systemd[1]: tomcat.service: control process exited, code=exited status=1
Oct 13 11:05:31 localhost.localdomain systemd[1]: Failed to start Apache Tomcat Web Application Container.
Oct 13 11:05:31 localhost.localdomain systemd[1]: Unit tomcat.service entered failed state.

yum localinstall本其他帖子所述,执行更新的jdk rpm的操作无效。


编辑:


按照@Bram的建议,我将配置文件更改为以下内容,但仍收到相同的错误:

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

[Service]
Type=forking

Environment=JAVA_HOME=/opt/jdk1.8.0_60
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

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

User=tomcat
Group=tomcat

[Install]
WantedBy=multi-user.target

另外,根据@JeffSchaller在聊天中的评论,我能够使tomcat从本地启动,如下所示:

[user@localhost tomcat]$ sudo /opt/tomcat/bin/startup.sh
Using CATALINA_BASE: /opt/tomcat
Using CATALINA_HOME: /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME: /
Using CLASSPATH: /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
Tomcat started.
[user@localhost tomcat]$

因此,此OP中的问题似乎与systemd配置有关。我该如何解决?


tomcat日志文件中有任何错误?如果我没记错的话,该文件称为catalina.out或类似的名称。
Bram

后面的Tomcat日志sudo systemctl start tomcat.service是一堆需要数百行的权限被拒绝的错误。
CodeMed

Answers:


16

我有同样的问题,通过以下方法解决了:

  1. 赋予tomcat用户整个tomcat目录的所有权:

    cd /opt && sudo chown -R tomcat tomcat/
    
  2. 并在/etc/systemd/system/tomcat.service中的下面注释掉:

    Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
    

1
让tomcat成为整个文件夹的所有者安全吗?我以为我们想尽可能地限制访问?
user3203425 '16

我现在没有要测试的安装程序,但是我认为问题出在:“ sudo chown -R tomcat work / temp / logs /”。我想说它至少也需要“ bin /”的所有权。
user2968675 '16

看来第1步对我来说确实做到了。第2步中的代码行是做什么的?
金佰利W

没错,步骤1足以解决此特定问题。步骤2设置Java堆大小和垃圾回收类型。由于我的环境特性,我需要它,但大多数人可能不需要。
user2968675 '16

就我而言,仅适用cd /opt && sudo chown -R tomcat tomcat/。因为我将所有者更改为系统用户,却忘记了使tomcat成为所有者,所以
imdzeeshan

2

由于Java是在非Defalt位置安装的,因此需要告诉tomcat在哪里找到它。

在发布的单元文件中,JAVA_HOME设置为/ usr / lib / jvm / jre,但在有关Java安装的部分中,JAVA_HOME为/opt/jdk1.8.0_60。

如果您在tomcat systemd单元文件中设置JAVA_HOME,我相信它将起作用。

此外,单位文件还指定了用户tomcat。但是,当您手动启动它时,您将以root身份启动它。问题可能是tomcat尝试打开特权端口。启动脚本是否以root身份启动tomcat?还是以tomcat用户身份启动进程?从单元文件中删除用户和组应触发与命令行尝试相同的行为。


如何解决以下错误:tomcat8.service的作业失败,因为控制进程退出并显示错误代码。有关详细信息,请参见“ systemctl状态tomcat8.service”和“ journalctl -xe”。invoke-rc.d:初始化脚本tomcat8,操作“启动”失败。-> sudo nano / etc / default / tomcat8->设置JAVA_HOME JAVA_HOME = / usr / lib / jvm / java-8- oracle-
合并

1

根据错误消息,我认为问题出ExecStop=/bin/kill -15 $MAINPID在没有替换变量的地方。根据服务文档$MAINPID,只能用于ExecReload命令。问题仍然存在:为什么ExecStop在触发时跑了start

这是可能systemd的叶子JVM进程的工作目录/可能是不相关的部署应用程序。

我建议你移动CATALINA_OPTSJAVA_OPTS/opt/tomcat/bin/setenv.sh剧本,这样一个简单的配置第一次尝试:

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

[Service]
Type=forking

Environment=JAVA_HOME=/usr/java/default
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat

WorkingDirectory=/opt/tomcat

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh

User=tomcat
Group=tomcat

[Install]
WantedBy=multi-user.target

在任何情况下,请报告journalctl -xnlogs/catalina.out内容

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.