将 Java 应用程序迁移到 AzureMigrate Java applications to Azure
1/20/2020
本文内容
本主题概述了关于如何将 Java 应用程序迁移到 Azure 的建议策略。This topic provides an overview of recommended strategies for migrating Java applications to Azure.
此迁移指南旨在介绍 Azure 方案的主流 Java,并提供高级规划建议和注意事项。This migration guidance is designed to cover mainstream Java on Azure scenarios, and to provide high-level planning suggestions and considerations. 若要与 Microsoft Java on Azure 团队讨论特定的 Java 应用迁移方案,请填写以下问卷,等待我们的代表与你联系。If you'd like to discuss a specific Java app migration scenario with the Microsoft Java on Azure team, please fill out the following questionnaire and a representative will contact you.
确定应用程序类型Identifying application type
在为 Java 应用程序选择云目标之前,需确定其应用程序类型。Before you select a cloud destination for your Java application, you'll need to identify its application type. 大多数 Java 应用程序都是以下类型之一:Most Java applications are one of the following types:
将在下面各部分介绍这些类型。These types are described in the following sections.
Spring Boot/JAR 应用程序Spring Boot / JAR applications
许多更新的应用程序都是从命令行直接调用。Many newer applications are invoked directly from the command line. 这些应用程序仍处理 Web 请求,但不依赖于应用程序服务器来提供 HTTP 请求处理,而是将 HTTP 通信和所有其他依赖项直接合并到应用程序包中。These applications still handle web requests, but instead of relying on an application server to provide HTTP request handling, they incorporate HTTP communication and all other dependencies directly into the application package. 此类应用程序通常使用框架(如 Spring Boot、Dropwizard、Micronaut、MicroProfile、Vert.x 等)生成。Such applications are frequently built with frameworks such as Spring Boot, Dropwizard, Micronaut, MicroProfile, Vert.x, and others.
这些应用程序会打包成带 .jar 扩展的存档(JAR 文件)。These applications are packaged into archives with the .jar extension (JAR files).
Spring Cloud/微服务Spring Cloud / microservices
微服务体系结构样式是一种方法,用于将单个应用程序开发为一系列小型服务,每项服务都在其自己的进程中运行,并通过轻型机制(通常是 HTTP 资源 API)通信。The microservice architectural style is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API. 这些服务围绕业务功能构建,可通过完全自动化的部署机制进行独立部署。These services are built around business capabilities and are independently deployable by fully automated deployment machinery. 这些服务可能使用不同的编程语言编写,并使用不同的数据存储技术,必须对其进行最低限度的集中管理。There is a bare minimum of centralized management of these services, which may be written in different programming languages and use different data storage technologies. 此类服务通常使用框架(如 Spring Cloud)构建。Such services are frequently built with frameworks such as Spring Cloud.
这些服务会打包成多个带 .jar 扩展的应用程序(JAR 文件)。These services are packaged into multiple applications with the .jar extension (JAR files).
Web 应用程序Web applications
Web 应用程序在 Servlet 容器中运行。Web applications run inside a Servlet container. 某些 Web 应用程序直接使用 servlet API,而许多 Web 应用程序则使用其他框架来封装 servlet API,例如 Apache Struts、Spring MVC、JavaServer Faces (JSF) 等。Some use servlet APIs directly, while many use additional frameworks that encapsulate servlet APIs, such as Apache Struts, Spring MVC, JavaServer Faces (JSF), and others.
Web 应用程序会打包成带 .war 扩展的存档(WAR 文件)。Web applications are packaged into archives with the .war extension (WAR files).
Java EE 应用程序Java EE applications
Java EE 应用程序(也称为 J2EE 应用程序,最新的称为 Jakarta EE 应用程序)可能包含 Web 应用程序的部分或全部元素,或不包含其中的任何元素。Java EE applications (also referred to as J2EE applications or, more recently Jakarta EE applications) can contain some, all, or none of the elements of web applications. 它们还可能包含并使用 Java EE 规范定义的多个其他组件。They can also contain and consume many additional components as defined by the Java EE specification.
Java EE 应用程序可打包为带 .ear 扩展的存档(EAR 文件),或带 .war 扩展的存档(WAR 文件)。Java EE applications can be packaged as archives with the .ear extension (EAR files) or as archives with the .war extension (WAR files).
Java EE 应用程序必须部署到符合 Java EE 规范的应用程序服务器(例如,WebLogic、WebSphere、WildFly、GlassFish、Payara 等)上。Java EE applications must be deployed onto Java EE-compliant application servers (such as WebLogic, WebSphere, WildFly, GlassFish, Payara, and others).
仅依赖于 Java EE 规范提供的功能的应用程序(即,与应用服务器无关的应用程序)可以从一个合规的应用程序服务器迁移到另一个合规的应用程序服务器。Applications that rely only on features provided by the Java EE specification (that is, app-server-independent applications) can be migrated from one compliant application server onto another. 如果应用程序依赖于特定的应用程序服务器(依赖于应用服务器),则可能需要选择一个允许你托管该应用程序服务器的 Azure 服务目标。If your application is dependent on a specific application server (app-server-dependent), you may need to select an Azure service destination that permits you to host that application server.
批处理作业/计划的作业Batch / scheduled jobs
某些应用程序适用于短暂运行,执行特定工作负载,然后退出,而不是等待请求或用户输入。Some applications are intended to run briefly, execute a particular workload, and then exit rather than wait for requests or user input. 此类作业有时需运行一次,有时则需定期按计划的时间间隔运行。Sometimes such jobs need to run once or at regular, scheduled intervals. 在本地,通常从服务器的 crontab 调用此类作业。On premises, such jobs are often invoked from a server's crontab.
这些应用程序会打包成带 .jar 扩展的存档(JAR 文件)。These applications are packaged into archives with the .jar extension (JAR files).
备注
如果应用程序使用计划程序(如 Spring Batch 或 Quartz)来运行计划任务,强烈建议你将此类任务构造为在应用程序外部运行。If your application uses a scheduler (such as Spring Batch or Quartz) to run scheduled tasks, we strongly recommend that you factor such tasks to run outside of the application. 如果应用程序在云中扩展为多个实例,则同一作业会运行多次。If your application scales to multiple instances in the cloud, the same job will run more than once. 此外,如果计划机制使用主机的本地时区,则在跨区域缩放应用程序时可能会遇到意外的行为。Furthermore, if your scheduling mechanism uses the host's local time zone, you may experience undesirable behavior when scaling your application across regions.
选择针对的 Azure 服务目标Selecting the target Azure service destination
以下部分说明哪些服务目标满足应用程序要求,以及它们涉及的责任。The following sections show you which service destinations meet your application requirements, and what responsibilities they involve.
托管选项网格Hosting options grid
使用以下网格可识别适用于你的应用程序类型的潜在目标。Use the following grid to identify potential destinations for your application type. 如你所见,AKS 和虚拟机支持所有应用程序类型,但它们要求你的团队承担更多的责任,如下一部分所示。As you can see, AKS and Virtual Machines support all application types, but they require your team to take on more responsibilities, as shown in the next section.
目标 →Destination →
应用程序 类型 ↓Application type ↓
应用App
服务Service
Java SEJava SE
应用App
服务Service
TomcatTomcat
AzureAzure
SpringSpring
云Cloud
AKSAKS
虚拟Virtual
机Machines
Spring Boot/JAR 应用程序Spring Boot / JAR applications
✔✔
✔✔
✔✔
✔✔
Spring Cloud/微服务Spring Cloud / microservices
✔✔
✔✔
✔✔
Web 应用程序Web applications
✔✔
✔✔
✔✔
Java EE 应用程序Java EE applications
✔✔
✔✔
商业应用程序服务器Commercial application servers
(例如 WebLogic 或 WebSphere)(such as WebLogic or WebSphere)
✔✔
✔✔
本地文件系统上的长期持久性Long-term persistence on local filesystem
✔✔
✔✔
✔✔
✔✔
应用程序服务器级聚类分析Application server-level clustering
✔✔
✔✔
批处理作业/计划的作业Batch / scheduled jobs
✔✔
✔✔
✔✔
VNet 集成/混合连接VNet Integration/Hybrid Connectivity
✔✔
✔✔
预览Preview
✔✔
✔✔
持续责任网格Ongoing responsibility grid
请使用以下网格来了解迁移后每个目标施加给团队的责任。Use the following grid to understand the responsibility each destination places on your team following migration.
团队对使用“👉”指示的任务持续承担责任。Your team is responsible on a continual basis for the tasks indicated with "👉". 建议你通过一个稳定且高度自动化的过程来履行所有此类责任。We recommend implementing a robust, highly automated process for fulfilling all such responsibilities.
备注
这并不是一个详尽的责任列表。This isn't an exhaustive list of responsibilities.
目标 →Destination →
任务 ↓Task ↓
应用App
服务Service
AzureAzure
SpringSpring
云Cloud
AKSAKS
虚拟Virtual
机Machines
更新库Updating libraries
(包括漏洞修正)(including vulnerability remediation)
👉👉
👉👉
👉👉
👉👉
更新应用程序服务器Updating the application server
(包括漏洞修正)(including vulnerability remediation)
👉👉
👉👉
更新 Java 运行时Updating the Java Runtime
(包括漏洞修正)(including vulnerability remediation)
👉👉
👉👉
触发 Kubernetes 更新Triggering Kubernetes updates
(由 Azure 通过手动触发器执行)(performed by Azure with a manual trigger)
空值N/A
👉👉
空值N/A
协调非后向兼容的 Kubernetes API 变更Reconciling non-backward-compatible Kubernetes API changes
空值N/A
👉👉
空值N/A
更新容器基础映像Updating container base image
(包括漏洞修正)(including vulnerability remediation)
空值N/A
👉👉
空值N/A
更新操作系统Updating the operating system
(包括漏洞修正)(including vulnerability remediation)
👉👉
检测和重启失败的实例Detecting and restarting failed instances
👉👉
针对更新实施清空和滚动重启Implementing draining and rolling restart for updates
👉👉
基础结构管理Infrastructure management
👉👉
👉👉
监视和警报管理Monitoring and alert management
👉👉
👉👉
👉👉
👉👉
如果将 servlet 容器(如 Spring Boot)作为应用程序的一部分进行部署,则应将其视为一个库。因此,这始终是你的责任。If you deploy the servlet container (such as Spring Boot) as part of your application, you should consider it a library and, as such, it's always your responsibility.
确保本地连接性Ensuring on-premises connectivity
如果应用程序需要访问任何本地服务,则需预配 Azure 的某个连接服务。If your application needs to access any of your on-premises services, you'll need to provision one of Azure's connectivity services. 或者,你需要重构应用程序,以便使用本地资源公开的公开可用的 API。Alternatively, you'll need to refactor your application to use publicly available APIs that your on-premises resources expose.
在开始任何迁移之前,应完成此操作。You should complete this effort before you start any migration.
清点当前容量和资源使用情况Inventory current capacity and resource usage
记录当前生产服务器的硬件,以及平均和峰值请求计数和资源使用情况。Document the hardware of the current production server(s) plus the average and peak request counts and resource usage. 将需要此信息来预配服务目标中的资源。You'll need this information to provision resources in the service destination.
迁移指导Migration guidance
请使用以下网格,按应用程序类型和针对的 Azure 服务目标来查找迁移指南。Use the following grids to find migration guidance by application type and targeted Azure service destination.
Java 应用程序Java applications
请使用以下行查找 Java 应用程序类型和列,找出将托管应用程序的 Azure 服务目标。Use the rows below to find your Java application type and the columns to find the Azure service destination that will host your application.
若要将 JBoss EAP 应用迁移到应用服务上的 Tomcat,请先将 Java EE 应用转换为在 Tomcat 上运行的 Java Web 应用 (servlet),然后按照下面提供的指南操作。If you'd like to migrate a JBoss EAP app to Tomcat on App Service, first convert the Java EE app to Java Web Apps (servlets) running on Tomcat, then follow the guidance indicated below.
若要将 Tomcat 上的 Web 应用迁移到 Azure Spring Cloud,请先将应用转换为 Spring Cloud 微服务,然后按照下面提供的指南操作。If you'd like to migrate a Web app on Tomcat to Azure Spring Cloud, first convert the app into Spring Cloud microservices, then follow the guidance indicated below.
目标 →Destination →
应用程序 类型 ↓Application type ↓
应用App
服务Service
Java SEJava SE
应用App
服务Service
TomcatTomcat
AzureAzure
SpringSpring
云Cloud
AKSAKS
虚拟机Virtual Machines
Spring Boot/Spring Boot /
JAR 应用程序JAR applications
指南guidance
已计划planned
指南guidance
已计划planned
Spring Cloud/Spring Cloud /
微服务microservices
空值N/A
空值N/A
指南guidance
已计划planned
指南guidance
已计划planned
Web 应用程序Web applications
Web 应用程序on Tomcat
空值N/A
指南guidance
已计划planned
Java EE 应用程序Java EE applications
请使用以下行查找在特定应用服务器上运行的 Java EE 应用程序类型。Use the rows below to find your Java EE application type running on a specific app server. 请使用列来查找将托管应用程序的 Azure 服务目标。Use the columns to find the Azure service destination that will host your application.
目标 →Destination →
应用服务器 ↓App server ↓
应用App
服务Service
Java SEJava SE
应用App
服务Service
TomcatTomcat
AzureAzure
SpringSpring
云Cloud
AKSAKS
虚拟机Virtual Machines
WildFly/WildFly /
JBoss ASJBoss AS
空值N/A
空值N/A
空值N/A
指南guidance
已计划planned
WebLogicWebLogic
空值N/A
空值N/A
空值N/A
WebSphereWebSphere
空值N/A
空值N/A
空值N/A
指南guidance
已计划planned
JBoss EAPJBoss EAP
空值N/A
空值N/A
空值N/A
指南guidance
已计划planned