Elastic Cloud Server

Building a Java Web Environment Based on Tomcat (CentOS 7.4)

2025-11-25 08:53:34

Application Scenarios

Tomcat is a widely used Java Web application server. This section describes the procedure for deploying a Java Web environment on the eSurfing Cloud Elastic Cloud Server. First, you need to download the package required for deploying the Java Web environment and upload the package to the cloud server, set up the security group rules for the ECS, and then install and configure the relevant software to complete the configuration of the development environment.

The cloud server used in this section takes eSurfing Cloud CentOS 7.4 64-bit operating system cloud server as an example.

Solution Architecture

Figure 1 Diagram of building Java Web environment based on Tomcat

Table 1 Resource and cost planning

 

Resource

Resource Description

Cost Description

Virtual Private Cloud (VPC)

VPC CIDR block: 192.168.0.0/16

Free

VPC Subnet

AZ: AZ 1 Subnet CIDR block:192.168.0.0/24

Free

Security Group

Inbound Rule 1:
Protocol/Application: ICMP
Port: Any
Source Address: 0.0.0.0/0
Inbound Rule 2:
Protocol/Application:
TCP Port: 8080
Source Address: 0.0.0.0/0

Free

ECS

Billing Mode: Yearly/Monthly
AZ: AZ 1
Specification: s6.large.2
Image: CentOS 7.4 64-bit
System Disk: 40G
EIP: Buy now
Internet Bandwidth: Pay-by-traffic
Bandwidth Size: 5Mbit/s

ECS involves the following fees: Cloud Server / EVS / Elastic IP For details about the billing method and standard, see Billing Description.

jdk

Java development tool software.
 How to access:
http://www.oracle.com/technetwork/java/javase/downloads


tomcat

an open source Web application server.
 How to access:
http://tomcat.apache.org/download-80.cgi


PuTTY

Cross-platform remote access tool. Used to access cloud server on Windows system
 during software installation.
 How to access:
https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html


WinSCP

Cross-platform file transfer tool. Used to transfer files between
Windows systems and Linux systems.
 How to access:http://winscp.net/


       

Description             

Table 1 shows the official URLs of JDK and Tomcat, and you can also refer to other open-source image addresses to obtain the package.

      

How to build Java Web environment based on Tomcat (manual)

Figure 2 Installation process

Operation Steps (Manual)

Pre-installation

· The ECS has been created and bound to the Elastic IP.

· In order to better obtain and update the system and software, it is recommended that you update the image source to eSurfing Cloud image source. For details, see how to use the Intranet yum source provided by eSurfing Cloud//hyperlink is required.

· Log in to the Elastic Cloud Server and execute the following command to create a new JDK directory and Tomcat directory.

cd /home/

mkdir webDemo

cd webDemo/

mkdir jdk

mkdir tomcat

· You can choose to download the package locally and then use the file transfer tool to upload the package to the cloud server. Or choose to use the wget command to directly download the package to the cloud server.

· Method 1: Use the file transfer tool to upload the package to the cloud server.

Use the WinSCP tool to upload the JDK package to the JDK folder of the cloud server.

Use the WinSCP tool to upload the Tomcat package to the Tomcat folder of the cloud server.

· Method 2: Use the wget command to directly download the package to the cloud server.

Execute the following command to enter the JDK directory.

cd /home/webDemo/jdk

Execute the following command to download the JDK package. For details about the download address of the package, see Table 1 to query the JDK download address, or use another open source image address to obtain the package.

wget jdk package download address

For example, click the open source image address to query the currently available version, and take the v8.5.93 version package as an example to execute the following command.

wget

https://dlcdn.apache.org/tomcat/tomcat-8/v8.5.93/bin/apache-tomcat-8.5.93.tar.gz --no-check-certificate

Execute the following command to enter the Tomcat directory.

cd /home/webDemo/tomcat

Execute the following command to download the Tomcat package.

See Table 1 to query the Tomcat download address or use another open source image address to obtain the package.

wget

https://dlcdn.apache.org/tomcat/tomcat-x/vx.x.xx/bin/ap

ache-tomcat-x.x.xx.tar.gz

For example, click the open source image address to query the currently available version, and take the v8.5.93 version package as an example to execute the following command.

wget

https://dlcdn.apache.org/tomcat/tomcat-8/v8.5.93/bin/apache-tomcat-8.5.93.tar.gz --no-check-certificate

Setting up ECS Security Group Rules

1. Click the name of the ECS to view its details, and on the ECS details page, select Security Group.

2. On the Security Group screen, go to the Security Group details page.

3. On the Security Group details page, click Add Rule to bring up the Add Rule window.

4. Configure security group rules as prompted. To deploy a Java Web environment, you need to add two security group rules to the ECS.
a. Add an ICMP security group rule for the cloud server.
If the default setting of the cloud server is to disable ICMP rules, timeout will be displayed when pinging the Elastic IP. So first of all, add ICMP rules for the cloud server.
Figure 3 Adding ICMP rule

                     

Note:               

The default setting of eSurfing Cloud cloud server is to release ICMP rules.      

b. Add an access rule for the port assigned by a Web project to the cloud server, for example, port 8080.

Figure 4 Adding port 8080

Install JDK

5. Execute the following command to enter the JDK directory.

cd /home/webDemo/jdk

2. Decompress the JDK package to the JDK directory.

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

3. Configure environment variables.

vim /etc/profile

4. Add the following at the bottom.

#set java environment

JAVA_HOME=/home/webDemo/jdk/jdk-17.0.x

JRE_HOME=$JAVA_HOME

PATH=JAVA_HOME/bin:JAVAHOME/bin:PATH

CLASSPATH=.:JAVA_HOME/lib/dt.jar:JAVAHOME/lib/dt.jar:JRE_HOME/lib/tools.jar

export JAVA_HOME JRE_HOME PATH CLASSPATH

     

Description

jdk-17.0.x indicates the specific version of the JDK package, the actual value needs to be obtained from the return value in step 2.

For example: jdk-17.0.8.

5. Execute the following command to save and exit.

:wq

6. Execute the following command to make the configuration in /etc/profile take effect.

source /etc/profile

7. Verify the installation.

java -version

The echo message is shown below to verify that the JDK installation is successful.

Install Tomcat

1. Execute the following command to enter the Tomcat directory.

cd /home/webDemo/tomcat

2. Decompress the Tomcat package to the Tomcat directory.

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

Taking the v8.5.93 version package as an example, execute the following command.

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

3. Go to the bin directory of Tomcat and execute the following command to install Tomcat.

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

cd bin/

Taking the v8.5.93 version package as an example, execute the following command.

cd /home/webDemo/tomcat/apache-tomcat-8.5.93/

cd bin/

4. Execute the following command to edit the setclasspath.sh script.

vi setclasspath.sh

Add the following at the bottom of the setclasspath.sh script.

Replace the JDK version number in the following section based on the version number of the JDK in Resource and Cost Planning.

export JAVA_HOME=/home/webDemo/jdk/jdk-17.0.8

export JRE_HOME=$JAVA_HOME

5. Execute the following command to save and exit.

:wq

6. Enter the following command to start Tomcat.

./startup.sh

7. Execute the following command to view the Tomcat process.

ps -ef | grep tomcat

If the echo message is shown in the following figure, it indicates that Tomcat has been successfully started.

Figure 5 View Tomcat process

Verify that the Java Web environment is set up

Enter the following in the browser.

http://cloud server EIP:8080

If the screen is redirected to the default Tomcat interface, then the Java Web environment is set up. We can access port 8080 of the cloud server over the Internet.

Figure 6 Accessing port 8080 of the cloud server


Ugbde8RnlIbO