转载

[译]在 Azure 中使用公用 IP 创建多 NIC VM

[译]在 Azure 中使用公用 IP 创建多 NIC VM Russ Slaten    2014 年 11 月 18 日下午 4 点

我们最近 宣布 了支持具有多个网络接口控制器 (NIC) 的虚拟机 (VM) 。我仍在努力了解此功能适用的所有新场景,但首先,我希望亲自测试一下这项功能。

我的方案是通过 PowerShell 使用 实例级公用 IP 地址 (PIP) 构建一个具有两个 NIC 的 VM ,一个用于后端子网,另一个用于前端子网。 PIP 向 VM 提供自己的公用 IP 地址,此地址与分配给 VM 所在云服务的虚拟 IP 地址 (VIP) 不同。二者最大的区别在于, PIP 是完全开放的,而使用 VIP 时需要在该云服务内的 VM 上为要访问的所有内容本质上设置端口转发规则。这也意味着,如果您要使用 PIP ,您应该在 VM 上运行某种防火墙。

方案示意图

[译]在 Azure 中使用公用 IP 创建多 NIC VM

步骤概览

1.   选择在 Azure 内具有唯一性的唯一名称,以用于下面的步骤

2.   创建虚拟网络 (VNET)

3.   更新 Azure PowerShell

4.   保存 Azure 订阅设置文件

5.   运行 PowerShell 脚本

6.   验证配置

详细步骤

  • 首先选择一个在 Azure 内具有唯一性的名称。我们要将此名称用于 VNET、云服务、VM、存储和 PIP。名称必须全部小写。在本例中,将使用 rslatendemo。
  • 下一步,我们需要登录到 Azure 门户并创建一个新的 VNET。请使用与此处相同的参数,因为脚本需要使用这些参数才能完成。
    • 转至 Networks (网络)并单击 New (新建)
    • 单击 Custom Create (自定义创建)
    • 在 Name (名称)中键入您选择的唯一名称,选择 South Central US (美国中南部)作为 Location (位置),然后单击 Next (下一步)两次
    • 配置地址空间: 192.168.0.0/21
    • 配置两个新子网:
      • 前端: 192.168.0.0/24
      • 后端: 192.168.1.0/24
    • 单击 OK (确定)
[译]在 Azure 中使用公用 IP 创建多 NIC VM
  • 更新您 PC 上的 Azure PowerShell,以便能够使用新的 Azure cmdlet: http://www.windowsazure.cn/documentation/articles/install-configure-powershell/  
  • 将 Azure 订阅文件保存到本地。您可以在此处下载您的 Azure 订阅文件: https://manage.windowsazure.cn/publishsettings/
  • 运行 CreateMultiNICPIPVM.ps1 脚本。

脚本操作

  • 使用您的 Azure 设置文件登录
  • 创建新存储帐户
  • 创建新存储容器
  • 创建新云服务
  • 在您之前创建的 VNET 中创建一个具有两个 NIC 和一个公用 IP 的新 VM。此 VM 将运行 Windows Server 2012 R2,采用大尺寸 (A3) 以支持多个 NIC,它位于美国中南部地区,并使用您之前在 VNET 中创建的子网。

脚本参数

名称

描述

示例

azureSettingsFile

设置文件的路径

c:/temp/rslatendemo.publishsettings

azureName

之前选择的唯一名称

rslatendemo

adminUserName

管理员用户名

rslatendemo

adminPassword

管理员用户密码

P@SSw0rd1

脚本示例

./CreateMultiNICPIPVM.ps1–azureSettingsFile c:/temp/rslatendemo.publishsettings –azureName rslatendemo–adminUserName rslatendemo –adminPassword P@SSw0rd1

验证配置

脚本应该运行并在New-AzureVMcmdlet下方显示 OperationStatus :Succeeded。大约 10 分钟后, VM 应该会开始运转,您可能需要刷新浏览器才能看到我们使用此脚本创建的对象。

  • 登录门户,找到所创建的 VM 并单击它,然后转至 Dashboard(仪表板)。记下用作 VIP 的 IP 地址。我的示例中为 23.102.153.182。
[译]在 Azure 中使用公用 IP 创建多 NIC VM
  • 单击 Connect(连接)并通过 RDP 登录到 VM。打开 IE 并在 Bing 中搜索“What is my IP Address”(我的 IP 地址是什么)。您可能需要将 Bing 添加到受信任的站点。记下此 IP,在我的示例中为 23.98.147.247。这便是我的 PIP。
[译]在 Azure 中使用公用 IP 创建多 NIC VM
  • 记下 VM 中的两个 NIC
[译]在 Azure 中使用公用 IP 创建多 NIC VM
  • 从您自己的 PC,对 PIP 执行 ping 操作,请注意请求超时
  • 现在,关闭 VM 中的 Windows 防火墙(临时)或允许 ICMP,然后再次对 PIP 执行 ping 操作
[译]在 Azure 中使用公用 IP 创建多 NIC VM

脚本

param(   [Parameter(Mandatory=$true)]   $azureSettingsFile,   [Parameter(Mandatory=$true)]   $azureName,   [Parameter(Mandatory=$true)]   $adminUserName,   [Parameter(Mandatory=$true)]   $adminPassword ) #可选参数 $azureLocation = "South Central US" $azureImageName = "a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-R2-201410.01-en.us-127GB.vhd" $azureInstanceSize = "Large" $azureFESubnetName = "Frontend" $azureFEStaticIP = "192.168.0.254" $azureBESubnetName = "Backend" $azureBEStaticIP = "192.168.1.254" #函数 function NewAzureStorageAccount {   param($account, $location)   #检查帐户是否已存在   $blob = Get-AzureStorageAccount -StorageAccountName $account -ErrorAction SilentlyContinue -WarningAction SilentlyContinue -Verbose:$false   #如不存在,请创建   if(!($blob))   {     Write-Host "Creating Storage Account..."     New-AzureStorageAccount -StorageAccountName $account -Location $location -Verbose:$false -WarningAction SilentlyContinue | Out-Null          #在继续之前确保已完成创建     while ((Get-AzureStorageAccount -StorageAccountName $account -WarningAction SilentlyContinue).StorageAccountStatus -ne "Created")     {       Start-Sleep 5     }     Write-Host "Storage Account Created"   }   else   {     Write-Host "Storage account already exists, skipping"   } } function NewAzureStorageContainer {   param($name)   #检查容器是否已存在   $container = Get-AzureStorageContainer -Name $name -ErrorAction SilentlyContinue   #如不存在,请创建   if(!($container))   {     Write-Host "Creating Storage Container..."     New-AzureStorageContainer -Name $name -Verbose:$false | Out-Null     Write-Host "Storage Container Created"   }   else   {     Write-Host "Storage container already exists, skipping"   } } function NewAzureService {   param($name, $location)   #检查服务是否已存在   $service = Get-AzureService -ServiceName $name -ErrorAction SilentlyContinue -WarningAction SilentlyContinue -Verbose:$false   #如不存在,请创建   if(!($service))   {     Write-Host "Creating Cloud Service..."     New-AzureService -ServiceName $name -Location $location -Verbose:$false -WarningAction SilentlyContinue | Out-Null     Write-Host "Cloud Service Created"   }   else   {     Write-Host "cloud service already exists, skipping"   } } #导入 Azure PowerShell 模块 Import-Module Azure #导入 Azure 设置文件 Import-AzurePublishSettingsFile -PublishSettingsFile $azureSettingsFile | Out-Null #创建存储 NewAzureStorageAccount -account $azureName -location $azureLocation #使用存储设置 Azure 订阅 Set-AzureSubscription -CurrentStorageAccountName $azureName -SubscriptionName ((Get-AzureSubscription).SubscriptionName) #创建存储容器 NewAzureStorageContainer -name vhds #创建云服务 NewAzureService -name $azureName -location $azureLocation #设置 VM 大小和映像 $vm = New-AzureVMConfig -Name $azureName -InstanceSize $azureInstanceSize -ImageName $azureImageName #设置 VM 凭据 Add-AzureProvisioningConfig -VM $vm -Windows -AdminUsername $adminUserName -Password $adminPassword #设置 VM 前端网络子网、静态 IP 和公用 IP Set-AzureSubnet -SubnetNames $azureFESubnetName -VM $vm Set-AzureStaticVNetIP -IPAddress $azureFEStaticIP -VM $vm Set-AzurePublicIP -PublicIPName $azureName -VM $vm #设置 VM 后端网络子网和静态 IP Add-AzureNetworkInterfaceConfig -Name $azureBESubnetName -SubnetName $azureBESubnetName -StaticVNetIPAddress $azureBEStaticIP -VM $vm #创建 VM New-AzureVM -ServiceName $azureName -VNetName $azureName -VM $vm

如果你有任何疑问 , 欢迎访问 MSDN 社区,由专家来为您解答 Windows Azure各种技术问题,或者拨打世纪互联客户服务热线 400-089-0365/010-84563652咨询各类服务信息。

希望此脚本可以作为示例 , 帮助您在环境中自动创建此类 VM 。

本文翻译自: http://blogs.msdn.com/b/rslaten/archive/2014/11/18/create-a-multi-nic-vm-with-a-public-ip-in-azure.aspx

正文到此结束
Loading...