Azure CLI vm创建和创建数据磁盘的顺序 [英] Azure CLI vm create and order of creating data disks

查看:54
本文介绍了Azure CLI vm创建和创建数据磁盘的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用CLI创建Linux VM而无需任何手动步骤。 VM将运行Mongo,我想为其分配3个附加数据磁盘,这些磁盘安装在/ data / log和/ journal上


我使用的CLI命令看起来有点像:

 az vm create \ 
--name mongo-node-1 \
--resource-group myresourcegroup \
- admin-username myrootuser \
--custom-data" $(cat mongo-node.yml)" \
--data-disks-sizes-gb 50 10 10 \
--image规范:UbuntuServer:18.04-LTS:最新




我期望按照我指定的顺序创建数据磁盘:

 / dev / sdc:50 GiB 
/ dev / sdd:10 GiB
/ dev / sde:10 GiB

但相反磁盘以另一种顺序创建:

 / dev / sdc:10 GiB 
/ dev / sdd:50 GiB
/ dev / sde: 10 GiB

这是非常不切实际的,因为我想创建文件系统&将它挂载到我在启动VM时提供给Azure CLI的CloudInit userdata文件中:

 #cloud-config 
repo_upgrade:all
repo_upgrade_exclude:[]
runcmd:
- echo"LC_ALL = C" | tee -a / etc / environment
- echo'type = 83'| sfdisk / dev / sdc
- echo'type = 83'| sfdisk / dev / sdd
- echo'type = 83'| sfdisk / dev / sde
- mkfs -t ext4 / dev / sdc1
- mkfs -t ext4 / dev / sdd1
- mkfs -t ext4 / dev / sde1
- mount / dev / sdc1 / data
- mount / dev / sdd1 / journal
- mount / dev / sde1 / log
- apt-key adv --keyserver hkp://keyserver.ubuntu。 com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
- apt-get update
- apt-get install -y mongodb-org




<为了实现这一目标,我需要确定哪些创建的设备是50GB磁盘,因为我不想使用10GB磁盘作为数据存储:这些用于日志和日志文件。我不知道如何使用Azure CLI执行此操作...



解决方案

好像是客户操作系统级别的问题。 


我测试了你的命令,磁盘按顺序附加了在命令中写入

 az vm create \ 
--name mongo-node-1 \
--resource-group VirtualMachines \
--admin-username myrootuser \
--data-disks-sizes-gb 50 10 20 40 \
--image规范:UbuntuServer:18.04-LTS:最新






您也可以创建VM然后附加数据磁盘,此时您可以指定要将磁盘分配给的LUN


https://docs.microsoft.com/en-us / CLI /天青/ VM /磁盘?视图=天青-CLI-LAT est

 az vm disk attach --vm-name 
[--caching {None,ReadOnly,ReadWrite}]
[--enable-write-accelerator]
[--ids]
[--lun]
[--name]
[--new]
[ --resource-group]
[--size-gb]
[--sku {Premium_LRS,StandardSSD_LRS,Standard_LRS,UltraSSD_LRS}]
[--subscription]


I'm trying to create a Linux VM using the CLI without any manual steps. The VM will run Mongo for which I want to allocate 3 additional data disks that are mounted on /data /log and /journal

The CLI command I use looks a bit like:

az vm create \
    --name mongo-node-1 \
    --resource-group myresourcegroup \
    --admin-username myrootuser \
    --custom-data "$(cat mongo-node.yml)" \
    --data-disk-sizes-gb 50 10 10 \
    --image Canonical:UbuntuServer:18.04-LTS:latest


I'm expecting the creation of the data disks to be completed in the order I specified:

/dev/sdc: 50 GiB
/dev/sdd: 10 GiB
/dev/sde: 10 GiB

But instead the disks are created in another order:

/dev/sdc: 10 GiB
/dev/sdd: 50 GiB
/dev/sde: 10 GiB

Which is very impractical because I want to create the filesystem & mount it in the CloudInit userdata file I'm supplying to the Azure CLI when launching the VM:

#cloud-config
repo_upgrade: all
repo_upgrade_exclude: []
runcmd:
- echo "LC_ALL=C" | tee -a /etc/environment
- echo 'type=83' | sfdisk /dev/sdc
- echo 'type=83' | sfdisk /dev/sdd
- echo 'type=83' | sfdisk /dev/sde
- mkfs -t ext4 /dev/sdc1
- mkfs -t ext4 /dev/sdd1
- mkfs -t ext4 /dev/sde1
- mount /dev/sdc1 /data
- mount /dev/sdd1 /journal
- mount /dev/sde1 /log
- apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
- apt-get update
- apt-get install -y mongodb-org

For this to work I need to be sure upfront which of the created devices is the 50GB disk, because I don't want to use a 10GB disk as the data storage: those are used for the journal and log files. And I don't see how I can do this with the Azure CLI...

解决方案

Seems like it is a Guest OS level issue. 

I tested your commands and the disks were attached in the order they were written in the command

az vm create \
    --name mongo-node-1 \
    --resource-group VirtualMachines \
    --admin-username myrootuser \
    --data-disk-sizes-gb 50 10 20 40 \
    --image Canonical:UbuntuServer:18.04-LTS:latest


You can also create the VM THEN attach the data disks at which point you can specify the LUN you want the disk assigned to 

https://docs.microsoft.com/en-us/cli/azure/vm/disk?view=azure-cli-latest

az vm disk attach --vm-name
                  [--caching {None, ReadOnly, ReadWrite}]
                  [--enable-write-accelerator]
                  [--ids]
                  [--lun]
                  [--name]
                  [--new]
                  [--resource-group]
                  [--size-gb]
                  [--sku {Premium_LRS, StandardSSD_LRS, Standard_LRS, UltraSSD_LRS}]
                  [--subscription]


这篇关于Azure CLI vm创建和创建数据磁盘的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆