是否可以通过服务配置配置azure VM大小?

时间:2012-08-17 16:39:44

标签: visual-studio-2010 azure

我希望在Azure部署中部署不同的VM大小,具体取决于哪个云服务是目标(例如,我希望在生产中使用更大的实例,但在测试中可以使用较小的实例)。在visual studio 2010中,所有服务配置的大小必须相同。

是否有解决方法,或者这只是它的方式?

4 个答案:

答案 0 :(得分:2)

我发现最好的解决方法是拥有两个不同的云项目。所以基本上你只需要创建两个不同的云项目,在每个项目中添加所有相同的角色,但每个项目都有不同的配置。每次更改时,您都必须小心更新两个位置的所有配置。这相当于有两个CSDEF,正如编程Simian提到的Brent,这只是实现这一目标的具体方法。

这也为您提供其他方面的灵活性。例如,您可以拥有一个包含HTTP和HTTPS端点的测试站点,但生产站点只能有HTTPS。

答案 1 :(得分:2)

我写了一篇精心设计的博客,关于在环境(DEV / QA / PROD /等)中切换各种配置文件这个稍微宽泛的问题......详细信息如下: http://www.paraleap.com/blog/post/Managing-environments-in-a-distributed-Azure-or-other-cloud-based-NET-solution.aspx

基本上,该方法使用预构建事件技术从共享位置复制特定于环境的.CSDEF文件

答案 2 :(得分:0)

VM大小在服务定义文件中声明。因此,创建具有不同大小的云服务包需要不同的包。最终,这不是视觉工作室支持的东西。

除此之外,如果您正在创建云服务(PaaS),我会质疑为什么需要这样做。我收到的最佳指导是运行您需要的最小的VM,并根据您的负载运行尽可能多的运行。通过拥有更多更小的实例,您的解决方案最终具有更大的弹性。

答案 3 :(得分:0)

我进一步评论,但我想我会用powershell提供我的解决方案。我在构建我的CI服务器之前运行它,这恰好是TeamCity,但这可以在本地或在CI上运行。

Param(
    [string]$RoleType,  #WebRole or WorkerRole
    [string]$RoleName,  #RoleName from CSDEF
    [string]$VMInstanceSizeIn,  #Options for VM Size: Small, Medium, Large, ExtraLarge, A6, A7
    [string]$csDefPath  #File path for ServiceDefinition.csdef for the cloud service project
)

$timeStampFormat = "g"
if ($VMInstanceSizeIn -eq $null) {$VMInstanceSizeIn = "Medium"}

Write-Output "$(Get-Date -f $timeStampFormat) - Setting $RoleType role type with RoleName $RoleName VM Size to $VMInstanceSizeIn in ServiceDefinition.csdef prior to building the package file."

Try 
{
    $csDefConfig = "$csDefPath\ServiceDefinition.csdef"
    Write-Output "$(Get-Date -f $timeStampFormat) - config file location: $csDefConfig"
    $csDefConfigXml = [xml](Get-Content $csDefConfig)
    Write-Output "$(Get-Date -f $timeStampFormat) - Found ServiceDefinition File at $csDefConfig"
    $csDefCurrentXmlNode = $csDefConfigXml.ServiceDefinition.$RoleType | where {$_.Name -eq $RoleName}
    $csDefCurrentXmlNode.SetAttribute("vmsize", $VMInstanceSizeIn)
    $csDefConfigXml.Save($csDefConfig)
    Write-Output "$(Get-Date -f $timeStampFormat) - Successfully saved the ServiceDefinition.csdef file to $csDefConfig"
}

Catch
{
    Write-Output "$(Get-Date -f $timeStampFormat) - Powershell Script Error. An error occurred while attempting to modify the ServiceDefinition.csdef file prior to building the solution."  
    Write-Error -ErrorRecord $_
    ##teamcity[buildStatus status='FAILURE' ]
    exit(1)
}

请注意,在编写本文时,我只需要处理一个Web和worker角色,因此我不确定是否曾经测试过多个worker角色。它应该至少足以让你开始。