Help Center> Elastic Cloud Server> Best Practices> Manually Deploying Java Web
Updated at: 2022-04-24 GMT+08:00

Manually Deploying Java Web

Introduction

Tomcat is a widely used Java Web application server. This section describes how to deploy a Java Web environment on an ECS. To do so, you need to download the Java Web installation packages, upload the packages to the ECS, and set security rules for the ECS. After installing Java Web, you need to configure related software.

Intended Audience

Any one who wants to deploy Java Web apps on their ECSs can refer to this section.

The ECS in this chapter uses CentOS 7.3 64bit as OS.

Deployment Process

Figure 1 Deployment Process

Related Software and Tools

Table 1 Software packages

Software Package

How to Obtain

jdk

http://www.oracle.com/technetwork/java/javase/downloads

tomcat

http://tomcat.apache.org/download-80.cgi

Table 1 lists the official paths to download JDK and Tomcat installation packages. You can also obtain the installation packages from other open-source image paths.

Table 2 Tool packages

Tool

Description

How to Obtain

PuTTY

A cross-platform remote access tool, which is used to access various nodes from a Windows OS during software installation

http://www.putty.org/

WinSCP

File transfer across platforms, which is used for transferring files between Windows and Linux systems

http://winscp.net/

Prerequisites

  • An ECS with an EIP bound is available.
  • The jdk and tomcat directories have been created on the ECS using the following commands:

    cd /home/

    mkdir webDemo

    cd webDemo/

    mkdir jdk

    mkdir tomcat

  • The installation packages have been downloaded to the local PC and uploaded to the ECS through the file transfer tool. Alternatively, you can run the wget command to download the installation packages to the ECS. The details of both methods are described as follows:
    • Method 1: Upload the installation packages to the ECS using the file transfer tool.
      • Use WinSCP to upload the JDK software package to the jdk directory.
      • Use WinSCP to upload the Tomcat software package to the tomcat directory.
    • Method 2: Run the wget command to download the installation packages to the ECS.
      1. Run the following command to switch to the jdk directory:

        cd /home/webDemo/jdk

      2. Running the following command to download the JDK installation package:

        wget JDK package download address

        Download the JDK installation package from the path listed in Table 1 or from other open-source image paths.

        Check the available jdk17 software package versions. The JDK installation package jdk-17_linux-x64_bin.tar.gz is used as an example. Run the following command to download the package:

        wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz

      3. Run the following command to switch to the tomcat directory:

        cd /home/webDemo/tomcat

      4. Running the following command to download the Tomcat installation package:

        Download the Tomcat installation package from the path listed in Table 1 or from other open-source image paths.

        wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-x/vx.x.xx/bin/apache-tomcat-x.x.xx.tar.gz

        Find the required version from the open-source image path. The Tomcat installation package of version 8.5.76 is used as an example. Run the following command to download the package:

        wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.76/bin/apache-tomcat-8.5.76.tar.gz --no-check-certificate

Configuring Security Group Rules for the ECS

  1. Click the ECS name to switch to the ECS details page and click Security Groups.
  2. In the upper right corner of the security group rule list, click Modify Security Group Rule.
  3. On the displayed page showing security group details, click Add Rule.
  4. In the Add Inbound Rule dialog box, add a security group rule as prompted.

    To deploy the Java Web environment, you need to add two security group rules for the ECS.

    1. Set Protocol to ICMP.

      If ICMP traffic to an ECS is disabled by default, pinging the ECS EIP will time out. Therefore, add a rule to allow ICMP traffic to the ECS.

      Figure 2 Adding the security group rule
    2. Set an appropriate port. You can set the port number only when TCP or UDP is selected for Protocol. 8080 is used as an example here.
      Figure 3 Adding port 8080

Installing JDK

  1. Run the following command to go to the jdk directory:

    cd /home/webDemo/jdk

  2. Run the following command to decompress the JDK installation package to the jdk directory:

    tar -xvf jdk-17_linux-x64_bin.tar.gz -C /home/webDemo/jdk/

  3. Run the following command to configure environment variables:

    vi /etc/profile

  4. Add the following content to the end of the file:
    #set java environment
    export JAVA_HOME=/home/webDemo/jdk/jdk-17.0.2
    export JRE_HOME=/home/webDemo/jdk/jdk-17.0.2/jre
    export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JRE_HOME/lib/tools.jar
    export PATH=$JAVA_HOME/bin:$PATH
  5. Run the following command to save the configuration and exit:

    :wq

  6. Run the following command to make the /etc/profile configurations take effect:

    source /etc/profile

  7. Run the following command to verify the installation.

    java -version

    JDK is successfully installed if the following information is displayed:

    [root@ecs-c525-web ~]# java -version
    java version "17.0.2" 2022-01-18 LTS
    Java(TM) SE Runtime Environment (build 17.0.2+8-LTS-86)
    Java HotSpot(TM) 64-Bit Server VM (build 17.0.2+8-LTS-86, mixed mode, sharing)

Installing Tomcat

  1. Run the following command to go to the tomcat directory:

    cd /home/webDemo/tomcat

  2. Run the following command to decompress the Tomcat installation package to the tomcat directory:

    tar -xvf apache-tomcat-x.x.xx.tar.gz -C /home/webDemo/tomcat/

    For example, to decompress the Tomcat installation package of version 8.5.76, run the following command:

    tar -xvf apache-tomcat-8.5.76.tar.gz -C /home/webDemo/tomcat/

  3. Run the following commands to install Tomcat:

    cd /home/webDemo/tomcat/apache-tomcat-x.x.xx/

    cd bin/

    For example, to install the Tomcat installation package of version 8.5.76, run the following commands:

    cd /home/webDemo/tomcat/apache-tomcat-8.5.76/

    cd bin/

  4. Run the following command to edit the setclasspath.sh script:

    vi setclasspath.sh

    Add the following content to the end of the setclasspath.sh script:

    Use the java version in Installing JDK to replace the JDK version in the following script:
    export JAVA_HOME=/home/webDemo/jdk/jdk-17.0.2
    export JRE_HOME=/home/webDemo/jdk/jdk-17.0.2/jre
  5. Run the following command to save the settings and exit:

    :wq

  6. Run the following command to start Tomcat:

    ./startup.sh

Verifying Java Web Deployment

Enter the following content in the address box of a browser:

http://EIP bound to the ECS:8080

If the Tomcat page is displayed, Java Web has been set up. Port 8080 of ECSs can be accessed over the public network.

Figure 4 Accessing port 8080
close