在某些環境下,PIP是Azure上的一種比較好的解決方案處理一些特殊的環境。比如大量的埠需要開啟、向外部的訪問非常多等等。
但目前,Azure的Reserved IP address不用應用到PIP上,只能應用到VIP上。
但當使用者需要使用PIP,又需要一個固定的連線方式時,我們建議採用DNS域名的方式來實現。
對於一個Azure上的虛擬機器:
預設是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 |
0 |
InstanceName |
hwubt1 |
InstanceUpgradeDomain |
0 |
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 |
0 |
InstanceName |
hwubt1 |
InstanceUpgradeDomain |
0 |
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地址沒有變。