Use the Application publishing management feature to deploy a Java application to a group of Elastic Computing Service (ECS) instances. Application Management provides a centralized and repeatable process for publishing applications and managing their lifecycle across multiple servers. This improves deployment efficiency and reliability.
Solution architecture
Application Management, Object Storage Service (OSS), and ECS work together to enable automated application deployment.
The core workflow is as follows:
Define the application and resources: Create an application and an application group in Application Management, and then import the target ECS instances into the group.
Prepare the deployment: Upload the application's JAR package to a bucket in OSS. Then, create a deployment for the application that contains the JAR package information and deployment scripts.
Execute the deployment: Use Application Management to publish the specified deployment to the target application group. Application Management uses automated tasks to download the deployment and start the application.
Key concepts
Applications, application groups, and deployments are the core concepts in Application Management:
Application: An application consists of an application program and the resources required for its deployment. It is managed and maintained as a single unit.
Application program: The program to be deployed, such as a web service, a machine learning model, or a database service.
Resources: The cloud resources required to deploy the application program, such as ECS instances, ESS scaling groups, or container clusters.
Application group: An application can be divided into multiple groups to isolate resources and configurations for different environments. For example:
By environment:
prod-group(production environment group) andpre-group(staging environment group).By region:
hangzhou-group(Hangzhou region group) andbeijing-group(Beijing region group). After you create the groups, you can import resources into each one.
Deployment: A deployment is a collection of the source files and the start/stop scripts for an application release. It contains all the information required for the release and is used for standardized, versioned application management. To release an application, you publish its deployment to an application group.
Procedure
Create an application and import Elastic Compute Service (ECS) instances.
If you do not have an ECS instance, create one that runs a Linux operating system from the ECS console - Custom Launch page.
We recommend using an ECS image of Alibaba Cloud Linux 3.2104 LTS 64-bit or Ubuntu 22.04 64-bit. The scripts in the following examples are based on these two images. If you use a different image, modify the scripts as needed.
Go to the ECS console - Application Management page, click Create from Existing Resources, create an application and an application group, and import the ECS instance into the application group.
Create an OSS deployment.
Download the official sample JAR package and upload it to OSS.
Go to the ECS console - Application Management page. On the My Applications tab, click the name of the target application.
On the application product page, select the Deployment tab, and then click Create Deployment.
On the Create Deployment page, set RevisionType to OSS File. Configure the parameters and click OK.
OSS file information: Specify the OSS Bucket and the path to the file.
If the ECS instance and the OSS Bucket are in the same region, you can select Internal Network Download to improve the download speed.
Working directory: The directory where the start and stop scripts run. The OSS file is automatically downloaded to this directory. Example:
/root/deploy.Alibaba Cloud Linux
function start_application() { set -e yum install -y maven-3.5.4 java -jar ./sample-spring-1.0-SNAPSHOT.jar & } start_applicationUbuntu
function start_application() { set -e apt update apt install -y maven java -jar ./sample-spring-1.0-SNAPSHOT.jar & } start_application### Stop the application (if any) function stop_application() { PID=$(ps -ef | grep "sample-spring-1.0-SNAPSHOT.jar" | grep -v "grep" | awk '{print $2}') if [ -n "$PID" ]; then kill -9 $PID fi } stop_application
Return to the deployment list. Find the deployment that you created and click Publish. Select the target group and click OK to start the deployment.
Verify the result.
Go to the details page of the target instance. Click Connect and select Workbench. Follow the prompts on the page to log on to the terminal.
Run the
curl http://localhost:8080/hellocommand. A return value ofAlibaba Spring Sample!indicates that the deployment was successful.