現(xiàn)象描述
在很多場(chǎng)景下,客戶會(huì)掛載多個(gè)數(shù)據(jù)磁盤到虛擬機(jī)上,為了提高性能和易擴(kuò)展性,會(huì)使用到 raid 或者 lvm 邏輯卷來(lái)組合磁盤使用,在進(jìn)行數(shù)據(jù)遷移和備份時(shí),會(huì)涉及到數(shù)據(jù)磁盤的管理,由于數(shù)據(jù)磁盤在虛擬機(jī)內(nèi)部和 Azure 存儲(chǔ)賬號(hào)內(nèi)的命名方式不一樣, 客戶會(huì)經(jīng)常對(duì)一大堆磁盤如何進(jìn)行一一對(duì)應(yīng)而深感頭痛。
解決方案
以下主要介紹如何定位虛擬機(jī)內(nèi)部附加的數(shù)據(jù)磁盤在存儲(chǔ)賬號(hào)里的對(duì)應(yīng)關(guān)系。
Linux虛擬機(jī)環(huán)境
案例中,Linux 虛擬機(jī)采用的是 CentOS 7.3,其他版本的 Linux 操作系統(tǒng)會(huì)略有區(qū)別,請(qǐng)注意區(qū)分。
創(chuàng)建 CentOS 7.3 虛擬機(jī)。
創(chuàng)建兩塊數(shù)據(jù)磁盤,名字為:
復(fù)制
LunTest-LunTest-0-201706130314040006 (對(duì)應(yīng) vhd: LunTest-LunTest-0613-1.vhd)
LunTest-LunTest-1-201706130315590578 (對(duì)應(yīng) vhd: LunTest-LunTest-0613-2.vhd)
將上述數(shù)據(jù)磁盤附加到虛擬機(jī)。
以管理員身份登錄虛擬機(jī),并切換到 root 用戶。
執(zhí)行命令:#fdisk -l:
復(fù)制
[root@LunTest chpaadmin]# fdisk? -l |grep -i Disk
Disk /dev/sda: 32.2 GB, 32214351872 bytes, 62918656 sectors
Disk label type: dos
Disk identifier: 0x000c7e0e
Disk /dev/sdb: 75.2 GB, 75161927680 bytes, 146800640 sectors
Disk label type: dos
Disk identifier: 0x7ca6a8d6
Disk /dev/sdc: 10.7 GB, 10737418240 bytes, 20971520 sectors
Disk /dev/sdd: 10.7 GB, 10737418240 bytes, 20971520 sectors
/dev/sdc和/dev/sdd為上述附加的數(shù)據(jù)磁盤,可以看到,這兩塊數(shù)據(jù)盤大小一致,無(wú)法準(zhǔn)確區(qū)分對(duì)應(yīng)的是 Azure 存儲(chǔ)賬號(hào)里的哪一塊數(shù)據(jù)磁盤。
以下介紹如何來(lái)進(jìn)行區(qū)分:
執(zhí)行命令:# dmesg -T |grep -i scsi:
復(fù)制
[root@LunTest chpaadmin]# dmesg -T |grep -i scsi
[Tue Jun 13 03:11:14 2017] SCSI subsystem initialized
[Tue Jun 13 03:11:14 2017] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 251)
[Tue Jun 13 03:11:16 2017] scsi host0: ata_piix
[Tue Jun 13 03:11:16 2017] scsi host1: ata_piix
[Tue Jun 13 03:11:16 2017] scsi host2: storvsc_host_t
[Tue Jun 13 03:11:16 2017] scsi 2:0:0:0: Direct-Access? ? Msft? ? Virtual Disk? ? 1.0? PQ: 0 ANSI: 4
[Tue Jun 13 03:11:16 2017] scsi host3: storvsc_host_t
[Tue Jun 13 03:11:16 2017] scsi: waiting for bus probes to complete ...
[Tue Jun 13 03:11:16 2017] scsi 1:0:0:0: CD-ROM? ? ? ? ? ? Msft? ? Virtual CD/ROM? 1.0? PQ: 0 ANSI: 5
[Tue Jun 13 03:11:16 2017] scsi host4: storvsc_host_t
[Tue Jun 13 03:11:16 2017] scsi host5: storvsc_host_t
[Tue Jun 13 03:11:16 2017] scsi 5:0:1:0: Direct-Access? ? Msft? ? Virtual Disk? ? 1.0? PQ: 0 ANSI: 4
[Tue Jun 13 03:11:16 2017] sr 1:0:0:0: [sr0] scsi3-mmc drive: 0x/0x tray
[Tue Jun 13 03:11:16 2017] sr 1:0:0:0: Attached scsi CD-ROM sr0
[Tue Jun 13 03:11:16 2017] sd 2:0:0:0: [sda] Attached SCSI disk
[Tue Jun 13 03:11:16 2017] sd 5:0:1:0: [sdb] Attached SCSI disk
[Tue Jun 13 03:11:23 2017] sd 2:0:0:0: Attached scsi generic sg0 type 0
[Tue Jun 13 03:11:23 2017] sr 1:0:0:0: Attached scsi generic sg1 type 5
[Tue Jun 13 03:11:23 2017] sd 5:0:1:0: Attached scsi generic sg2 type 0
[Tue Jun 13 03:14:16 2017] scsi 4:0:0:0: Direct-Access? ? Msft? ? Virtual Disk? ? 1.0? PQ: 0 ANSI: 4
[Tue Jun 13 03:14:16 2017] sd 4:0:0:0: Attached scsi generic sg3 type 0
[Tue Jun 13 03:14:16 2017] sd 4:0:0:0: [sdc] Attached SCSI disk
[Tue Jun 13 03:16:23 2017] scsi 4:0:0:1: Direct-Access? ? Msft? ? Virtual Disk? ? 1.0? PQ: 0 ANSI: 4
[Tue Jun 13 03:16:23 2017] sd 4:0:0:1: Attached scsi generic sg4 type 0
[Tue Jun 13 03:16:23 2017] sd 4:0:0:1: [sdd] Attached SCSI disk
上述顯示的 "4:0:0:0" 和 "4:0:0:1" 分別為磁盤/dev/sdc和/dev/sdd的設(shè)備掛載地址,最后一位為磁盤的 LUN ID.
通過(guò) PowerShell,執(zhí)行以下命令來(lái)獲取數(shù)據(jù)磁盤的 LUN ID:
復(fù)制
PS C:\Users\chpa> $vm = Get-AzureVM -ServiceName luntest -Name luntest
PS C:\Users\chpa> $vm.VM.DataVirtualHardDisks
HostCaching? ? ? ? : None
DiskLabel? ? ? ? ? :
DiskName? ? ? ? ? ? : LunTest-LunTest-0-201706130314040006
Lun? ? ? ? ? ? ? ? : 0
LogicalDiskSizeInGB : 10
MediaLink? ? ? ? ? : https://tcportalvhdsgrnnb3k173zr.blob.core.chinacloudapi.cn/vhds/LunTest-LunTest-0613-1.vhd
SourceMediaLink? ? :
IOType? ? ? ? ? ? ? : Standard
ExtensionData? ? ? :
HostCaching? ? ? ? : None
DiskLabel? ? ? ? ? :
DiskName? ? ? ? ? ? : LunTest-LunTest-1-201706130315590578
Lun? ? ? ? ? ? ? ? : 1
LogicalDiskSizeInGB : 10
MediaLink? ? ? ? ? : https://tcportalvhdsgrnnb3k173zr.blob.core.chinacloudapi.cn/vhds/LunTest-LunTest-0613-2.vhd
SourceMediaLink? ? :
IOType? ? ? ? ? ? ? : Standard
ExtensionData? ? ? :
至此,通過(guò) LUN ID 將虛擬機(jī)內(nèi)部的數(shù)據(jù)磁盤和 Azure 存儲(chǔ)賬號(hào)的磁盤一一對(duì)應(yīng)起來(lái)了。
Windows 虛擬機(jī)環(huán)境
案例中,Windows 虛擬機(jī)采用的是 Windows Server 2012 R2,其他版本的 Windows 操作系統(tǒng)會(huì)略有區(qū)別,請(qǐng)注意區(qū)分。
創(chuàng)建 Windows Server 2012 R2 虛擬機(jī)。
創(chuàng)建兩塊數(shù)據(jù)磁盤,名字為:
復(fù)制
dcuser-dcuser-0-201706130918520846(對(duì)應(yīng) vhd: dcuser-dcuser-noid.vhd)
dcuser-dcuser-1-201706130924230994(對(duì)應(yīng) vhd: dcuser-dcuser-noid-too.vhd)
將上述數(shù)據(jù)磁盤附加到虛擬機(jī)。
以管理員身份登錄虛擬機(jī)。
打開(kāi)命令,執(zhí)行如下命令,查看當(dāng)前磁盤的 LUN ID:
復(fù)制
PS C:\Users\azureuser> diskpart
Microsoft DiskPart version 6.3.9600
Copyright (C) 1999-2013 Microsoft Corporation.
On computer: dcuser
DISKPART> list disk
Disk ###? Status? ? ? ? Size? ? Free? ? Dyn? Gpt
--------? -------------? -------? -------? ---? ---
Disk 0? ? Online? ? ? ? ? 127 GB? 2048 KB
Disk 1? ? Online? ? ? ? ? 50 GB? ? ? 0 B
Disk 2? ? Online? ? ? ? ? 10 GB? 1024 KB
Disk 3? ? Online? ? ? ? ? 10 GB? 1024 KB
DISKPART> select disk 2
Disk 2 is now the selected disk.
DISKPART> detail disk
Microsoft Virtual Disk
Disk ID: 961D20C6
Type? : SAS
Status : Online
Path? : 0
Target : 0
LUN ID : 5
Location Path : UNAVAILABLE
Current Read-only State : No
Read-only? : No
Boot Disk? : No
Pagefile Disk? : No
Hibernation File Disk? : No
Crashdump Disk? : No
Clustered Disk? : No
Volume ###? Ltr? Label? ? ? ? Fs? ? Type? ? ? ? Size? ? Status? ? Info
----------? ---? -----------? -----? ----------? -------? ---------? --------
Volume 2? ? E? New Volume? NTFS? Partition? ? ? 9 GB? Healthy
DISKPART>
通過(guò) PowerShell,執(zhí)行以下命令來(lái)獲取數(shù)據(jù)磁盤的 LUN ID:
復(fù)制
PS C:\Users\chpa> $vm = Get-AzureVM -ServiceName dcuser -Name dcuser
PS C:\Users\chpa> $vm.vm.DataVirtualHardDisks
HostCaching? ? ? ? : None
DiskLabel? ? ? ? ? :
DiskName? ? ? ? ? ? : dcuser-dcuser-0-201706130918520846
Lun? ? ? ? ? ? ? ? : 5
LogicalDiskSizeInGB : 10
MediaLink? ? ? ? ? : https://tcportalvhdsgrnnb3k173zr.blob.core.chinacloudapi.cn/vhds/dcuser-dcuser-noid.vhd
SourceMediaLink? ? :
IOType? ? ? ? ? ? ? : Standard
ExtensionData? ? ? :
HostCaching? ? ? ? : None
DiskLabel? ? ? ? ? :
DiskName? ? ? ? ? ? : dcuser-dcuser-1-201706130924230994
Lun? ? ? ? ? ? ? ? : 1
LogicalDiskSizeInGB : 10
MediaLink? ? ? ? ? : https://tcportalvhdsgrnnb3k173zr.blob.core.chinacloudapi.cn/vhds/dcuser-dcuser-noid-too.vhd
SourceMediaLink? ? :
IOType? ? ? ? ? ? ? : Standard
ExtensionData? ? ? :
至此,通過(guò) LUN ID 將虛擬機(jī)內(nèi)部的數(shù)據(jù)磁盤和 Azure 存儲(chǔ)賬號(hào)的磁盤一一對(duì)應(yīng)起來(lái)了。
立即訪問(wèn)http://market.azure.cn