问题描述
在云中环境,部署的应用到云服务(Cloud Service)都是动态的IP地址,所以在添加DNS记录的时候,都是使用CNAME,但如果需要在DNS中添加A记录,则需要一个固定IP。
解决方案
Azure提供了保留IP的服务,可以通过New-AzureReservedIP命令来创建。然后再云服务(Cloud Service)中使用。操作步骤如下:
步骤一:通过powershell 命令进行创建保留IP
New-AzureReservedIP -ReservedIPName $Name - -Location $Location
- Get-AzureReservedIP 查看创建的保留地址
- Remove-AzureReservedIPAssociation 解除保留IP地址
步骤二:修改Cloud Service配置文件,把ReservedIP与Cloud Service关联,然后重新发布文件
<?xml version="1.0" encoding="utf-8"?> <ServiceConfiguration serviceName="AzureCloudService2" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="6" osVersion="*" schemaVersion="2015-04.2.6"> <Role name="WebRole1"> <Instances count="1" /> <ConfigurationSettings> </ConfigurationSettings> </Role> <NetworkConfiguration> <AddressAssignments> <ReservedIPs> <ReservedIP name="MyPassIp2"/> </ReservedIPs> </AddressAssignments> </NetworkConfiguration> </ServiceConfiguration>
或通过Powershell命令进行绑定
Set-AzureReservedIPAssociation -ReservedIPName MyPassIp2 -ServiceName <cloud service name>
附加因ReservedIP而引发的错误
1) 云服务在更新发布后无法修改RDP的密码,修改时出现错误消息:ReservedIP was not mapped to an endpoint. The service definition must contain atleast one endpoint that maps to the ReservedIP.
【答】根据错误消息提示,查看到是ReservedIP地址没有绑定endpoint推断是新发布的配置文件中遗漏了该Cloud Service的ReservedIP配置部分。所以需要先解绑ReservedIP,重新绑定。 也可以再解绑后修改RDP密码。修改成功后重新绑定ReservedIP. 解决问题的过程中使用的命令正是:
Remove-AzureReservedIPAssociation -ReservedIPName <ReservedIPName> -ServiceName <ServiceName > Set-AzureReservedIPAssociation -ReservedIPName <ReservedIPName> -ServiceName <ServiceName >
参考文档
Azure 云服务的配置 NetworkConfiguration 架构: https://docs.azure.cn/zh-cn/cloud-services/schema-cscfg-networkconfiguration
New-AzureReservedIP: https://docs.microsoft.com/en-us/powershell/module/servicemanagement/azure.service/new-azurereservedip?view=azuresmps-4.0.0