温馨提示×

centos weblogic应用部署方法

小樊
40
2025-10-07 07:43:48
栏目: 智能运维

Prerequisites for WebLogic Application Deployment on CentOS
Before deploying applications to WebLogic on CentOS, complete the following setup:

  • Install JDK: Ensure JDK 8 or later is installed (WebLogic 12c+ requires JDK 8+). Verify with java -version and configure environment variables (JAVA_HOME, PATH) in /etc/profile or ~/.bash_profile.
  • Create WebLogic User: Avoid using root for installation. Run groupadd weblogic and useradd -g weblogic weblogic, then set a password with passwd weblogic.
  • Download WebLogic: Obtain the appropriate installer from Oracle’s official website (e.g., fmw_14.1.1.0.0_wls_lite_generic.jar for a minimal installation).
  • Configure Firewall: Allow WebLogic’s default port (7001) by running firewall-cmd --permanent --add-port=7001/tcp and firewall-cmd --reload (or disable SELinux/firewall temporarily for testing).

Step 1: Install WebLogic Server

  1. Extract Installer: Switch to the weblogic user (su - weblogic) and extract the downloaded JAR file:
    mkdir -p /opt/weblogic && unzip fmw_14.1.1.0.0_wls_lite_generic.jar -d /opt/weblogic 
  2. Create Response File: Define silent installation parameters in /opt/weblogic/wls.rsp:
    [ENGINE] Response File Version=1.0.0.0.0 [GENERIC] ORACLE_HOME=/opt/weblogic/Oracle/Middleware INSTALL_TYPE=WebLogic Server DECLINE_SECURITY_UPDATES=true 
  3. Run Silent Installation: Execute the installer with the response file:
    java -jar /opt/weblogic/fmw_14.1.1.0.0_wls_lite_generic.jar -silent -responseFile /opt/weblogic/wls.rsp -invPtrLoc /opt/weblogic/oraInst.loc 
    (Create /opt/weblogic/oraInst.loc with inventory_loc=/opt/weblogic/oraInventory and inst_group=weblogic if not present.)

Step 2: Create a WebLogic Domain

  1. Run Domain Configuration Script: Navigate to the WebLogic configuration directory and start the wizard:
    cd /opt/weblogic/Oracle/Middleware/wlserver/common/bin && ./config.sh 
  2. Follow Prompts:
    • Select “Create a new domain” and provide a name (e.g., base_domain).
    • Set the administrator username/password (e.g., weblogic/admin123).
    • Choose the domain location (default: /opt/weblogic/user_projects/domains/base_domain).
    • Select “Development Mode” for testing (switch to “Production Mode” for production).
  3. Complete Domain Creation: The script generates the domain structure. Start the domain with:
    cd /opt/weblogic/user_projects/domains/base_domain/bin && ./startWebLogic.sh 
    Access the console at http://<server-ip>:7001/console (login with the admin credentials).

Step 3: Deploy Applications (3 Common Methods)

Method 1: Deploy via WebLogic Console (GUI)

  1. Login to Console: Open http://<server-ip>:7001/console in a browser and authenticate.
  2. Navigate to Deployments: Expand the “Deployments” section in the left-hand menu and click “Install”.
  3. Select Application File:
    • Choose “Upload your files” and browse to upload the WAR/EAR file (e.g., myapp.war).
    • Alternatively, select “Install Application Located on the Server” if the file is already on the server (e.g., in /opt/weblogic/deployments).
  4. Configure Deployment:
    • Enter a deployment name (e.g., MyApp).
    • Select the target server/cluster (e.g., AdminServer).
    • Choose “Install this deployment as an application”.
  5. Complete Deployment: Click “Finish” and verify the application status changes to “Active” in the Deployments list.

Method 2: Deploy via Auto-Deployment Directory

  1. Copy WAR File: Place the WAR file into the domain’s auto-deployment directory:
    cp myapp.war /opt/weblogic/user_projects/domains/base_domain/applications/ 
  2. Verify Deployment: WebLogic automatically detects and deploys the application. Check the console’s “Deployments” section—the application should appear with a status of “Prepared”. Start it manually if needed (select the app → “Control” → “Start”).

Method 3: Deploy via Command Line (weblogic.Deployer)

  1. Use weblogic.Deployer: This tool allows programmatic deployment. Run the following command to install a WAR file:
    java weblogic.Deployer -adminurl t3://localhost:7001 -username weblogic -password admin123 -install /opt/weblogic/deployments/myapp.war -targets AdminServer -name MyApp 
    Replace localhost, weblogic, admin123, and paths with your environment details.
  2. Check Status: Use -list to verify the deployment:
    java weblogic.Deployer -adminurl t3://localhost:7001 -username weblogic -password admin123 -list 
    The output should include MyApp with a status of “deployed”.

Step 4: Verify Application Access
After successful deployment, access the application using its context root:

  • If the WAR file is named myapp.war, the default URL is http://<server-ip>:7001/myapp.
  • To customize the context root, add a weblogic.xml file in the WAR’s WEB-INF directory:
    <?xml version="1.0" encoding="UTF-8"?> <weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app"> <context-root>/customroot</context-root> </weblogic-web-app> 
    Redeploy the application, and access it via http://<server-ip>:7001/customroot.

Troubleshooting Tips

  • Deployment Fails: Check the WebLogic logs (/opt/weblogic/user_projects/domains/base_domain/servers/AdminServer/logs/AdminServer.log) for errors. Common issues include missing dependencies or incorrect file permissions.
  • Application Not Accessible: Verify the server is running (ps -ef | grep weblogic), the port is open (netstat -tuln | grep 7001), and the context root is correct.
  • Firewall Blocking: Ensure the firewall allows traffic to the WebLogic port (7001 by default).

0