在某些环境下,PIP是Azure上的一种比较好的解决方案处理一些特殊的环境。比如大量的端口需要打开、向外部的访问非常多等等。

但目前,Azure的Reserved IP address不用应用到PIP上,只能应用到VIP上。

但当用户需要使用PIP,又需要一个固定的连接方式时,我们建议采用DNS域名的方式来实现。

对于一个Azure上的虚拟机:

Azure Public IP DNS域名-LMLPHP

默认是VIP地址映射虚拟机。但当开启了PIP后,默认向外访问的地址为PIP地址。PIP具体方法见:http://www.cnblogs.com/hengwei/p/4779166.html

此时的PIP是不能预留IP地址的。如果不配置,这个地址也没有默认的DNS域名。如果VM关机等情况,其IP地址更换,将影响客户的应用。

我们可以通过增加PIP DNS域名的方法解决这个问题。

通过Powershell配置:

Get-AzureVM

ServiceName Name Status

----------- ---- ------

hwmysql hwubt1 ReadyRole

get-azurevm -ServiceName hwmysql -Name hwubt1 | set-AzurePublicIP -PublicIPName hwpip -DomainNameLabel hwpip | Update-AzureVM

OperationDescription         OperationId              OperationStatus

--------------------             -----------                 ---------------

Update-AzureVM         785ce71c-c5a6-42f5-84e0-a5dcea6b47b5     Succeeded

get-azurevm -ServiceName hwmysql -Name hwubt1

DeploymentName

hwmysql1

Name

hwubt1

Label

VM

Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVM

InstanceStatus

RoleStateUnknown

IpAddress

10.1.1.100

InstanceStateDetails

PowerState

Started

InstanceErrorCode

InstanceFaultDomain

InstanceName

hwubt1

InstanceUpgradeDomain

InstanceSize

Standard_D1

HostName

hwubt1

AvailabilitySetName

DNSName

http://hwmysql.chinacloudapp.cn/

Status

RoleStateUnknown

GuestAgentStatus

Microsoft.WindowsAzure.Commands.ServiceManagement.Model.GuestAgentStatus

ResourceExtensionStatusList

{}

PublicIPAddress

42.159.236.183

PublicIPName

hwpip

PublicIPDomainNameLabel

hwpip

PublicIPFqdns

{hwpip.hwmysql.chinacloudapp.cn hwpip.0.hwmysql.chinacloudapp.cn}

NetworkInterfaces

{}

VirtualNetworkName

hwvnet

ServiceName

hwmysql

OperationDescription

Get-AzureVM

OperationId

dac94b4d49994ea292b82499bbb3503c

OperationStatus

OK

其中-DomainNameLabel hwpip是指明需要DNS域名的参数,添加了这个参数,可以在get-azurevm中看到这个PIP地址以及关联了hwpip.hwmysql.chinacloudapp.cn的域名。

这时在cmd中解析:

nslookup hwpip.hwmysql.chinacloudapp.cn

Server: xxxx

Address: x.x.x.x

Name: hwpip.hwmysql.chinacloudapp.cn

Address: 42.159.236.183

这时此PIP地址已经可以通过DNS解析到。

我们通过Powershell释放VM的资源:

stop-azurevm -ServiceName hwmysql -Name hwubt1

OperationDescription     OperationId             OperationStatus

--------------------         -----------                 ---------------

Stop-AzureVM     4d9929b7-351e-4452-afd5-7596d6061b75     Succeeded

此时通过get-azurevm可以看到PIP地址以及释放:

DeploymentName

hwmysql1

Name

hwubt1

Label

VM

Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVM

InstanceStatus

StoppedDeallocated

IpAddress

InstanceStateDetails

PowerState

Stopped

InstanceErrorCode

InstanceFaultDomain

InstanceName

hwubt1

InstanceUpgradeDomain

InstanceSize

Standard_D1

HostName

AvailabilitySetName

DNSName

http://hwmysql.chinacloudapp.cn/

Status

StoppedDeallocated

GuestAgentStatus

ResourceExtensionStatusList

{}

PublicIPAddress

PublicIPName

PublicIPDomainNameLabel

PublicIPFqdns

{}

NetworkInterfaces

{}

VirtualNetworkName

hwvnet

ServiceName

hwmysql

OperationDescription

Get-AzureVM

OperationId

6534b10dc6054872a495700ddf7ff49b

OperationStatus

OK

通过start-azurevm开机,再观察PIP情况:

DeploymentName

hwmysql1

Name

hwubt1

Label

VM

Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVM

InstanceStatus

ReadyRole

IpAddress

10.1.1.100

InstanceStateDetails

PowerState

Started

InstanceErrorCode

InstanceFaultDomain

InstanceName

hwubt1

InstanceUpgradeDomain

InstanceSize

Standard_D1

HostName

hwubt1

AvailabilitySetName

DNSName

http://hwmysql.chinacloudapp.cn/

Status

ReadyRole

GuestAgentStatus

Microsoft.WindowsAzure.Commands.ServiceManagement.Model.GuestAgentStatus

ResourceExtensionStatusList

{}

PublicIPAddress

42.159.239.59

PublicIPName

hwpip

PublicIPDomainNameLabel

hwpip

PublicIPFqdns

{hwpip.hwmysql.chinacloudapp.cn hwpip.0.hwmysql.chinacloudapp.cn}

NetworkInterfaces

{}

VirtualNetworkName

hwvnet

ServiceName

hwmysql

OperationDescription

Get-AzureVM

OperationId

945a9299ff6647af8398f2f07fc17b31

OperationStatus

OK

此时再进行DNS解析:

nslookup hwpip.hwmysql.chinacloudapp.cn

Server: xxxx

Address: x.x.x.x

Name: hwpip.hwmysql.chinacloudapp.cn

Address: 42.159.239.59

可以观察到,PIP地址发生变化,但DNS地址没有变。

05-04 08:35