- Documentation
Elastic Compute Service
Elastic Compute Service
Best Practices
Self-service website creation
Building environments
Setting up a Java web environment
Building environments
Setting up a Java web environment
Setting up a Java web environment
Tomcat is currently a widely used Java web application server. This topic uses Tomcat as an example to describe how to deploy a Java web environment on a Linux instance.
Software versions
- Operating system: In the example provided in this topic, CentOS 7.6 is used.
- Tomcat: a web application server. In this topic, Tomcat 10.1.41 is used.
- JDK: The Java Development Kit. In the example provided in this topic, JDK 18.0.2.1 is used.
Prerequisites
- An EIP is associated with the Linux instance, enabling the instance to connect to the Internet. For information about how to associate an EIP with an ECS instance, see Associating EIPs.
Step 1: Download software
- Download the JDK. Go to the Java SE page to obtain the download link for the required Java SE version. In the example provided in this topic, JDK 18.0.2.1 is downloaded.
- Method 1: First, download the JDK to your local machine, and then upload the JDK to your ECS instance. For more information, see Overview of local data upload.
- Method 2: Run the following command to download JDK 18.0.2.1 to the ECS instance.
- Execute the following command to download Tomcat. This topic uses Tomcat 10.1.41 as an example. Please visit the Apache official website to obtain the download link for the required version.
Step 2: Install the JDK
- Execute the following command to create a new directory.
- Execute the following command to extract the JDK installation package to the /usr/java directory.
- Execute the following command to enter the /usr/java directory.
- Execute the following command to modify the profile file.
- Press the i key to enter edit mode and add the following content at the end.
-
- Press Esc, enter :wq, and then press Enter to save and exit the file.
- Execute the following command to make the newly added configuration in the profile file take effect.
- Execute the following command to verify whether the JDK is installed.
- If the following output is displayed, the installation is successful.
-
Step 3: Install Tomcat
- Execute the following commands in sequence to create a new directory.
- Execute the following command to extract the Tomcat installation package to /usr/tomcat.
- Execute the following command to enter the bin directory.
- Execute the following command to modify the setclasspath.sh script.
- Press the i key to enter edit mode, and then add the following content.
-
- Press Esc, enter :wq, and then press Enter to save and exit the file.
- Execute the following command to start Tomcat.
-
Step 4: Allow and test service ports
- In the inbound rules of the instance security group, allow the port required by the Java web environment. In the example provided in this topic, HTTP port 8080 is allowed.
- Click the instance name, select the "Security Group" tab, and click the "Edit rule" button. The security group details are displayed.
- On the "Access rules > Inbound rules" tab, click the "Add rule" button. Set "Priority" to "1", set "Strategy" to "Allow", select "TCP" for "Protocol type", set "Port range" to "8080", and set "Source" to "0.0.0.0/0", as shown in the following figure. Click the "Confirm" button.
- Enter http://<ECS instance EIP>:8080 in the local browser to access the Java web environment.
- If the following output is displayed, the Java web environment is set up successfully.
-
Last updated: 2026.06.18 17:48:25