Tob*_* J. 3 azure azure-compute-emulator
您是否曾尝试在具有完整IIS和多个角色实例的Windows Azure模拟器中运行托管服务?几天前,我注意到一次只有一个Web角色的多个实例在IIS中启动.以下屏幕截图说明了行为,屏幕截图前面的消息框显示了此行为的原因.尝试在IIS管理器中启动其中一个已停止的网站时出现消息框.
示例云应用程序包含两个Web角色:MvcWebRole1和WCFServiceWebRole1,每个都配置为使用三个实例.我的第一个想法是:"当然!在真正的天蓝色世界中不会发生端口冲突,因为每个角色实例都是一个自己的虚拟机.它无法在模拟器中运行!" 但经过一些研究和分析azure计算模拟器的许多部分后,我发现计算模拟器为每个角色实例创建了一个唯一的IP(在我的例子中从127.255.0.0到127.255.0.5).这篇MSDN博客文章(http://blogs.msdn.com/b/avkashchauhan/archive/2011/09/16/whats-new-in-windows-azure-sdk-1-5-each-instance-in-any微软员工Avkash Chauhan的-role-gets-its-own-ip-address-to-match-compute-emulator-close-the-cloud-environment.aspx)也描述了这种行为.在得出结论后,我提出了以下问题:为什么计算模拟器(更准确地说是DevFC.exe)没有将相应角色的IP添加到每个网站的绑定信息中?
我手动和tadaaaaa为每个网站添加了IP:每个网站都可以在没有任何冲突的情况下启动.下一个屏幕截图显示了突出显示已更改的绑定信息.
再一次:为什么模拟器不能为我做这件事?我写了一个小的静态助手方法,在每个角色开始时为我做绑定扩展.也许有人想要使用它:
public static class Emulator
{
public static void RepairBinding(string siteNameFromServiceModel, string endpointName)
{
// Use a mutex to mutually exclude the manipulation of the iis configuration.
// Otherwise server.CommitChanges() will throw an exeption!
using (var mutex = new System.Threading.Mutex(false, "AzureTools.Emulator.RepairBinding"))
{
mutex.WaitOne();
using (var server = new Microsoft.Web.Administration.ServerManager())
{
var siteName = string.Format("{0}_{1}", Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.CurrentRoleInstance.Id, siteNameFromServiceModel);
var site = server.Sites[siteName];
// Add the IP of the role to the binding information of the website
foreach (Binding binding in site.Bindings)
{
//"*:82:"
if (binding.BindingInformation[0] == '*')
{
var instanceEndpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[endpointName];
string bindingInformation = instanceEndpoint.IPEndpoint.Address.ToString() + binding.BindingInformation.Substring(1);
binding.BindingInformation = bindingInformation;
server.CommitChanges();
}
else
{
throw new InvalidOperationException();
}
}
}
// Start all websites of the role if all bindings of all websites of the role are prepared.
using (var server = new Microsoft.Web.Administration.ServerManager())
{
var sitesOfRole = server.Sites.Where(site => site.Name.Contains(RoleEnvironment.CurrentRoleInstance.Role.Name));
if (sitesOfRole.All(site => site.Bindings.All(binding => binding.BindingInformation[0] != '*')))
{
foreach (Site site in sitesOfRole)
{
if (site.State == ObjectState.Stopped)
{
site.Start();
}
}
}
}
mutex.ReleaseMutex();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我调用helper方法如下
public class WebRole : RoleEntryPoint
{
public override bool OnStart()
{
if (RoleEnvironment.IsEmulated)
{
AzureTools.Emulator.RepairBinding("Web", "ServiceEndpoint");
}
return base.OnStart();
}
}
Run Code Online (Sandbox Code Playgroud)
我知道了!
我在三台不同的机器上都有这种行为,这些机器都是格式化的,并且最近提供了全新的干净Windows 8,Visual Studio 2012和Azure SDK 1.8以及Azure Tools安装.因此,重新安装Azure SDK和工具(正如Anton所说)不应该改变任何东西.但我的三台机器的清洁度至关重要!安东,你的机器上安装了至少VS2010 SP 1的Visual Studio 2010吗?我IISConfigurator.exe用ILSpy 分析并找到了将网站的绑定信息中的IP设置为'*'(而不是127.255.0.*)的代码.这取决于静态属性Microsoft.WindowsAzure.Common.Workarounds.BindToAllIpsWorkaroundEnabled.如果Visual Studio 2010的SP级别小于1,此方法在内部使用Microsoft.WindowsAzure.Common.Workarounds.TryGetVS2010SPVersion并导致设置IP绑定'*'.TryGetVS2010SPVersion检查四个注册表项,我不知道为什么但我的注册表中存在其中一个键并返回Visual Studio 2010 SP级别0(我从未在三台机器中的任何一台上安装VS2010 !!!).当我将值HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\DevDiv\vs\Servicing\10.0\SP从0 更改为10(更大的值应该为0)时,Azure模拟器开始127.255.0.*将角色的IP 设置为IIS中所有网站上的绑定信息,并且所有网站都已正确启动.
| 归档时间: |
|
| 查看次数: |
1752 次 |
| 最近记录: |