Help Center> Elastic Cloud Server> Best Practices> Manually Deploying Java Web

Manually Deploying Java Web

Introduction

Tomcat is a widely used Java Web application server. This section describes how to deploy Java Web on an ECS. To do so, you need to download the Java Web installation package, upload the package 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 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 directory has been created on the ECS. The commands are as follows:

    cd /home/

    mkdir webDemo

    cd webDemo/

    mkdir jdk

  • The tomcat directory has been created on the ECS. The commands are as follows:

    cd webDemo/

    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 JDK 8 software package versions. The JDK installation package jdk-8u261-linux-x64.tar.gz is used as an example. Run the following command to download the package:

        wget http://mirrors.linuxeye.com/jdk/jdk-8u261-linux-x64.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.

        Run the following command to download the installation package, for example, apache-tomcat-8.5.58.tar.gz:

        wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.58/bin/apache-tomcat-8.5.58.tar.gz

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 is disabled by default, pinging the ECS EIP will time out. Therefore, you must add a rule that allows access to the ECS over ICMP.

    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.

Installing JDK

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

    tar -xvf jdk-8u261-linux-x64.tar.gz -C /home/webDemo/jdk/

  2. Run the following command to configure environment variables:

    vi /etc/profile

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

    :wq

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

    source /etc/profile

  6. 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 "1.8.0_261"
    Java(TM) SE Runtime Environment (build 1.8.0_261-b11)
    Java HotSpot(TM) 64-Bit Server VM (build 25.261-b08, mixed mode

Installing Tomcat

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

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

  2. Run the following commands to install Tomcat:

    cd /home/webDemo/tomcat/apache-tomcat-8.5.58/

    cd bin/

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

    vi setclasspath.sh

    Add the following content to the setclasspath.sh script:
    export JAVA_HOME=/home/webDemo/jdk/jdk1.8.0_261
    export JRE_HOME=/home/webDemo/jdk/jdk1.8.0_261/jre
  4. Save the file and exit. 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 2 Accessing port 8080