Alibaba Cloud Marketplace provides images that are pre-configured with a Java runtime environment, a web server, and a database. These images allow you to deploy a ready-to-use Java web server on an ECS instance without manual installation and configuration.
Prerequisites
-
An Alibaba Cloud account is created. To create an Alibaba Cloud account, go to the Sign up to Alibaba Cloud page.
-
You have created a security group in the target region and VPC, and added an inbound rule to allow traffic on ports 22 and 8080. For more information, see Add a security group rule.
Background information
This tutorial demonstrates how to deploy a Java web server using the Alibaba Cloud Marketplace image JAVA_nginx_tomcat_CentOS7.9_20G as an example. Marketplace images may incur charges. You can also select and purchase other images from the Alibaba Cloud Marketplace as needed.
Procedure
Step 1: Purchase an image and create an instance
-
Go to the image details page for JAVA_nginx_tomcat_CentOS7.9_20G.
-
Click Choose Your Plan.
-
Configure the parameters on the Custom Launch page. The main parameters are listed below, and you can configure other parameters as needed. For more information, see Create an instance by using Custom Launch.
Parameter
Example
Description
Region
China (Hangzhou)
The instance must be in the same region as the security group.
Network and zone
Default VPC
The instance must be in the same VPC as the security group.
Image
Marketplace Image - JAVA_nginx_tomcat_CentOS7.9_20G
The image is automatically selected based on your purchase. No changes are required.
Public IP address
Select Assign Public IPv4 Address.
To access the Java web environment over the internet, you must assign a public IPv4 address to the instance. Alternatively, you can associate an EIP with the instance after you create it. For more information, see Associate an EIP with a cloud resource.
Security group
sg-2zebli************if
Select the security group that you created. The security group must allow inbound traffic on ports 22 and 8080.
Step 2: Get the public IP address
You need the instance's public IP address to verify the environment configuration.
Go to ECS console - Instances.
-
In the upper-left corner of the page, select a region and resource group.
-
Click the ID of the target instance to go to the Instance Details page and find the public IP address.
Step 3: Verify the environment configuration
-
Connect to the Linux instance. For more information, see Connection methods.
-
Verify the Java environment.
Run the following command to check the installed Java version.
java -version[root@xxx ~]# java -version java version "1.8.0_121" Java(TM) SE Runtime Environment (build 1.8.0_121-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
-
Verify Tomcat.
-
Run the following command to start Tomcat. If the output includes
Tomcat started., Tomcat has started successfully.NoteThe default installation directory of Tomcat in the image used for this tutorial is
/usr/local/tomcat. This path may vary depending on the image. Check the image details page in Alibaba Cloud Marketplace for the correct path and modify the command accordingly./usr/local/tomcat/bin/startup.sh[root@ixxxxxxxxxx ~]# /opt/tomcat/bin/startup.sh Using CATALINA_BASE: /opt/tomcat Using CATALINA_HOME: /opt/tomcat Using CATALINA_TMPDIR: /opt/tomcat/temp Using JRE_HOME: /usr/share/jdk1.8.0_121/jre Using CLASSPATH: /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar Tomcat started.
-
In your browser's address bar, enter
http://. The appearance of the Tomcat welcome page confirms that the environment is configured correctly.:8080 Note-
If the Tomcat welcome page does not appear after you enter
http://, check the security group to ensure that inbound traffic on port 8080 is allowed.:8080 -
To test your project, upload a WAR package to the webapps directory of Tomcat. For the image in this tutorial, the directory is
/usr/local/tomcat/webapps. Then, enterhttp://in your browser to access the project. For more information, see Upload files to or download files from a Linux instance.:8080/

-
-
-
Verify MySQL.
-
Run the following command to connect to MySQL. When prompted, enter the password. If you are authenticated successfully, the MySQL CLI is displayed.
NoteFor the image used in this tutorial, the default remote username is
rootand the default password isyl2vXBS%FjGoSfby. The defaults may vary by image. Check the image details page in Alibaba Cloud Marketplace and use the correct username and password.mysql -u root -p[root@ixxxxxxxx ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.7.19 MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
-
In the MySQL CLI, run the following command to list all available databases. If the command succeeds, it confirms that your instance can communicate with MySQL.
SHOW DATABASES;mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec)
-
Next steps
-
After you deploy the Java web environment, you can configure a website on the server and associate a domain name with the public IP address of the ECS. For more information, see Build a website.
You can select suitable development tools for web development. If your application needs to use a database to store application data, you can add the database configuration to a related configuration file, such as a Properties file, in your web project to connect to the database. After development is complete, you can deploy the Java web application to Tomcat (for example, to the
webappsdirectory in the Tomcat installation directory). After the application is deployed and running, you can access your application through a web browser. For more information, see Tomcat 9 Application Deployment Guide.NoteIf you use a different version of Tomcat, replace the version number in the URL with the corresponding version.
To upload local files to the ECS, see Upload files to or download files from a Linux instance.
-
You can use Server Load Balancer (SLB) to improve the availability and performance of your website. For more information, see Getting Started.