Setting Up Tomcat-based Java Web Environment (CentOS 7.4)
Application Scenarios
Tomcat is a widely used Java Web application server. This section describes how to set up 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.
The ECS in this chapter uses CentOS 7.4 64bit as OS.
Architecture
Resource and Cost Planning
Resource |
Description |
Cost |
---|---|---|
VPC |
VPC CIDR block: 192.168.0.0/16 |
Free |
Subnet |
|
Free |
Security group |
Inbound rule 1:
Inbound rule 2:
|
Free |
ECS |
|
The following resources generate costs:
For billing details, see Billing Modes. |
jdk |
A Java development tool software. You can download it from: |
Free |
tomcat |
An open-source web application server. You can download it from: |
Free |
PuTTY |
A cross-platform remote access tool, which is used to access various nodes from a Windows OS during software installation. You can download it from: https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html |
Free |
WinSCP |
A file transfer across platform, which is used for transferring files between Windows and Linux systems. You can download it from: |
Free |
Table 1 lists the official paths to download JDK and Tomcat installation packages. You can also obtain the packages from open-source image paths.
Process
Procedure
Preparations
- An ECS is created and has an EIP bound.
- The image source has been updated to a Huawei Cloud image source. For details, see How Can I Use an Automated Tool to Configure a Huawei Cloud Image Source (x86_64 and Arm)? This facilitates obtaining and updating the system and software.
- 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.
- Run the following command to go to the jdk directory:
cd /home/webDemo/jdk
- Run 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.
For example, to check the available versions of the jdk17 software package (jdk-17_linux-x64_bin.tar.gz used as an example), run the following command:
wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz
- Run the following command to go to the tomcat directory:
cd /home/webDemo/tomcat
- Run 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.xx is used as an example. Run the following commands to download the package:
wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.xx/bin/apache-tomcat-8.5.xx.tar.gz --no-check-certificate
- Run the following command to go to the jdk directory:
- Method 1: Upload the installation packages to the ECS using the file transfer tool.
Configuring Security Group Rules for the ECS
- Click the ECS name to switch to the ECS details page and click Security Groups.
- In the upper right corner of the security group rule list, click Modify Security Group Rule.
- On the displayed page showing security group details, click Add Rule.
- 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.
- Set Protocol to ICMP.
If ICMP traffic to an ECS is disabled by default, pinging the ECS EIP will time out. Add a rule to allow ICMP traffic to the ECS first.
Figure 3 Adding a rule to allow ICMP traffic
- Set an appropriate port. Port 8080 is used as an example here.
Figure 4 Adding port 8080
- Set Protocol to ICMP.
Installing JDK
- Run the following command to go to the jdk directory:
cd /home/webDemo/jdk
- 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/
- Run the following command to configure environment variables:
- Add the following content to the end of the file:
#set java environment JAVA_HOME=/home/webDemo/jdk/jdk-17.0.x JRE_HOME=$JAVA_HOME PATH=$JAVA_HOME/bin:$PATH CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JRE_HOME/lib/tools.jar export JAVA_HOME JRE_HOME PATH CLASSPATH
In the preceding command, jdk-17.0.x indicates the version of the JDK installation package that is obtained from the command output in 2.
Example value: jdk-17.0.9
- Run the following command to save the settings and exit:
- Run the following command to make the /etc/profile configurations take effect:
source /etc/profile
- Run the following command to verify the installation.
If the following information is displayed, JDK is installed.
[root@ecs-c525-web ~]# java -version java version "17.0.9" 2023-10-17 LTS Java(TM) SE Runtime Environment (build 17.0.9+11-LTS-201) Java HotSpot(TM) 64-Bit Server VM (build 17.0.9+11-LTS-201, mixed mode, sharing)
Installing Tomcat
- Run the following command to go to the tomcat directory:
cd /home/webDemo/tomcat
- 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.xx, run the following commands:
tar -xvf apache-tomcat-8.5.xx.tar.gz -C /home/webDemo/tomcat/
- 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.xx, run the following commands:
cd /home/webDemo/tomcat/apache-tomcat-8.5.xx/
cd bin/
- 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 Resource and Cost Planning to replace the JDK version in the following script:export JAVA_HOME=/home/webDemo/jdk/jdk-17.0.9 export JRE_HOME=$JAVA_HOME
- Run the following command to save the settings and exit:
- Run the following command to start Tomcat:
- Run the following command to check the Tomcat process:
If the following information is displayed, Tomcat is started successfully.
Figure 5 Checking the Tomcat process
Verifying Java Web Deployment
Enter the following URL in the address bar of the browser:
http://EIP bound to the ECS:8080
If the Tomcat page is displayed, Java Web has been set up. Port 8080 can be accessed over the public network.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot