Java Azure 服务架构资源管理器中的 Webapp 部署
Java Webapp Deployment in Azure Service fabric explorer
我们有一个无状态的 Java 应用程序,我想将其部署在 Azure 结构中。我已经按照文档安装了 Fabric SDK 和 Visual studio 工具。
之后,我创建了 Service Fabric 应用程序 "Guest Executable" 模板,我的项目结构如下所示:
我已按照与 https://azure.microsoft.com/en-us/documentation/articles/service-fabric-deploy-existing-app/
中的文档类似的步骤进行操作
我的ServiceManifest.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest Name="Guest1Pkg"
Version="1.0.0"
xmlns="http://schemas.microsoft.com/2011/01/fabric"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ServiceTypes>
<StatelessServiceType ServiceTypeName="Guest1Type" UseImplicitHost="true" />
</ServiceTypes>
<CodePackage Name="Code" Version="1.0.0">
<EntryPoint>
<ExeHost>
<Program>HelloWorld.war</Program>
<Arguments></Arguments>
<WorkingFolder>CodePackage</WorkingFolder>
</ExeHost>
</EntryPoint>
</CodePackage>
<ConfigPackage Name="Config" Version="1.0.0" />
<Resources>
<Endpoints>
<Endpoint Name="JavaAppTypeEndpoint" Protocol="http" Port="8080" Type="Input" />
</Endpoints>
</Resources>
</ServiceManifest>
我的 ApplicationManifest.xml 片段如下:
<?xml version="1.0" encoding="utf-8"?>
<ApplicationManifest ApplicationTypeName="Application1Type"
ApplicationTypeVersion="1.0.0"
xmlns="http://schemas.microsoft.com/2011/01/fabric"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Parameters>
<Parameter Name="Guest1_InstanceCount" DefaultValue="-1" />
</Parameters>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="Guest1Pkg" ServiceManifestVersion="1.0.0" />
<ConfigOverrides />
</ServiceManifestImport>
<DefaultServices>
<Service Name="Guest1">
<StatelessService ServiceTypeName="Guest1Type" InstanceCount="[Guest1_InstanceCount]">
<SingletonPartition />
</StatelessService>
</Service>
</DefaultServices>
</ApplicationManifest>
我在本地部署到 Service Fabric Explorer,构建和发布步骤都很好,没有任何错误:
-------- Package: Project: Application1 succeeded, Time elapsed: 00:00:00.3530634 --------
2>Started executing script 'Deploy-FabricApplication.ps1'.
2>. 'C:\Users\samanoha\Documents\Visual Studio 2015\Projects\Application1\Application1\Scripts\Deploy-FabricApplication.ps1' -ApplicationPackagePath 'C:\Users\samanoha\Documents\Visual Studio 2015\Projects\Application1\Application1\pkg\Debug' -PublishProfileFile 'C:\Users\samanoha\Documents\Visual Studio 2015\Projects\Application1\Application1\PublishProfiles\Local.5Node.xml' -DeployOnly:$true -UnregisterUnusedApplicationVersionsAfterUpgrade $false -OverrideUpgradeBehavior 'None' -OverwriteBehavior 'Always' -SkipPackageValidation:$true -ErrorAction Stop
2>Copying application to image store...
2>Copy application package succeeded
2>Registering application type...
2>Register application type succeeded
2>Removing application package from image store...
2>Remove application package succeeded
2>Finished executing script 'Deploy-FabricApplication.ps1'.
2>Time elapsed: 00:00:01.9327912
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
========== Deploy: 1 succeeded, 0 failed, 0 skipped ==========
Started executing script 'Publish-NewServiceFabricApplication'.
[void](Connect-ServiceFabricCluster); Import-Module 'C:\Program Files\Microsoft SDKs\Service Fabric\Tools\PSModule\ServiceFabricSDK\ServiceFabricSDK.psm1'; Publish-NewServiceFabricApplication -ApplicationPackagePath 'C:\Users\samanoha\Documents\Visual Studio 2015\Projects\Application1\Application1\pkg\Debug' -ApplicationParameterFilePath 'C:\Users\samanoha\Documents\Visual Studio 2015\Projects\Application1\Application1\PublishProfiles\..\ApplicationParameters\Local.5Node.xml' -ApplicationParameter @{_WFDebugParams_='[]'} -Action Create -SkipPackageValidation:$true -ErrorAction Stop
Creating application...
ApplicationName : fabric:/Application1
ApplicationTypeName : Application1Type
ApplicationTypeVersion : 1.0.0
ApplicationParameters : { "_WFDebugParams_" = "[]" }
Create application succeeded.
Finished executing script 'Publish-NewServiceFabricApplication'.
Time elapsed: 00:00:01.8691591
Started executing script 'Get-ServiceFabricApplicationStatus'.
[void](Connect-ServiceFabricCluster); Import-Module 'C:\Program Files\Microsoft SDKs\Service Fabric\Tools\PSModule\ServiceFabricSDK\ServiceFabricSDK.psm1'; Get-ServiceFabricApplicationStatus -ApplicationName 'fabric:/Application1' -ErrorAction Stop
The application has started.
Service Status:
fabric:/Application1/Guest1 is ready.
The application is ready.
Finished executing script 'Get-ServiceFabricApplicationStatus'.
Time elapsed: 00:00:01.0230548
但是应用程序健康状态显示错误并且事件是
"Error event: SourceId='System.Hosting', Property='CodePackageActivation:Code:EntryPoint'.
There was an error during CodePackage activation."
我不知道部署中可能存在什么问题,除了上面提到的之外,是否还需要在应用程序服务入口点中包含任何内容。
此外,Java web 应用程序在独立 tomcat 上部署时具有以下上下文 http://localhost:8080/HelloWorld/hello . If the Application is deployed in Service fabric cluster, will the URL context for this remains same or should it be something like http://localhost:8080/Application1/Guest1/HelloWorld/hello 由于围绕它的 Azure 结构包装器?
您在程序配置中放置的内容必须是可执行的(.exe、.cmd 等)。 Service Fabric 将尝试执行您放入其中的任何内容。
例如,在您链接到的文档中,要执行 node.js 应用程序,程序是 node.exe 并且参数指向应用程序:
<ExeHost>
<Program>node.exe</Program>
<Arguments>bin/www</Arguments>
<WorkingFolder>CodePackage</WorkingFolder>
</ExeHost>
最后发现我们需要在Host虚拟机(Azure VM或本地桌面)中单独安装Java,然后我们必须引用java路径。
所以我的服务清单是
<EntryPoint>
<ExeHost>
<Program>scripts\launchConfig.cmd</Program>
<Arguments></Arguments>
<WorkingFolder>CodePackage</WorkingFolder>
<ConsoleRedirection FileRetentionCount="5" FileMaxSizeInKb="2048"/>
</ExeHost>
</EntryPoint>
我在 Code 文件夹下创建了一个名为 scripts 的文件夹,脚本文件 "launchConfig.cmd" 只有一行,如下所示:
"C:\Program Files (x86)\Java\jre1.8.0_101\bin\java.exe" -jar HelloWorld.war
我们可能需要删除路径硬编码,但这是最终引用的方式。
入口点应该是一个命令。 HelloWorld.war 不是命令。来宾可执行文件专为 运行 命令或 exe 而设计。
<SetupEntryPoint>
<ExeHost>
<Program>scripts\launchConfig.cmd</Program>
</ExeHost>
</SetupEntryPoint>
和 launchConfig.cmd 应包含 运行 Tomcat 或 jboss(或任何 j2ee 应用程序服务器)的脚本。您应该在 运行 服务器之前安装 java,配置 tomcat/ jboss,部署 HelloWorld.war 并配置端口。
如之前的回答所述,一种方法是将 Java 单独安装到机器上。
我在 https://blog.vjrantal.net/2017/04/11/high-availability-java-hosting-in-azure-using-service-fabric/ 上写了另一种方法,它基于将需要的 Java 运行时打包到应用程序包中。
我们有一个无状态的 Java 应用程序,我想将其部署在 Azure 结构中。我已经按照文档安装了 Fabric SDK 和 Visual studio 工具。
之后,我创建了 Service Fabric 应用程序 "Guest Executable" 模板,我的项目结构如下所示:
我已按照与 https://azure.microsoft.com/en-us/documentation/articles/service-fabric-deploy-existing-app/
中的文档类似的步骤进行操作我的ServiceManifest.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest Name="Guest1Pkg"
Version="1.0.0"
xmlns="http://schemas.microsoft.com/2011/01/fabric"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ServiceTypes>
<StatelessServiceType ServiceTypeName="Guest1Type" UseImplicitHost="true" />
</ServiceTypes>
<CodePackage Name="Code" Version="1.0.0">
<EntryPoint>
<ExeHost>
<Program>HelloWorld.war</Program>
<Arguments></Arguments>
<WorkingFolder>CodePackage</WorkingFolder>
</ExeHost>
</EntryPoint>
</CodePackage>
<ConfigPackage Name="Config" Version="1.0.0" />
<Resources>
<Endpoints>
<Endpoint Name="JavaAppTypeEndpoint" Protocol="http" Port="8080" Type="Input" />
</Endpoints>
</Resources>
</ServiceManifest>
我的 ApplicationManifest.xml 片段如下:
<?xml version="1.0" encoding="utf-8"?>
<ApplicationManifest ApplicationTypeName="Application1Type"
ApplicationTypeVersion="1.0.0"
xmlns="http://schemas.microsoft.com/2011/01/fabric"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Parameters>
<Parameter Name="Guest1_InstanceCount" DefaultValue="-1" />
</Parameters>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="Guest1Pkg" ServiceManifestVersion="1.0.0" />
<ConfigOverrides />
</ServiceManifestImport>
<DefaultServices>
<Service Name="Guest1">
<StatelessService ServiceTypeName="Guest1Type" InstanceCount="[Guest1_InstanceCount]">
<SingletonPartition />
</StatelessService>
</Service>
</DefaultServices>
</ApplicationManifest>
我在本地部署到 Service Fabric Explorer,构建和发布步骤都很好,没有任何错误:
-------- Package: Project: Application1 succeeded, Time elapsed: 00:00:00.3530634 --------
2>Started executing script 'Deploy-FabricApplication.ps1'.
2>. 'C:\Users\samanoha\Documents\Visual Studio 2015\Projects\Application1\Application1\Scripts\Deploy-FabricApplication.ps1' -ApplicationPackagePath 'C:\Users\samanoha\Documents\Visual Studio 2015\Projects\Application1\Application1\pkg\Debug' -PublishProfileFile 'C:\Users\samanoha\Documents\Visual Studio 2015\Projects\Application1\Application1\PublishProfiles\Local.5Node.xml' -DeployOnly:$true -UnregisterUnusedApplicationVersionsAfterUpgrade $false -OverrideUpgradeBehavior 'None' -OverwriteBehavior 'Always' -SkipPackageValidation:$true -ErrorAction Stop
2>Copying application to image store...
2>Copy application package succeeded
2>Registering application type...
2>Register application type succeeded
2>Removing application package from image store...
2>Remove application package succeeded
2>Finished executing script 'Deploy-FabricApplication.ps1'.
2>Time elapsed: 00:00:01.9327912
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
========== Deploy: 1 succeeded, 0 failed, 0 skipped ==========
Started executing script 'Publish-NewServiceFabricApplication'.
[void](Connect-ServiceFabricCluster); Import-Module 'C:\Program Files\Microsoft SDKs\Service Fabric\Tools\PSModule\ServiceFabricSDK\ServiceFabricSDK.psm1'; Publish-NewServiceFabricApplication -ApplicationPackagePath 'C:\Users\samanoha\Documents\Visual Studio 2015\Projects\Application1\Application1\pkg\Debug' -ApplicationParameterFilePath 'C:\Users\samanoha\Documents\Visual Studio 2015\Projects\Application1\Application1\PublishProfiles\..\ApplicationParameters\Local.5Node.xml' -ApplicationParameter @{_WFDebugParams_='[]'} -Action Create -SkipPackageValidation:$true -ErrorAction Stop
Creating application...
ApplicationName : fabric:/Application1
ApplicationTypeName : Application1Type
ApplicationTypeVersion : 1.0.0
ApplicationParameters : { "_WFDebugParams_" = "[]" }
Create application succeeded.
Finished executing script 'Publish-NewServiceFabricApplication'.
Time elapsed: 00:00:01.8691591
Started executing script 'Get-ServiceFabricApplicationStatus'.
[void](Connect-ServiceFabricCluster); Import-Module 'C:\Program Files\Microsoft SDKs\Service Fabric\Tools\PSModule\ServiceFabricSDK\ServiceFabricSDK.psm1'; Get-ServiceFabricApplicationStatus -ApplicationName 'fabric:/Application1' -ErrorAction Stop
The application has started.
Service Status:
fabric:/Application1/Guest1 is ready.
The application is ready.
Finished executing script 'Get-ServiceFabricApplicationStatus'.
Time elapsed: 00:00:01.0230548
但是应用程序健康状态显示错误并且事件是
"Error event: SourceId='System.Hosting', Property='CodePackageActivation:Code:EntryPoint'.
There was an error during CodePackage activation."
我不知道部署中可能存在什么问题,除了上面提到的之外,是否还需要在应用程序服务入口点中包含任何内容。
此外,Java web 应用程序在独立 tomcat 上部署时具有以下上下文 http://localhost:8080/HelloWorld/hello . If the Application is deployed in Service fabric cluster, will the URL context for this remains same or should it be something like http://localhost:8080/Application1/Guest1/HelloWorld/hello 由于围绕它的 Azure 结构包装器?
您在程序配置中放置的内容必须是可执行的(.exe、.cmd 等)。 Service Fabric 将尝试执行您放入其中的任何内容。
例如,在您链接到的文档中,要执行 node.js 应用程序,程序是 node.exe 并且参数指向应用程序:
<ExeHost>
<Program>node.exe</Program>
<Arguments>bin/www</Arguments>
<WorkingFolder>CodePackage</WorkingFolder>
</ExeHost>
最后发现我们需要在Host虚拟机(Azure VM或本地桌面)中单独安装Java,然后我们必须引用java路径。
所以我的服务清单是
<EntryPoint>
<ExeHost>
<Program>scripts\launchConfig.cmd</Program>
<Arguments></Arguments>
<WorkingFolder>CodePackage</WorkingFolder>
<ConsoleRedirection FileRetentionCount="5" FileMaxSizeInKb="2048"/>
</ExeHost>
</EntryPoint>
我在 Code 文件夹下创建了一个名为 scripts 的文件夹,脚本文件 "launchConfig.cmd" 只有一行,如下所示:
"C:\Program Files (x86)\Java\jre1.8.0_101\bin\java.exe" -jar HelloWorld.war
我们可能需要删除路径硬编码,但这是最终引用的方式。
入口点应该是一个命令。 HelloWorld.war 不是命令。来宾可执行文件专为 运行 命令或 exe 而设计。
<SetupEntryPoint>
<ExeHost>
<Program>scripts\launchConfig.cmd</Program>
</ExeHost>
</SetupEntryPoint>
和 launchConfig.cmd 应包含 运行 Tomcat 或 jboss(或任何 j2ee 应用程序服务器)的脚本。您应该在 运行 服务器之前安装 java,配置 tomcat/ jboss,部署 HelloWorld.war 并配置端口。
如之前的回答所述,一种方法是将 Java 单独安装到机器上。
我在 https://blog.vjrantal.net/2017/04/11/high-availability-java-hosting-in-azure-using-service-fabric/ 上写了另一种方法,它基于将需要的 Java 运行时打包到应用程序包中。