You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将基于GlassFish的Java EE应用部署到CentOS服务器?

Hey there! Let's get your Java EE app deployed to CentOS with GlassFish smoothly—since it runs fine locally, we just need to replicate that environment on the server and get your app up. Here's a step-by-step breakdown:

1. Set up the base environment on CentOS

First, you need a working JDK because GlassFish relies on it. Make sure to pick a version compatible with your GlassFish release (e.g., GlassFish 6 requires JDK 11 or later):

  • Install OpenJDK 11 (the most common, stable choice):
    sudo yum update -y
    sudo yum install java-11-openjdk-devel -y
    
  • Verify the installation to make sure it worked:
    java -version
    
    You should see output showing an OpenJDK 11.x.x version.
2. Install GlassFish Server on CentOS

It's best practice to run GlassFish as a non-root user (to avoid security risks), so let's set that up first:

  • Create a dedicated user for GlassFish:
    sudo useradd -m glassfish
    sudo passwd glassfish
    
  • Switch to the new user and download/extract GlassFish (replace the version number with the one you're using locally, e.g., 6.2.5):
    sudo su - glassfish
    wget https://download.eclipse.org/ee4j/glassfish/glassfish-6.2.5.zip
    unzip glassfish-6.2.5.zip
    mv glassfish6 /opt/glassfish  # Optional: Move to a standard system directory for easier access
    
  • Start the default GlassFish domain (domain1):
    /opt/glassfish/bin/asadmin start-domain domain1
    
    You can check if the admin console is accessible by visiting http://your-server-ip:4848 (we'll open this port in the firewall shortly). The default credentials are admin/admin—you'll be prompted to change this password on your first login.
3. Package your local Java EE app

Since your app runs locally, you probably already have a WAR/EAR package ready. If not:

  • If you use Maven, run this in your project root directory on your local machine:
    mvn clean package
    
    Your WAR file will be in the target folder of your project.
  • For Eclipse/IntelliJ, right-click your project → Export → WAR File (follow the prompts to save it to your local drive).
4. Deploy the app to CentOS GlassFish

You have two straightforward options here:

Option 1: Deploy via the Admin Console

  1. Open http://your-server-ip:4848 in a browser and log in with your updated admin credentials.
  2. Navigate to Applications → Deploy.
  3. Under Package File to Upload, click Browse and select your WAR/EAR file from your local machine.
  4. Leave the default settings (or adjust the context path if you want a custom URL for your app) and click OK. Wait a few seconds, and your app should appear in the list as "Running".

Option 2: Deploy via the command line (faster for repeated deployments)

  • First, transfer your WAR file to the CentOS server from your local machine using scp:
    scp /path/to/your-app.war glassfish@your-server-ip:/tmp/
    
  • Log into the CentOS server as the glassfish user, then run the deploy command:
    /opt/glassfish/bin/asadmin deploy /tmp/your-app.war
    
    You'll get a confirmation message like "Application deployed successfully."
5. Make the app accessible to everyone

Now let's ensure external users can reach your app:

  • Open the necessary ports in the CentOS firewall (it uses firewalld by default):
    • For general app access (port 8080):
      sudo firewall-cmd --add-port=8080/tcp --permanent
      
    • If you want to keep the admin console accessible (optional—only do this if you trust the network):
      sudo firewall-cmd --add-port=4848/tcp --permanent
      
    • Reload the firewall to apply the changes:
      sudo firewall-cmd --reload
      
  • Test your app by visiting http://your-server-ip:8080/your-app (replace your-app with your WAR file name, unless you changed the context path during deployment).
6. Troubleshooting common issues
  • App fails to start: Check the GlassFish server logs for detailed error messages:
    tail -f /opt/glassfish/glassfish/domains/domain1/logs/server.log
    
    Look for exceptions like missing dependencies or misconfigured resources.
  • Can't access the app/admin console: Double-check the firewall rules and confirm GlassFish is running with:
    /opt/glassfish/bin/asadmin status-domain domain1
    
  • Forgot admin password: Reset it quickly with:
    /opt/glassfish/bin/asadmin change-admin-password
    

内容的提问来源于stack exchange,提问作者minustwo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 12:21:53