windows - Tomcat8 无法在 Windows 主机上的 VirtualBox Vagrant 中的 Ubuntu 16.04 中启动
问题描述
我对 vagrant 不是很熟悉,并且有一个 Ubuntu 16.04 的映像,其中包含一个可设置和运行 tomcat8 服务器应用程序的 ansible 脚本。我去windows主机上设置,tomcat服务每次都启动失败。
运行 ansible playbook 的结果是:
TASK [Restart tomcat] **********************************************************
fatal: [localhost]: FAILED! => {"changed": true, "cmd": "service tomcat8 restart", "delta": "0:00:00.046020", "end": "2019-02-02 17:55:28.417905", "failed": true, "rc": 1, "start": "2019-02-02 17:55:28.371885", "stderr": "Job for tomcat8.service failed because the control process exited with error code. See \"systemctl status tomcat8.service\" and \"journalctl -xe\" for details.", "stdout": "", "stdout_lines": [], "warnings": ["Consider using service module rather than running service"]}
尝试运行的结果sudo service tomcat8 restart
是:
Job for tomcat8.service failed because the control process exited with error code. See "systemctl status tomcat8.service" and "journalctl -xe" for details.
通过以下方式检查服务状态sudo service tomcat8 status
:
● tomcat8.service - LSB: Start Tomcat.
Loaded: loaded (/etc/init.d/tomcat8; bad; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2019-02-04 16:15:19 UTC; 46s ago
Docs: man:systemd-sysv-generator(8)
Process: 10703 ExecStop=/etc/init.d/tomcat8 stop (code=exited, status=0/SUCCESS)
Process: 11859 ExecStart=/etc/init.d/tomcat8 start (code=exited, status=127)
Feb 04 16:15:19 vagrant systemd[1]: Starting LSB: Start Tomcat....
Feb 04 16:15:19 vagrant tomcat8[11859]: [58B blob data]
Feb 04 16:15:19 vagrant systemd[1]: tomcat8.service: Control process exited, code=exited status=127
Feb 04 16:15:19 vagrant systemd[1]: Failed to start LSB: Start Tomcat..
Feb 04 16:15:19 vagrant systemd[1]: tomcat8.service: Unit entered failed state.
Feb 04 16:15:19 vagrant systemd[1]: tomcat8.service: Failed with result 'exit-code'.
我曾尝试使用 apt-get 重新安装 tomcat8,但 prerm 和 postinst 出现错误,因此我删除了所有 tomcat8.prerm、tomcat8.preinst、tomcat8.postinst 等文件,然后再次尝试,但没有成功。(老实说,不记得确切的结果 - 如果需要,我可以再试一次并更新这篇文章)
我还尝试在运行 ansible playbook 之前手动安装 tomcat8,同样的事情发生了。
我只是觉得我只是在冒险,并且不确定从哪里开始深入挖掘,因此非常感谢任何和所有想法。
更新:结果当它在 macOS 主机上运行时,不会发生此错误..
更新第 2 部分:我在剧本中找到了问题孩子:
- name: Configure tomcat memory
template:
src: /home/vagrant/shared/resources/tomcat8
dest: /etc/default/tomcat8
mode: 0640
force: True
如果我从剧本中删除它,则不会发生此错误。我不认为它与tomcat8文件的内容有关,因为我尝试基本上将所有行注释掉以恢复默认值,但仍然有问题。我猜这可能与权限有关?尽管如此,这是它正在复制的文件中的内容:
# Run Tomcat as this user ID. Not setting this or leaving it blank will use the
# default of tomcat8.
TOMCAT8_USER=tomcat8
# Run Tomcat as this group ID. Not setting this or leaving it blank will use
# the default of tomcat8.
TOMCAT8_GROUP=tomcat8
# The home directory of the Java development kit (JDK). You need at least
# JDK version 7. If JAVA_HOME is not set, some common directories for
# OpenJDK and the Oracle JDK are tried.
#JAVA_HOME=/usr/lib/jvm/java-7-openjdk
# You may pass JVM startup parameters to Java here. If unset, the default
# options will be: -Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC
#
# Use "-XX:+UseConcMarkSweepGC" to enable the CMS garbage collector (improved
# response time). If you use that option and you run Tomcat on a machine with
# exactly one CPU chip that contains one or two cores, you should also add
# the "-XX:+CMSIncrementalMode" option.
#JAVA_OPTS="-Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC" # original setting
JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom -Djava.awt.headless=true -Xmx1024m -XX:MaxPermSize=512m -XX:+UseConcMarkSweepGC -Dapp.profile=vm"
# To enable remote debugging uncomment the following line.
# You will then be able to use a java debugger on port 8000.
JAVA_OPTS="${JAVA_OPTS} -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"
# Java compiler to use for translating JavaServer Pages (JSPs). You can use all
# compilers that are accepted by Ant's build.compiler property.
#JSP_COMPILER=javac
# Use the Java security manager? (yes/no, default: no)
#TOMCAT8_SECURITY=no
# Number of days to keep logfiles in /var/log/tomcat8. Default is 14 days.
#LOGFILE_DAYS=14
# Whether to compress logfiles older than today's
#LOGFILE_COMPRESS=1
# Location of the JVM temporary directory
# WARNING: This directory will be destroyed and recreated at every startup !
#JVM_TMP=/tmp/tomcat8-temp
# If you run Tomcat on port numbers that are all higher than 1023, then you
# do not need authbind. It is used for binding Tomcat to lower port numbers.
# (yes/no, default: no)
#AUTHBIND=no
#GEOSERVER_DATA_DIR=/efs/geoserver_data
解决方案
问题很可能是 systemd 模块内的错误 JAVA_HOME 路径。检查 /etc/systemd/system/tomcat.service 中的 JAVA_HOME 路径,它的末尾不应有“jre/”,这对于较新的 Java 版本是错误的。尝试:
sudo nano /etc/systemd/system/tomcat.service
并删除 JAVA_HOME 路径的尾随“jre/”。然后重启tomcat
sudo systemctl daemon-reload
sudo systemctl restart tomcat
推荐阅读
- sql - Redshift 无法插入,时间戳列是字符串类型
- javascript - 如何将图像从一个用户发送到服务器,然后使用 node js 和 socket.io 将其显示回聊天室中的所有客户端?
- c++ - 交换 std::vector 中两个元素的索引
- google-chrome - 如何在没有时间戳的情况下将网页打印为pdf?
- java - Java FX Stage 类中的 showandwait() 和 show() 有什么区别?
- python - 为什么我不能在 python repl.it 中使用 PyNaCl 库
- spring-boot - 分别在每个 maven 模块的 ApplicationContext 中运行的中央 SpringBootTest
- django - 如何在我的 django forloop 中使用 if 和 else
- git - 如何删除以前的 git 提交?
- python - 变量 __cached__ 是做什么用的?