Alibaba Cloud Marketplace provides images that are integrated with Java runtime environments, web servers, and databases. An Alibaba Cloud Marketplace image helps you deploy a Java web server that can be used out of the box without the need to install and configure the server. This topic describes how to use an Alibaba Cloud Marketplace image to deploy a Java web environment on an Elastic Compute Service (ECS) instance.
Prerequisites
An Alibaba Cloud account is created. To create an Alibaba Cloud account, go to the Sign up to Alibaba Cloud page.
A virtual private cloud (VPC) is created in the region in which you want to create an ECS instance for Java web environment deployment. A security group is created in the VPC and a rule is added to the security group to allow inbound traffic on ports 22 and 8080. The ECS instance on which you want to deploy a Java web environment will be created in the VPC and added to the security group. For information about how to add an inbound security group rule, see Add a security group rule.
Background information
In the following example, the JAVA_nginx_tomcat_CentOS7.9_20G Alibaba Cloud Marketplace image is used. You may be charged for the Alibaba Cloud Marketplace image. You can also purchase another image from Alibaba Cloud Marketplace based on your business requirements. For more information, see Alibaba Cloud Marketplace.
Procedure
Step 1: Purchase a Java web environment image from Alibaba Cloud Marketplace and create an ECS instance from the image
You can use a Java web environment image to deploy a Java web server that can be used out of the box without the need to install and configure the server.
Click JAVA_nginx_tomcat_CentOS7.9_20G to go to the details page of the image.
Click Choose Your Plan.
On the Custom Launch tab of the ECS instance buy page, configure the parameters. Take note of the parameters in the following table. You can configure other parameters based on your business requirements. For information about how to configure other parameters, see Create an instance on the Custom Launch tab.
Parameter
Example
Description
Region
China (Hangzhou)
Select the region in which the security group that you created in the prerequisites resides.
Network and Zone
Default VPC
Select the VPC in which the security group that you created in the prerequisites resides.
Image
The Alibaba Cloud Marketplace image that you purchased is automatically selected in the Image section. You do not need to configure this parameter.
Public IP Address
Select Assign Public IPv4 Address.
In this example, you access the Java web environment deployed on the ECS instance over the Internet. You must assign a public IPv4 address to the instance when you create the instance or associate an elastic IP address (EIP) with the instance after the instance is created. For information about how to associate an EIP with an ECS instance, see Associate an EIP with an ECS instance.
Security Group
sg-2zebli************if
Select the security group that you created in the prerequisites. A rule must be added to the security group to allow inbound traffic on ports 22 and 8080.
Step 2: Obtain the public IP address of the created ECS instance
To verify the environment configuration of the Java web server by using the public IP address of the ECS instance, you must obtain the public IP address of the instance.
Go to ECS console - Instance.
In the top navigation bar, select the region and resource group of the resource that you want to manage.
Find the ID of the ECS instance that you created to go to the Instance Details page and obtain the public IP address of the instance.
Step 3: Verify the environment configuration
Log on to the Linux ECS instance. For more information, see Connect to an instance.
Verify the Java environment.
Run the following command to check the Java version and ensure that the correct Java version is installed:
java -version
Verify the Apache Tomcat server.
Run the following command to start Apache Tomcat. If the
Tomcat started
message appears, Apache Tomcat is started.NoteIn this example,
/usr/local/tomcat
is the default installation directory for the Apache Tomcat server in the image that you used to create the ECS instance. The installation directory may vary based on the image that you use. You can obtain the installation directory on the details page of the Alibaba Cloud Marketplace image and change the directory in the following command./usr/local/tomcat/bin/startup.sh
In the address bar of a web browser on your on-premises device, enter
http://<Public IP address of the ECS instance>:8080
. If the Apache Tomcat welcome page appears, the Java web environment is configured as expected.NoteIf the Apache Tomcat welcome page does not appear after you enter
http://<Public IP address of the ECS instance>:8080
, check whether the security group allows inbound traffic on port 8080.If you want to upload an on-premises project to test the environment, upload a WAR package to the webapps directory under the Apache Tomcat installation directory. In this example, the
/usr/local/tomcat/webapps
directory is used. Then, enterhttp://<Public IP address of the ECS instance>:8080/<Package name>
in the address bar of a web browser to access the project. For more information, see Upload a file to or download a file from a Linux instance.
Verify the MySQL service.
Run the following command to connect to MySQL. Enter the username that is used to connect to MySQL after
-u
. After the command is run, you are prompted to enter a password. If the password that you enter is valid and correct, your identity is authenticated. In this case, the MySQL CLI appears.NoteIn the image used in this example, the default username used to connect to MySQL is
root
and the default password that corresponds to the username isyl2vXBS%FjGoSfby
. The default username and password may vary based on the image that you use. You can obtain the default username and password on the details page of your Alibaba Cloud Marketplace image and replace the username and password specified in the following command with the actual username and password.mysql -u root -p
Run the following command at the MySQL CLI to view all available MySQL databases. If the command is run as expected, the MySQL service is reachable.
SHOW DATABASES;
What to do next
After you deploy a Java web environment on an ECS instance, consider configuring a website on the instance and binding a domain name to the public IP address of the instance. For more information, see Build a website.
Select an appropriate development tool to develop web applications. If an application requires a database to store application data, add database configurations to the relevant configuration file of the corresponding web project, such as the Properties file, and connect to the database. After the development is complete, you can deploy the Java web applications to Apache Tomcat, such as to the webapps directory under the Apache Tomcat installation directory. After the Java web applications are deployed and started, you can access your applications over the web interface. For more information, see Apache Tomcat 9 Tomcat Web Application Deployment.
NoteIf you use a different version of Apache Tomcat, replace the version number in the URL with the corresponding version number.
You can upload on-premises files to the ECS instance. For more information, see Upload a file to or download a file from a Linux instance.
Consider using a Server Load Balancer (SLB) instance to improve the availability and performance of your website. For more information, see Getting Started.