Ubuntu16.04下Tomcat8启动失败:tomcat.service状态码203求助
Hey there, that exit code 203 for Tomcat usually points to two common culprits: incorrect Java 8 environment configuration or permission issues with Tomcat's files and directories. Let's work through this step by step to get your server up and running.
Step 1: Verify Java 8 Installation & Environment Variables
Tomcat 8 relies on Java 8, so first make sure it's properly set up:
- Check if Java 8 is installed:
You should see output likejava -versionopenjdk version "1.8.0_XXX"or Oracle Java 8. If not, install OpenJDK 8 with:sudo apt-get update && sudo apt-get install openjdk-8-jdk - Set the
JAVA_HOMEenvironment variable:
Edit the system environment file:
Add this line (adjust the path if you installed Oracle Java instead):sudo nano /etc/environment
Save and exit, then apply the changes:JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"
Verify it's set correctly:source /etc/environmentecho $JAVA_HOME
Step 2: Fix Tomcat Permissions
This is one of the most common causes for exit status 203. The fix depends on how you installed Tomcat:
If you installed Tomcat via apt:
- Check the user Tomcat is supposed to run as:
Look forcat /etc/default/tomcat8TOMCAT_USER=tomcat8(this is the default). - Ensure Tomcat's core directories are owned by the
tomcat8user:sudo chown -R tomcat8:tomcat8 /var/lib/tomcat8 /var/log/tomcat8 /var/cache/tomcat8
If you manually downloaded and extracted Tomcat:
- First create a dedicated
tomcat8user (best practice for security):sudo useradd -r -m -U -d /opt/tomcat8 -s /bin/false tomcat8 - Transfer ownership of the Tomcat directory to this user:
sudo chown -R tomcat8:tomcat8 /opt/tomcat8 - Make sure the startup/shutdown scripts are executable:
sudo chmod +x /opt/tomcat8/bin/*.sh
Step 3: Check Detailed Logs for Exact Errors
If the above steps don't fix it, dig into the logs to find the root cause:
- For apt-installed Tomcat, check the Catalina log:
sudo tail -n 50 /var/log/tomcat8/catalina.out - For manually installed Tomcat, logs are in your Tomcat directory:
sudo tail -n 50 /opt/tomcat8/logs/catalina.out - You can also check systemd's detailed service logs:
This will show specific issues like "Java not found" or "permission denied when reading server.xml".sudo journalctl -u tomcat8.service -xe
Step 4: Fix Systemd Service File (Manual Installations)
If you set up Tomcat manually, your systemd service file might have incorrect paths or user settings. Create/edit the service file:
sudo nano /etc/systemd/system/tomcat8.service
Paste this configuration (adjust paths to match your Tomcat and Java installation):
[Unit] Description=Apache Tomcat Web Application Container After=network.target [Service] Type=forking Environment=JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 Environment=CATALINA_PID=/opt/tomcat8/temp/tomcat.pid Environment=CATALINA_HOME=/opt/tomcat8 Environment=CATALINA_BASE=/opt/tomcat8 Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC' Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom' ExecStart=/opt/tomcat8/bin/startup.sh ExecStop=/opt/tomcat8/bin/shutdown.sh User=tomcat8 Group=tomcat8 UMask=0007 RestartSec=10 Restart=always [Install] WantedBy=multi-user.target
Save and exit, then reload systemd and restart Tomcat:
sudo systemctl daemon-reload sudo systemctl start tomcat8
Verify the Fix
Check if Tomcat is running:
sudo systemctl status tomcat8
You should see active (running) in green. You can also test by visiting http://localhost:8080 in your browser—you'll see the default Tomcat welcome page if everything works.
内容的提问来源于stack exchange,提问作者shareef

