9

我想在 azure 中维护一个暂存环境和一个生产环境。每个都应该有自己的 blob 存储和 sql 存储。实现这一目标的最佳方法是什么?设置暂存和生产 sql 服务器以及两个 blob 存储帐户?

4

3 回答 3

13

这就是我管理生产/验收/测试环境的方式(请注意,我没有使用staging这个词)。对于每个环境,我创建以下内容(取决于项目):

  • 云服务
  • 存储帐户
  • SQL Azure 服务器 + 数据库
  • AppFabric (ACS, ...) 命名空间
  • 虚拟机

因此,假设我有一个名为myapp的应用程序,那么我的环境将如下所示:

  • 生产
    • 云服务:myapp-prod .cloudapp.net
    • 存储帐户:myapp-prod
    • SQL Azure Server 包含 1 个数据库:MyApp
  • 验收
    • 云服务:myapp-acce .cloudapp.net
    • 存储帐户:myapp-acce
    • SQL Azure Server 包含 1 个数据库:MyAppAcce
  • 测试
    • ...

因此,所有环境都有一个在生产部署槽中运行的应用程序版本。每当我想为我的生产环境进行 VIP 交换时,我只使用暂存部署槽(注意生产部署槽和生产环境之间的区别)。

这种方法有几个优点,每个环境都有专用组件(如存储帐户):

  • 在不影响实际应用程序的情况下测试新版本很容易。
  • 每个环境可以有不同的安全性(例如,所有开发人员都可以访问测试存储帐户的密钥)
  • 如果您正在测试您的应用程序,您可以使用真实的 URL + SSL,而不是那个又长又丑的暂存 URL。
  • 测试与 ACS 的集成很容易,因为每个环境都有其专用的命名空间。
  • 使用 Visual Studio,您可以轻松管理每个环境的设置。
  • 最后但同样重要的是,您必须知道 Windows Azure 存储的可伸缩性目标适用于存储帐户级别。这意味着,如果您对所有环境使用单个存储帐户,则可能会降低应用程序在生产中的性能,因为您正在对在暂存中运行的应用程序进行压力测试。如果您在每个环境中使用一个存储帐户,则在执行某项操作时不会影响其他环境。
于 2012-09-20T15:34:08.173 回答
2

这是一个分步指南。

1)您需要库:Microsoft.Samples.WindowsAzure.ServiceManagement 有一个名为“Windows Azure 服务管理库”的 nuGet 包,其中包含该库。

2) 您需要创建一个 X509Certificate2 并按照此处列出的说明进行操作。确保将您创建的 .CER 文件上传到订阅证书存储。确保将带有 PRIVATE KEY 的 .PFX 副本上传到实际的云服务证书存储。

为 Windows Azure 管理创建和上传证书

http://blogs.msdn.com/b/clouddeployments/archive/2010/05/12/making-calls-to-the-service-management-api-from-a-service-running-in-windows-azure。 aspx

3) 这些教程也掩盖了这一点:您需要定义服务端点。我在我的 app.config 文件中执行了以下操作

 <system.serviceModel>
  <bindings>
    <webHttpBinding>
    <binding name="WindowsAzureServiceManagement_WebHttpBinding" closeTimeout="00:01:00"
             openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00">
      <readerQuotas maxStringContentLength="1048576" maxBytesPerRead="131072" />
      <security mode="Transport">
        <transport clientCredentialType="Certificate" />
      </security>
    </binding>
  </webHttpBinding>
</bindings>
<client>
  <endpoint name="WindowsAzureEndPoint"
            address="https://management.core.windows.net"
            binding="webHttpBinding" bindingConfiguration="WindowsAzureServiceManagement_WebHttpBinding"                contract="Microsoft.Samples.WindowsAzure.ServiceManagement.IServiceManagement" />     
</client>
</system.serviceModel>

4) 完成后,我创建了一个名为“GetServerInstance”的静态类。这是代码:

public static class GetServerInstance
  {
      const string SubId = "your azuresubscriptionid";        

    public static bool IsProductionEnvironment()
    {
        //get the current deploymentId
        var currentInstance = RoleEnvironment.DeploymentId;  
        var mgmtChannnel = ServiceManagementHelper.CreateServiceManagementChannel("WindowsAzureEndPoint",GetCertifcate()); //make the endpoint.  
        var serviceDetails = mgmtChannnel.GetHostedServiceWithDetails(SubId, "your-cloud-service-name", true);
        var currentDeploymentSlot = serviceDetails.Deployments.First(p => p.PrivateID == currentInstance).DeploymentSlot;

        if (currentDeploymentSlot == DeploymentSlotType.Staging)            
            return false; //staging server

        if (currentDeploymentSlot == DeploymentSlotType.Production)            
            return true; //production server        

    }


    private static X509Certificate2 GetCertifcate()
    {
        string certificateThumbprint = RoleEnvironment.GetConfigurationSettingValue("CertificateThumbprint");
        if (String.IsNullOrEmpty(certificateThumbprint))
        {
            return null; //I'd throw an exception here and log the error
        }

        var certificateStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
        certificateStore.Open(OpenFlags.ReadOnly);

        var certs = certificateStore.Certificates.Find(X509FindType.FindByThumbprint, certificateThumbprint, false);
        if (certs.Count != 1)
        {                
            return null; //I'd throw an exception here and log the error
        }

        return certs[0];
    }
}

5) 现在是我的工人角色,我不想在 Staging 上运行,因为它会向人们收取两次费用。我称之为:

 if (GetServerInstance.IsProductionEnvironment())
        {
           //Do work! I'm in production
        };
于 2013-08-09T01:08:53.300 回答
0

不是一个真正的答案,但我需要比评论中允许的更多的字符:)

我也在处理同样的问题。拥有单独的存储帐户和数据库服务器是可行的方法,但挑战是从配置文件中选择适当的存储帐户/数据库,因为您可以在暂存或生产环境中部署代码。RoleInstance 类没有办法区分暂存和生产。

您剩下的唯一选择是调用服务管理 API 并确定要选择的存储帐户/数据库。给这个等式添加一个更复杂的情况是,当您执行 VIP 交换时,您的暂存槽突然变成了生产槽(反之亦然),现在您必须根据新环境切换存储帐户/数据库连接字符串。

我很想听听其他人在做什么。

于 2012-09-20T12:52:17.467 回答