gpt4 book ai didi

Azure 网站缩放

转载 作者:行者123 更新时间:2023-12-03 01:49:43 25 4
gpt4 key购买 nike

我可以使用 Azure 管理库扩展 Azure Web 应用程序/API 应用程序吗?我基本上想实现网络应用程序的扩展和缩小来处理限制。因此,我需要通过 C# 代码扩展 Web 应用程序和 API 应用程序。有指向任何合适的库/ReST API 的指针吗?

在下面提到的答案的帮助下,我了解了如何更新 APP Service 计划以进行横向扩展,但是,我无法找到我的 APP Service 的 webHostingPlanName。我尝试使用下面的代码,托管计划总是为空。

        var regionName = "myregion";

var credentials = GetCredentials();

var websiteManagementClient = CloudContext.Clients.CreateWebSiteManagementClient(credentials);

var webSpaces = websiteManagementClient.WebSpaces.List();
var webSpace = webSpaces.FirstOrDefault(x => x.GeoRegion == regionName);
if (webSpace == null)
{
throw new Exception(string.Format("No webspace for region {0} found", regionName));
}

var webHostingPlans = websiteManagementClient.WebHostingPlans.List(webSpace.Name);
var webHostingPlan = webHostingPlans.FirstOrDefault();// this is null always, I know an APP service exists in this region

最佳答案

是的,我们可以使用 Microsoft.WindowsAzure.Management.Websites 库来扩展和缩小 Web 应用程序。使用方法 WebSiteManagementClient.WebHostingPlans.UpdateAsync(webspaceName, webHostingPlanName, webHostingPlanUpdateParameters) 来实现它。

我已经做了一个演示来做到这一点。以下是我的详细步骤:

1.安装Microsoft.WindowsAzure.Management.WebSites,我们可以从link获取它。 .

2.创建WebsiteManagementClient对象

我使用证书来创建网站管理客户端。

  • 安装 VS 后,使用 VS 文件夹下的 makecert.exe 创建证书。

    makecert -sky exchange -r -n "CN=[CertificateName]" -pe -a sha1 -len 2048 -ss My "[CertificateName].cer

enter image description here

  • 上传.将文件证书发送到 Azure 门户,然后获取指纹

enter image description here3.使用代码生成WebsiteManagementClient对象

          public static X509Certificate2 GetCert(string thumbprint)
{

X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
certStore.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);
if (certCollection.Count <= 0) return null;
X509Certificate2 cert = certCollection[0];
return cert;
}

var cert = GetCert(字符串指纹)
var subscriptionId = "您的订阅Id"
var webSiteManagementClient = new WebSiteManagementClient(new CertificateCloudCredentials(subscriptionId, cert));

4.构造WebHostingPlanUpdateParameters

var webHostingPlanUpdateParameters = new WebHostingPlanUpdateParameters
{
NumberOfWorkers = 1, //the number of the instances
SKU = SkuOptions.Standard,
WorkerSize = WorkerSizeOptions.Small
};

5.使用代码更新 WebHostingPlans

client.WebHostingPlans.UpdateAsync(webspaceName, webHostingPlanName, webHostingPlanUpdateParameters);

Note: If you try to run the project on the Azure. Please refer to document Using Certificates in Azure Websites Applications. Adding an app setting named WEBSITE_LOAD_CERTIFICATES with its value set to the thumbprint of the certificate will make it accessible to your web application

关于Azure 网站缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40231598/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com