標籤:windows azure 配置實現虛擬機器外網ip綁定(雲端服務)
Windows Azure 配置實現虛擬機器外網IP綁定(雲端服務)
我們上一篇介紹了如何對已存在的虛擬網路的外網IP做綁定,今天主要介紹配置實現虛擬機器外網綁定,兩者區別在於一個已存在,一個不存在,如果不存在的話,我們需要建立一個雲端服務,同時對建立的雲端服務做標記,標記後,可建立對應得虛擬機器來完成外網IP綁定,具體見下:首先注意配置保留虛擬機器外網IP需要注意以下事項
一、 操作前的注意事項:
1. 如果虛擬機器要使用虛擬網路,只能在Regional SLB/VPC Operations and Maintenance System中使用ReservedIP,已經有部署的基於地緣組的虛擬網路無法直接轉換為Regional SLB/VPC Operations and Maintenance System
2. 這個操作目前只能由PowerShell完成
3. 必須先建立一個ReservedIP,再建立虛擬機器
4. 目前ReservedIP可以應用到掛載在地區虛擬網路下的虛擬機器,為其保留公網IP
5. ReservedIP是計費的
關閉虛擬機器不會釋放掉保留的RIP,但是當雲端服務中所有虛擬機器都刪除後,RIP會被釋放,但並不會被從訂閱中刪除,您可以用來綁定到其他雲端服務中的虛擬機器。
二、 建立Regional SLB/VPC Operations and Maintenance System:
在門戶的虛擬網路中建立新的虛擬網路,由於目前預設建立為“地區虛擬網路”,所以直接在虛擬網路中建立即為地區虛擬網路。
三、下載並匯入Publishsettings File
四、 建立ReservedIP
五、 在ReservedIP中建立新的虛擬機器:
5.1指定當前的SubID和StorageAccount
Set-AzureSubscription -SubscriptionName "XXXX" -CurrentStorageAccountName "
標黃處分別為SubID的名稱,即是之前在Publishsettings裡中修改的Name欄位
後面的是儲存帳號的名稱,如果對應的地區無儲存帳號,則需要建立一個
5.2列出當前的Image列表之後,列出當前的Image列表:
輸入:
(Get-AzureVMImage)|Format-Table -Property imagename,PublishedDate –AutoSize
該操作會列出當前所有映像的名稱和發布日期。預設情況下請選擇時間最新的版本。請先複製imagename全文備用
六、 驗證ReservedIP是否生效:
七、 刪除ReservedIP:
由於ReservedIP是收費的,如果不想使用了,可以刪除。 使用命令:Remove-AzureReservedIP -ReservedIPName "frankVIP"
具體操作見習:
首先是下載及安裝powershell
我們都知道windows azure的相關操作都是依賴於windows azure for powershell來做管理的,所以我們需要安裝azure powershell
通過以下方法就可以下載windowsazure訂閱
https://manage.windowsauzre.cn/publishsettings
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M01/6F/C6/wKiom1Wn2aygLgvZAAHD57DOIt4075.jpg" height="338" />
然後下載並且安裝windowsazure powershell,然後在windowsazure powershell下匯入該訂閱檔案;
訪問www.windowsazure.cn ---> 文檔和資源---> azure 命令列介面---->windows安裝就會提示下載windowsazure powershell
我們同樣可以查看上面的windows powershell的相關文檔
http://www.windowsazure.cn/documentation/articles/install-configure-powershell/
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M02/6F/C6/wKiom1Wn2ayCAY6sAAFROdt_EY4095.jpg" height="318" />
Azure powershell 下載連結,下載的時候選擇0.9.3版本
https://github.com/Azure/azure-powershell/releases
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M00/6F/C6/wKiom1Wn2azhNQ9IAADXNBRCbuw533.jpg" height="310" />
具體方法可以瀏覽網頁內部
下載後就是安裝,根據提示安裝完powershell即可;我們可以通過
(get-module azure).version
查單當前使用的azure powershell版本
註:執行以下命令需要使用版本為0.9.3的azure powershell,不能用0.9.4的azure powershell,如果安裝了最新的卸載 後安裝就版本
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M01/6F/C3/wKioL1Wn24jAarGXAACPSQ_zPuQ564.jpg" height="244" />
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M01/6F/C6/wKiom1Wn2a2iDhxSAADJSME-tmg049.jpg" height="342" />
Import-AzurePublishSettingsFile 匯入 .publishsettings 檔案以供模組使用
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M00/6F/C6/wKiom1Wn2a2AniZSAADt6NdxCzI501.jpg" height="343" />
因為我已經匯入過了,所以再次匯入會提示以下資訊
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M00/6F/C3/wKioL1Wn24ngyNxHAAE8UzCVUbc999.jpg" height="319" />
如果在windowsazure powershell中匯入多個訂閱檔案的話,我們需要選擇預設的
我們首先通過get-azuresubscrpit 查看當前powershell下已匯入的訂閱檔案
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M01/6F/C3/wKioL1Wn24nBKMAlAAESaswLKRg273.jpg" height="309" />
我們發現有兩個,所以我們需要通過以下命令來設定預設的即可
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M01/6F/C3/wKioL1Wn24mS0tGwAACIviFLvCo342.jpg" height="67" />
Select-azuresubscript -subsciptionName "xxxxx" -default
然後我們可以
Get-azurevm 查看當前訂閱性的所有vm資訊
“ServiceName” 為雲端服務名字,”name“為虛機名字
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M02/6F/C3/wKioL1Wn24nwu-BvAABvLxhocD8354.jpg" height="105" />
我們首先需要建立一個Reservedip( 無法具體指定某個 IP ,此操作 AzureAzure Azure平台會為客戶隨機指定一個 平台會為客戶隨機指定一個 VIP) VIP) :
$ReservedIP = New-AzureReservedIP -ReservedIPName "RVIP" -Label "testvip" -Location "China North"
-ReservedIPName的命名可以任意定義;在此我定義為:RVIP
-Label 為描述 在此我藐視為testvip
-Location 為地區,必須和虛擬網路同區
建立完成
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M02/6F/C6/wKiom1Wn2a7j1wZ6AACXcIU5D24662.jpg" height="120" />
我們通過get-azurereservedip查看具體的保留ip資訊,如果還沒有部署,sevicename(代表雲端服務名稱),DeploymentName(代表虛擬名稱)將為空白
get-azurereservedip -ReservedipName RVIP
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M00/6F/C3/wKioL1Wn24rRfNrIAAEDF7RyAGo852.jpg" height="267" />
我們當然也可以通過get-azurereservedip 查看所有的reservedip
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M00/6F/C3/wKioL1Wn24qgZbQ_AAFpBbcnlOs634.jpg" height="344" />
然後我們在reservedip中建立虛擬機器
1指定當前的SubID和StorageAccount (否則建立虛擬機器會報錯)
Set-AzureSubscription -SubscriptionName "XXXX" -CurrentStorageAccountName "YYYY"
標黃處分別為SubID的名稱,即是之前在Publishsettings裡中修改的Name欄位
後面的是儲存帳號的名稱,如果對應的地區無儲存帳號,則需要建立一個
查看儲存賬戶及subscriptionname
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M00/6F/C6/wKiom1Wn2a7TavFPAACvVnIdSjY796.jpg" height="303" />
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M02/6F/C3/wKioL1Wn24qAeWGQAACiF7qCnGQ993.jpg" height="257" />
Set-AzureSubscription -SubscriptionName "MSDN Ultimate" -CurrentStorageAccountName "iternaldata"
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M01/6F/C6/wKiom1Wn2a6wkwoBAABYJq4o5Ac376.jpg" height="50" />
2列出當前的Image列表,記錄需要使用的映像的排列數字:輸入:
(Get-AzureVMImage)|Format-Table -Property label,PublishedDate –AutoSize
該操作會列出當前所有映像名稱和發布日期。預設會選擇最新的版本
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M00/6F/C3/wKioL1Wn24qxCbDhAALWL2h7aKw782.jpg" height="328" />
(Get-AzureVMImage)|Format-Table -Property imagename,PublishedDate –AutoSize
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M02/6F/C3/wKioL1Wn24uhc3NHAAK12cmFOho728.jpg" height="300" />
我們複製選擇出自己選擇的imasgename
55bc2b193643443bb879a78bda516fc8__Windows-Server-2012-R2-201502.01-zh.cn-127GB.vhd
確認資訊後,開始在reservedip中部署虛擬機器
如果需要建立windows虛擬機器代碼如下:
New-AzureVMConfig -Name "windows"[F4] -InstanceSize Small -ImageName (get-azurevmimage)[29].ImageName[F5] | Add-AzureProvisioningConfig -Windows -AdminUsername gavin -Password Password2015 | New-AzureVM -ServiceName "CustomCloud"[F6] –ReservedIPName "RVIP"[F7] -Location "China North"[F8]Commented [F4]: 定義 該新的 VM 配置 檔案名稱Commented [F5]: 指定 要使用的 ImageImageImageImageImage Name,Name,Name,Name,Name,把之前複製 的粘貼過來Commented [F6]: 建立 雲端服務的名稱Commented [F7]: 指定 要應用的 ReservedIPReservedIPReservedIPReservedIPReservedIPReservedIPReservedIPReservedIPReservedIPReservedIPCommented [F8]: 生效 的位置( 要與 之前 一致 ))Commented [F10]: 定義 該新的 VM 配置 檔案名稱Commented [F11]: 建立 雲端服務的名稱Commented [F12]: 指定 要應用的 ReservedIPReservedIPReservedIPReservedIPReservedIPReservedIPReservedIPReservedIPReservedIPReservedIPCommented [F13]: 生效 的位置( 要與 之前 一致 ))
My Code如下:
New-AzureVMConfig -Name "Winodws" -InstanceSize Large -ImageName "55bc2b193643443bb879a78bda516fc8__Windows-Server-2012-Datacenter-201502.01-zh.cn-127GB.vhd" | Add-AzureProvisioningConfig -Windows -AdminUsername gavin -Password Password2015 | New-AzureVM -ServiceName "CustomCloud" –ReservedIPName "RVIP" -Location "China North"
如需建立在vnet內部則在 -Location "XXX"後面再添加 –SLB/VPC Operations and Maintenance SystemName “vnetname” 虛擬網路名稱
同時在Add-AzureProvisioningConig之前添加 | Set-AzureSubnet -SubnetName “subnetname” | 虛擬網路下的子網名稱
因為我們是需要指定內部虛擬網路的,所以需要指定參數;具體執行見下:
New-AzureVMConfig -Name "Winodws" -InstanceSize Large -ImageName "55bc2b193643443bb879a78bda516fc8__Windows-Server-2012-R2-201502.01-zh.cn-127GB.vhd" | Set-AzureSubnet -SubnetName "Subnet-1" | Add-AzureProvisioningConfig -Windows -AdminUsername gavin -Password Password2015 | New-AzureVM -ServiceName "CustomCloud" –ReservedIPName "RVIP" -Location "China North" -SLB/VPC Operations and Maintenance SystemName "iternal"
如果需要建立linux虛擬機器代碼如下:
New-AzureVMConfig -Name "Linux" -InstanceSize Large -ImageName "55bc2b193643443bb879a78bda516fc8__Windows-Server-2012-R2-201502.01-zh.cn-127GB.vhd" | Add-AzureProvisioningConfig -Linux -LinuxUser gavin -Password Password2015 | New-AzureVM -ServiceName "CustomCloud" –ReservedIPName "RVIP" -Location "China North"
如需建立在vnet內部則在 -Location "XXX"後面再添加 –SLB/VPC Operations and Maintenance SystemName “vnetname” 為虛擬網路
同時在Add-AzureProvisioningConig之前添加 | Set-AzureSubnet -SubnetName “subnetname” subnetname為虛擬網路下的子網名稱
因為我們是需要指定內部虛擬網路的,所以需要指定參數;具體執行見下:
New-AzureVMConfig -Name "Linux" -InstanceSize Large -ImageName "55bc2b193643443bb879a78bda516fc8__Windows-Server-2012-R2-201502.01-zh.cn-127GB.vhd" | Set-AzureSubnet -SubnetName “Subnet-1” | Add-AzureProvisioningConfig -Linux -LinuxUser gavin -Password Password2015 | New-AzureVM -ServiceName "CustomCloud" –ReservedIPName "RVIP" -Location "China North" -SLB/VPC Operations and Maintenance SystemName "iternal"
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M00/6F/C3/wKioL1Wn24vSn7PLAAEX5IPXnXs480.jpg" height="168" />
操作成後,我們接下來通過
get-azurereservedip
來顯示當前已經配置的reservedip
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M01/6F/C3/wKioL1Wn24ui0O85AAD-h2iGQ9A066.jpg" height="229" />
然後在portal上進行查看
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M01/6F/C6/wKiom1Wn2a-CP5KiAADfFZXs9Cg284.jpg" height="352" />
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M02/6F/C3/wKioL1Wn24uQuJP0AACiPZikogk286.jpg" height="172" />
接下來就是驗證reserverdip是否生效
首先是記錄當前vip資訊139.219.12.75
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M02/6F/C3/wKioL1Wn24vSZbRxAAEd97BNnm8954.jpg" height="323" />
我們將此vm關機30分鐘,關機後地址會釋放
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M00/6F/C3/wKioL1Wn24yTR5d0AAEmtiEOOuU015.jpg" height="352" />
30分鐘後,我們再次啟動該vm,然後查看公用虛擬ip地址
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M00/6F/C6/wKiom1Wn2bDCt62ZAAFC7d8s7Wo840.jpg" height="357" />
那怎麼刪除Reservedip:
由於Reservedip是收費的,所以不想使用,可以刪除;
刪除前,我們可以通過以下命令查看當前訂閱下有哪些Reservedip
get-azureReservedip
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M00/6F/C6/wKiom1Wn2bDhAsmNAAD4Zw6udwc104.jpg" height="237" />
然後刪除命名為RVIP的Reservedip
Remove-AzureReservedip -ReservedIPName "RVIP"
需要注意的是:如果相關的雲端服務中又存在的虛擬機器,需要先刪除虛擬機器才能刪除Reservedip,否在會報錯
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M02/6F/C3/wKioL1Wn26KgO6qOAAEq8XoNpJg304.jpg" height="195" />
我們刪除該reservedip下的vm
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M01/6F/C6/wKiom1Wn2caS9Z-WAADqBfXHukk652.jpg" height="353" />
刪除後,我們再次嘗試刪除命名為RVIP的reservedip
Remove-AzureReservedip -ReservedIPName "RVIP"
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M02/6F/C6/wKiom1Wn2cajBQTcAADsCEoWljE504.jpg" height="175" />
然後我們再次執行
get-azurereservedip
查看當前訂閱下的所有reservedip
650) this.width=650;" title="image" style="border-top:0px;border-right:0px;background-image:none;border-bottom:0px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px;" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M00/6F/C3/wKioL1Wn26KBcRS0AACB8qqf5pg193.jpg" height="88" />
本文出自 “高文龍” 部落格,請務必保留此出處http://gaowenlong.blog.51cto.com/451336/1675494
Windows Azure 配置實現虛擬機器外網IP綁定(雲端服務)