2010-12-01 7 views

答えて

75

プロードまたはステージングの場合は、実際には設定を変更しないでください。ステージング領域は "QA"環境ではなく、プロダクションが展開される前の保持領域だけになるように設計されています。

新しいデプロイメントをアップロードすると、パッケージをアップロードする現在のデプロイメントスロットが破棄され、VMのアップロードと起動が行われている間に10〜15分間ダウンします。実稼働環境にまっすぐアップロードすると、稼動停止時間は15分です。したがってステージングエリアが発明されました。ステージングにアップロードしてテストし、「スワップ」ボタンをクリックするとステージング環境が魔法のようにプロダクション(仮想IPスワップ)になります。 したがって、あなたのステージングは​​実際にあなたのプロダクションと同じ100%になるはずです。

あなたが探していると思うことは、QA /テスト環境ですか?独自のプロダクト/ステージングを使用して、テスト環境用の新しいサービスを開く必要があります。この場合、デプロイメント環境(プロダクション、テストなど)ごとに1セットの複数の設定ファイルセットを維持することが望ましいでしょう。

特に、Azureが上にあるような設定を行う方法はたくさんあります.configファイル、独自の* .cscfgファイル私がAzureプロジェクトでやっている方法は、次のとおりです。 小さなConfigプロジェクトをセットアップし、そこに展開タイプと一致するフォルダを作成します。 * .config & * .cscfgファイルの各フォルダ内では、特定のデプロイメント環境に一致するデバッグ、テスト、リリース...ビルドターゲットの種類としてVisual Studioでセットアップされます。 ConfigプロジェクトのビルドターゲットフォルダからConfigプロジェクトのルートフォルダにすべてのファイルをコピーするConfigプロジェクトをコンパイルするたびに小さなxcopyコマンドがあります。

ソリューション内の他のすべてのプロジェクトは、Configプロジェクトのルートフォルダから.configまたは.cscfgファイルにリンクします。

私の設定は自動的にすべてのビルド設定に自動的に適応します。また、.config変換を使用して、リリースと非リリースのビルドターゲットのデバッグ情報を管理します。

あなたはこのすべてを読んで、まだ、その後、ランタイムでのステージング・ステータス対生産で取得したいしている場合: Azure structure of your Serviceで取得するために適切なX509 certificateで管理APIを使用するとRoleEnvironment.DeploymentId からdeploymentIdを取得し、 GetDeploymentsメソッドを呼び出します(残りのAPIですが、抽象ライブラリがあります)。コンフィグレーション文字列の設定についての要求とhttp://blog.paraleap.com/blog/post/Managing-environments-in-a-distributed-Azure-or-other-cloud-based-NET-solution

+2

こんにちは、私はいくつかのコードサンプルまたはステップバイステップガイダンスを提供してください。私は環境ごとにAzureのweb.configにも問題があります。 –

+1

Igorekがブログポストを書くために+1を書いています:) – Slav

+6

8ヶ月後ですが、ここはhttp://www.paraleap.com/ですブログ/投稿/管理中の環境 - Azure-or-other-cloud-based-NET-solution.aspx – Igorek

8

ステージング@環境間での切り替えノーダウンタイムのアップグレードおよびロールバックする能力のために主に使用される一時的な展開スロットであるとしてブログ記事:

希望これは

編集を支援しますアップグレードを元に戻す。

システムを(コードでも設定でも)このようなAzureの仕様に結合しないことをお勧めします。

+38

VIPでスワップする前に、キューからジョブを引き出して副作用を引き起こしている場合を除いて、ステージング時にそれらを行わないようにする方法がない限り、これは素晴らしいことです。その場合、プロダクションに達するまで、そうしたことをしないようにあなたのサービスに指示する方法が必要です。 – Jaxidian

+8

正確には、私は持っている問題です。私のワーカーの役割は、新しいメッセージが到着したときにサービスバスのキューからイベントを取得します。 「本物の」プロダクション環境に到達するまで、「本物の」プロダクションキューに接続したくないので、この問題の唯一のものではありません。 – Michael

+2

これはマイクロソフトの立場であり、以上の理由から理想的でありながら純粋ではありません。インスタンスのスロットを示す値を使用して、cscfgの前と後のVIPスワップを変更するだけです。シンプルで信頼性が高く、簡単です。 – Eric

1

はここにあなたのサービスは、外の世界に直面したときに

  1. VIPスワップのみが理にかなって検討する4点です。AKA、APIを公開してリクエストに反応するとき
  2. すべてのサービスがキューからメッセージをプルして処理している場合、サービスはプロアクティブであり、VIPスワップは適切なソリューションではありません。
  3. サービスが反応的で積極的な場合は、デザインを再検討することができます。おそらく、サービスを2つの異なるサービスに分割します。
  4. VIPスワップの前と後のcscfgファイルを変更する提案は、サービスの積極的な部分が短いダウンタイムを取ることができれば良い(まずメッセージをプルしないようにステージングとプロダクションを設定してから、VIPスワッププロダクションの設定を更新してメッセージを引き出します)。
48

時々私はMicrosoftがここに正確にこれを行うコードサンプルを掲載している

...倫理やベストプラクティスを説明できない...人々は質問に答えることを望む: https://code.msdn.microsoft.com/windowsazure/CSAzureDeploymentSlot-1ce0e3b5

image showing Staging instance

image showing Production instance

protected void Page_Load(object sender, EventArgs e) 
{ 
    // You basic information of the Deployment of Azure application. 
    string deploymentId = RoleEnvironment.DeploymentId; 
    string subscriptionID = "<Your subscription ID>"; 
    string thrumbnail = "<Your certificate thumbnail print>"; 
    string hostedServiceName = "<Your hosted service name>"; 
    string productionString = string.Format(
     "https://management.core.windows.net/{0}/services/hostedservices/{1}/deploymentslots/{2}", 
     subscriptionID, hostedServiceName, "Production"); 
    Uri requestUri = new Uri(productionString); 

    // Add client certificate. 
    X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine); 
    store.Open(OpenFlags.OpenExistingOnly); 
    X509Certificate2Collection collection = store.Certificates.Find(
     X509FindType.FindByThumbprint, thrumbnail, false); 
    store.Close(); 

    if (collection.Count != 0) 
    { 
     X509Certificate2 certificate = collection[0]; 
     HttpWebRequest httpRequest = (HttpWebRequest)HttpWebRequest.Create(requestUri); 
     httpRequest.ClientCertificates.Add(certificate); 
     httpRequest.Headers.Add("x-ms-version", "2011-10-01"); 
     httpRequest.KeepAlive = false; 
     HttpWebResponse httpResponse = httpRequest.GetResponse() as HttpWebResponse; 

     // Get response stream from Management API. 
     Stream stream = httpResponse.GetResponseStream(); 
     string result = string.Empty; 
     using (StreamReader reader = new StreamReader(stream)) 
     { 
      result = reader.ReadToEnd(); 
     } 
     if (result == null || result.Trim() == string.Empty) 
     { 
      return; 
     } 
     XDocument document = XDocument.Parse(result); 
     string serverID = string.Empty; 
     var list = from item 
        in document.Descendants(XName.Get("PrivateID", 
         "http://schemas.microsoft.com/windowsazure")) 
        select item; 

     serverID = list.First().Value; 
     Response.Write("Check Production: "); 
     Response.Write("DeploymentID : " + deploymentId 
      + " ServerID :" + serverID); 
     if (deploymentId.Equals(serverID)) 
      lbStatus.Text = "Production"; 
     else 
     { 
      // If the application not in Production slot, try to check Staging slot. 
      string stagingString = string.Format(
       "https://management.core.windows.net/{0}/services/hostedservices/{1}/deploymentslots/{2}", 
       subscriptionID, hostedServiceName, "Staging"); 
      Uri stagingUri = new Uri(stagingString); 
      httpRequest = (HttpWebRequest)HttpWebRequest.Create(stagingUri); 
      httpRequest.ClientCertificates.Add(certificate); 
      httpRequest.Headers.Add("x-ms-version", "2011-10-01"); 
      httpRequest.KeepAlive = false; 
      httpResponse = httpRequest.GetResponse() as HttpWebResponse; 
      stream = httpResponse.GetResponseStream(); 
      result = string.Empty; 
      using (StreamReader reader = new StreamReader(stream)) 
      { 
       result = reader.ReadToEnd(); 
      } 
      if (result == null || result.Trim() == string.Empty) 
      { 
       return; 
      } 
      document = XDocument.Parse(result); 
      serverID = string.Empty; 
      list = from item 
        in document.Descendants(XName.Get("PrivateID", 
         "http://schemas.microsoft.com/windowsazure")) 
        select item; 

      serverID = list.First().Value; 
      Response.Write(" Check Staging:"); 
      Response.Write(" DeploymentID : " + deploymentId 
       + " ServerID :" + serverID); 
      if (deploymentId.Equals(serverID)) 
      { 
       lbStatus.Text = "Staging"; 
      } 
      else 
      { 
       lbStatus.Text = "Do not find this id"; 
      } 
     } 
     httpResponse.Close(); 
     stream.Close(); 
    } 
} 
+10

実際に質問にお答えいただき、ありがとうございます。 –

+2

「時には私は人々がただ倫理やベストプラクティスを説明しないで質問に答えてくれることを願っています...」 - Amen brother –

5

Windows Azure Management Librariesあなたはこのようにそれを行うことができます別の質問に@GuaravMantri answerのおかげ:

using System; 
using System.Linq; 
using System.Security.Cryptography.X509Certificates; 
using Microsoft.Azure; 
using Microsoft.WindowsAzure.Management.Compute; 
using Microsoft.WindowsAzure.Management.Compute.Models; 

namespace Configuration 
{ 
    public class DeploymentSlotTypeHelper 
    { 
     static string subscriptionId = "<subscription-id>"; 
     static string managementCertContents = "<Base64 Encoded Management Certificate String from Publish Setting File>";// copy-paste it 
     static string cloudServiceName = "<your cloud service name>"; // lowercase 
     static string ns = "http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration"; 

     public DeploymentSlot GetSlotType() 
     { 
      var managementCertificate = new X509Certificate2(Convert.FromBase64String(managementCertContents)); 
      var credentials = new CertificateCloudCredentials(subscriptionId, managementCertificate); 

      var computeManagementClient = new ComputeManagementClient(credentials); 
      var response = computeManagementClient.HostedServices.GetDetailed(cloudServiceName); 
      return response.Deployments.FirstOrDefault(d => d.DeploymentSlot == DeploymentSlot.Production) == null ? DeploymentSlot.Staging : DeploymentSlot.Production; 
     } 
    } 
} 
2

この問題を解決するための簡単な方法は、あなたのインスタンスでそれが実行されている環境を識別するためのキーを設定しています。

1)生産現場で設定: 設定>>アプリケーション設定>>アプリケーション設定 そして、SLOT_NAMEという名前のキーを作成し、値 "production"を作成します。重要:スロットの設定を確認してください。 設定>>アプリケーション設定>>アプリケーション設定 そして、SLOT_NAMEという名前のキーと「ステージング」という名前を作成します。重要:スロットの設定を確認してください。

アプリケーションから変数にアクセスし、アプリケーションが実行されている環境を特定します。 Javaでは、次のものにアクセスできます。

String slotName = System.getenv("APPSETTING_SLOT_NAME"); 
関連する問題