在前两篇的博客中主要讲解了对VIP的固定,VIP是针对云服务,而有时我们需要针对虚拟机的固定,比如当我做FTP服务器的时候,如果使用VIP的话,我们需要在外部防火墙内针对主动可被动端口开启许多,给我们的部署带来了许多的麻烦,这时候PIP就比较适合我们了,PIP可以直接穿透外部防火墙到虚拟机,不在单独在外部防火墙中开启这么多的端口,但是PIP的这个特性也决定了他的不安全性,这是我们在使用时也是需要特别注意的。
废话不多少了,直接开始动手实验吧:
从公网申请PIP地址并分配给现有的VM Instance
PS C:\> Get-AzureVM -ServiceName jeffcentos -Name centosPIP | Set-AzurePublicIP -PublicIPName jeffPIP2 | Update-AzureVM
详细信息: 19:17:38 - Completed Operation: Get Deployment
详细信息: 19:17:41 - Completed Operation: Get Deployment
详细信息: 19:17:41 - Begin Operation: Update-AzureVM
详细信息: 19:18:12 - Completed Operation: Update-AzureVM
OperationDescription OperationId OperationStatus
-------------------- ----------- ---------------
Update-AzureVM 57d21c72-4fe0-448e-9bb8-b13e1b4b50c0 Succeeded
2. 在新建VM时保留PIP
(1)首先使用命令从公网获得一个PIP
PS C:\> New-AzureReservedIP –ReservedIPName "JEFFPIP" –Label "jeffPIP" –Location "China North"
详细信息: 18:54:18 - Begin Operation: New-AzureReservedIP
详细信息: 18:54:51 - Completed Operation: New-AzureReservedIP
OperationDescription OperationId OperationStatus
-------------------- ----------- ---------------
New-AzureReservedIP b882b7f3-8661-4d37-a92a-8360ba520cd1 Succeeded
(2)查看成功获得的PIP
PS C:\> Get-AzureReservedIP
详细信息: 18:55:52 - Begin Operation: Get-AzureReservedIP
详细信息: 18:55:53 - Completed Operation: Get-AzureReservedIP
ReservedIPName : JEFFPIP
Address : 139.219.14.132
Id : 35b80824-29b8-4491-bd10-2fec1922048a
Label : jeffPIP
Location : China North
State : Created
InUse : False
ServiceName :
DeploymentName :
OperationDescription : Get-AzureReservedIP
OperationId : a1b79933-22f2-4a15-a2ea-61b94764e066
OperationStatus : Succeeded
(3)使用映像或者磁盘在创建VM的时候使用此PIP(这里主要演示使用映像创建的)
PS C:\> New-AzureVMConfig -Name ‘centos‘ -InstanceSize Small -ImageName jeffcentos-20150402-800866 | Add-AzureProvisioni
ngConfig -Linux -LinuxUser "azureuser" -Password "P@ssw0rd123" | New-AzureVM -ServiceName "testpip" –ReservedIPName "JEF
FPIP" -VNetName ‘chinnort‘
警告: Subnet should be specified when deploying VMs in a VNET: centos
详细信息: 19:03:16 - Begin Operation: New-AzureVM - Create Deployment with VM centos
详细信息: 19:04:23 - Completed Operation: New-AzureVM - Create Deployment with VM centos
OperationDescription OperationId OperationStatus
-------------------- ----------- ---------------
New-AzureVM 03626a98-22ed-45b0-bd3f-5c8f66a57067 Succeeded
(4)查看已经使用PIP的VM
PS C:\> Get-AzureReservedIP
详细信息: 19:09:16 - Begin Operation: Get-AzureReservedIP
详细信息: 19:09:19 - Completed Operation: Get-AzureReservedIP
ReservedIPName : JEFFPIP
Address : 139.219.14.132
Id : 35b80824-29b8-4491-bd10-2fec1922048a
Label : jeffPIP
Location : China North
State : Created
InUse : True
ServiceName : testpip
DeploymentName : testpip
OperationDescription : Get-AzureReservedIP
OperationId : c2494b48-d504-4535-b885-ee45043dd785
OperationStatus : Succeeded
备注:在我们创建的时候有时候会遇到下面这个错误:
PS C:\> New-AzureVMConfig -Name ‘centos‘ -InstanceSize Small -ImageName jeffcentos-jeffcentos-0-201504020640350599 | Add-AzureProvisioningConfig -Linux -LinuxUser "azureuser" -Password "P@ssw0rd123" | New-AzureVM -ServiceName "testpip" –ReservedIPName "JEFFPIP" -VNetName ‘chinnort‘
New-AzureVMConfig : Must specify MediaLocation or set a current storage account using Set-AzureSubscription.
所在位置 行:1 字符: 1
+ New-AzureVMConfig -Name ‘centos‘ -InstanceSize Small -ImageName jeffcentos-jeffc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-AzureVMConfig], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.NewAzure
VMConfigCommand
主要使我们在此订阅下有多个存储账号,这里是要求你制定一个存储账号来存储VM,使用一下办法解决
PS C:\> Set-Set-AzureSubscription -SubscriptionName "订阅账号" -CurrentStorageAccountName "存储账号"。
查看存储账号:Get-AzureStorageAccount
本文出自 “jeff-微软公有云” 博客,请务必保留此出处http://jeffcsc.blog.51cto.com/8669937/1634232
原文地址:http://jeffcsc.blog.51cto.com/8669937/1634232