初始安裝後tomcat 8將無法啟動
我正在嘗試在新的 CentOS 7 虛擬機上安裝 tomcat。我成功安裝了 apache httpd,當我將虛擬機的 ip 輸入到網路中另一台電腦上的 Web 瀏覽器中時,我能夠獲得 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 status tomcat.service”和“journalctl -xn”。# sudo systemctl enable tomcat.service ln -s ‘/etc/systemd/system/tomcat.service’ ‘/etc/systemd/system/multi-user.target.wants/tomcat.service’ # sudo systemctl enable 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
目錄的tomcat使用者所有權:cd /opt && sudo chown -R tomcat tomcat/
- 並在 /etc/systemd/system/tomcat.service 中註釋掉以下行:
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
由於您將 Java 安裝在非預設位置,因此您需要告訴 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 身份啟動程序?從單元文件中刪除使用者和組應該會觸發與命令行嘗試相同的行為。