云服务中的实例级公共 IP 地址配置
本文介绍如何在 Microsoft Azure 云端服务(经典)和 Azure 云服务(扩展支持)中配置实例级公共 IP 地址(PIP)。 与虚拟 IP 地址(VIP)不同,实例级公共 IP 地址不负载均衡。 VIP 分配给云服务,云服务中的所有虚拟机和角色实例共享该 VIP。 但是,公共 IP 地址(PIP)仅与单个实例的网络适配器相关联。 公共 IP 地址在多实例部署中非常有用,其中每个实例都可以独立于 Internet 访问。 下图说明了 PIP 的值,并将其与 VIP 区分开来。
在图中,发送到 VIP 的网络流量显示为数据中心 IP 地址 (DIP) 1 和 DIP 2 之间的负载均衡。 但是,发送到 PIP 1 的流量始终会转到 DIP 1,发送到 PIP 2 的流量始终会发送到 DIP 2。 数据中心 IP 地址是虚拟机(VM)的专用 IP 地址。
有关详细信息,请参阅 Azure 博客文章的实例级公共 IP 地址 。
Azure 云服务(经典)的过程
按角色配置实例级公共 IP 地址:
<?xml version="1.0" encoding="utf-8"?> <ServiceConfiguration serviceName="TestVirtualnetwork" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="6" osVersion="*" schemaVersion="2015-04.2.6"> <Role name="WebRole1"> <Instances count="1" /> <ConfigurationSettings> <Setting name="APPINSIGHTS_INSTRUMENTATIONKEY" value="xxx" /> </ConfigurationSettings> </Role> <Role name="WebRole2"> <Instances count="1" /> <ConfigurationSettings> <Setting name="APPINSIGHTS_INSTRUMENTATIONKEY" value="xxx" /> </ConfigurationSettings> </Role> <Role name="WebRole3"> <Instances count="1" /> <ConfigurationSettings> <Setting name="APPINSIGHTS_INSTRUMENTATIONKEY" value="xxx" /> </ConfigurationSettings> </Role> <Role name="WebRole4"> <Instances count="1" /> <ConfigurationSettings> <Setting name="APPINSIGHTS_INSTRUMENTATIONKEY" value="xxx" /> </ConfigurationSettings> </Role> <NetworkConfiguration> <VirtualNetworkSite name="Group RESOURCE_GROUP VIRTUAL_NETWORK_NAME" /> <AddressAssignments> <InstanceAddress roleName="WebRole1"> <Subnets><Subnet name="subnet001" /></Subnets> <PublicIPs> <PublicIP name="PubIP" domainNameLabel="pip" /> <!-- with domain --> </PublicIPs> </InstanceAddress> <InstanceAddress roleName="WebRole2"> <Subnets><Subnet name="subnet003" /></Subnets> <PublicIPs> <PublicIP name="PubIP"/> <!-- without domain --> </PublicIPs> </InstanceAddress> </AddressAssignments> </NetworkConfiguration> </ServiceConfiguration>
使用以下方法之一获取角色的当前公共 IP 地址。
对于每个角色实例,请运行 Get-AzureRole PowerShell cmdlet。 此 cmdlet 基于模块
Azure.Service
。 通过使用上一步中的 IP 地址配置,可以看到每个角色实例的实例详细信息之间的差异。查看角色的详细信息
WebRole2
,其公共 IP 名称没有域名标签:$roleParams = @{ ServiceName = "<cloud-service-name>" Slot = "Production" RoleName = "WebRole2" InstanceDetails = $true } Get-AzureRole @roleParams
cmdlet 输出类似于以下文本:
InstanceEndpoints : {Microsoft.WindowsAzure.Plugins.RemoteForwarder.RdpInput, Endpoint1} InstanceErrorCode : InstanceFaultDomain : 0 InstanceName : WebRole2_IN_0 InstanceSize : Standard_D1_v2 InstanceStateDetails : InstanceStatus : ReadyRole InstanceUpgradeDomain : 0 RoleName : WebRole2 DeploymentID : 0123456789abcdef0123456789abcdef IPAddress : 10.2.2.5 PublicIPAddress : 20.115.22.157 PublicIPName : PubIP PublicIPIdleTimeoutInMinutes : PublicIPDomainNameLabel : PublicIPFqdns : {} ServiceName : contoso-vnet-pip OperationDescription : Get-AzureRole OperationId : 12345678-9abc-def0-1234-56789abcdef0 OperationStatus : Succeeded
现在,查看角色的详细信息
WebRole1
,该角色使用相同的公共 IP 名称,但也具有域名标签:$roleParams = @{ ServiceName = "<cloud-service-name>" Slot = "Production" RoleName = "WebRole1" InstanceDetails = $true } Get-AzureRole @roleParams
在 cmdlet 输出中,
InstanceEndpoints
、InstanceName
、InstanceStatus
、RoleName
IPAddress
、PublicIPAddress
、、PublicIPDomainNameLabel
和PublicIPFqdns
OperationId
值不同:InstanceEndpoints : {Endpoint1} InstanceErrorCode : InstanceFaultDomain : 0 InstanceName : WebRole1_IN_0 InstanceSize : Standard_D1_v2 InstanceStateDetails : InstanceStatus : StoppedVM InstanceUpgradeDomain : 0 RoleName : WebRole1_IN_0 DeploymentID : 0123456789abcdef0123456789abcdef IPAddress : 10.2.0.4 PublicIPAddress : 20.168.229.192 PublicIPName : PubIP PublicIPIdleTimeoutInMinutes : PublicIPDomainNameLabel : pip PublicIPFqdns : {pip.contoso-vnet-pip.cloudapp.net, pip.0.contoso-vnet-pip.cloudapp.net} ServiceName : contoso-vnet-pip OperationDescription : Get-AzureRole OperationId : 23456789-abcd-ef01-2345-6789abcdef01 OperationStatus : Succeeded
Azure 云服务过程(扩展支持)
按角色配置实例级公共 IP 地址:
<?xml version="1.0" encoding="utf-16"?> <ServiceConfiguration xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" serviceName="Test_cloudservice" osFamily="6" osVersion="*" schemaVersion="2015-04.2.6" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration"> <Role name="TestWebRole"> <ConfigurationSettings> <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" /> </ConfigurationSettings> <Instances count="2" /> </Role> <Role name="TestWorkerRole"> <ConfigurationSettings> <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" /> </ConfigurationSettings> <Instances count="1" /> </Role> <NetworkConfiguration> <VirtualNetworkSite name="test001VNet" /> <AddressAssignments> <InstanceAddress roleName="TestWebRole"> <Subnets> <Subnet name="default" /> </Subnets> <PublicIPs> <PublicIP name="PubIP" domainNameLabel="pip" /> </PublicIPs> </InstanceAddress> <InstanceAddress roleName="TestWorkerRole"> <Subnets> <Subnet name="default" /> </Subnets> </InstanceAddress> <ReservedIPs> <ReservedIP name="Group TESTCSES cses-prod" /> </ReservedIPs> </AddressAssignments> </NetworkConfiguration> </ServiceConfiguration>
使用 CloudService 中的 PublicIPAddress - 列出云服务公共 IP 地址 REST API 获取网络适配器的公共 IP 地址。 以下代码片段显示了一个示例 JSON 响应:
{ "value": [ { "name": "PubIP", "id": "/subscriptions/<your-subscription-guid>/resourceGroups/TESTCSES/providers/Microsoft.Compute/cloudServices/testcsesv2/roleInstances/TestWebRole_IN_0/networkInterfaces/nic1/ipConfigurations/ipconfig1/publicIPAddresses/PubIP", "etag": "W/\"3456789a-bcde-f012-3456-789abcdef012\"", "location": "eastus", "properties": { "provisioningState": "Succeeded", "resourceGuid": "<your-resource-guid>", "ipAddress": "20.169.153.231", "publicIPAddressVersion": "IPv4", "publicIPAllocationMethod": "Dynamic", "idleTimeoutInMinutes": 4, "dnsSettings": { "domainNameLabel": "pip.0.cses-prod", "fqdn": "pip.0.cses-prod.eastus.cloudapp.azure.com" }, "ipTags": [], "ipConfiguration": { "id": "/subscriptions/<your-subscription-guid>/resourceGroups/TESTCSES/providers/Microsoft.Compute/cloudServices/testcsesv2/roleInstances/TestWebRole_IN_0/networkInterfaces/nic1/ipConfigurations/ipconfig1" } }, "sku": { "name": "Basic", "tier": "Regional" } }, { "name": "PubIP", "id": "/subscriptions/<your-subscription-guid>/resourceGroups/TESTCSES/providers/Microsoft.Compute/cloudServices/testcsesv2/roleInstances/TestWebRole_IN_1/networkInterfaces/nic1/ipConfigurations/ipconfig1/publicIPAddresses/PubIP", "etag": "W/\"456789ab-cdef-0123-4567-89abcdef0123\"", "location": "eastus", "properties": { "provisioningState": "Succeeded", "resourceGuid": "<your-resource-guid>", "ipAddress": "20.231.68.190", "publicIPAddressVersion": "IPv4", "publicIPAllocationMethod": "Dynamic", "idleTimeoutInMinutes": 4, "dnsSettings": { "domainNameLabel": "pip.1.cses-prod", "fqdn": "pip.1.cses-prod.eastus.cloudapp.azure.com" }, "ipTags": [], "ipConfiguration": { "id": "/subscriptions/<your-subscription-guid>/resourceGroups/TESTCSES/providers/Microsoft.Compute/cloudServices/testcsesv2/roleInstances/TestWebRole_IN_1/networkInterfaces/nic1/ipConfigurations/ipconfig1" } }, "sku": { "name": "Basic", "tier": "Regional" } } ] }
尽管数组中的 value
两个 name
对象都具有键值 PubIP
,但相应 properties
密钥中的 IP 地址和 DNS 设置存在差异。 键ipAddress
在第一个数组对象和第20.231.68.190
二个数组对象中具有值20.169.153.231
。 键dnsSettings
在第一个数组对象和第pip.1.cses-prod
二个数组对象中具有值pip.0.cses-prod
。
联系我们寻求帮助
如果你有任何疑问或需要帮助,请创建支持请求或联系 Azure 社区支持。 你还可以将产品反馈提交到 Azure 反馈社区。