新建Azure VM或者對現有的VM使用PIP

 在前兩篇的博客中主要講解了對VIP的固定,VIP是針對雲服務,而有時我們需要針對虛擬機的固定,比如當我做FTP服務器的時候,如果使用VIP的話,我們需要在外部防火牆內針對主動可被動端口開啓許多,給我們的部署帶來了許多的麻煩,這時候PIP就比較適合我們了,PIP可以直接穿透外部防火牆到虛擬機,不在單獨在外部防火牆中開啓這麼多的端口,但是PIP的這個特性也決定了他的不安全性,同時PIP 在固定但是虛擬機重啓後也會改變,這是我們在使用時也是需要特別注意的。

  廢話不多少了,直接開始動手實驗吧:


  1. 創建虛擬機並得到一個VIP


wKioL1V6UsmgUkayAAFw8XsisdY599.jpg

wKiom1V6USKAuqIjAAGmvA56Mys685.jpg


2. 從公網申請PIP地址並分配給現有的VM Instance


wKioL1V6U1KQoyr3AAQQlWG3njc196.jpg

wKiom1V6UaqSsQ80AAM7D_xa4sM757.jpg


3. 查看PIP


wKiom1V6Un2zuCv5AAWmWmw2zOY441.jpg


4. VM重啓

wKiom1V6UsSAG_LrAADimfjsCI8451.jpg


5. 再次查看PIP,IP已經發生了改變


wKioL1V6VCXB35bIAAS9FyugEaQ577.jpg


備註:及時PIP使用powershell固定後VM重啓也會改變



 在新建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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章