Red Hat Training
A Red Hat training course is available for RHEL 8
1.8. 在 Azure 中创建并启动虚拟机
以下步骤提供从镜像创建 managed-disk Azure 虚拟机的最低命令选项。如需了解更多选项,请参阅az vm create。
流程
输入以下命令来创建虚拟机。
$ az vm create \ -g <resource-group> -l <azure-region> -n <vm-name> \ --vnet-name <vnet-name> --subnet <subnet-name> --size Standard_A2 \ --os-disk-name <simple-name> --admin-username <administrator-name> \ --generate-ssh-keys --image <path-to-image>
注意选项
--generate-ssh-keys
创建私钥/公钥对。私钥和公钥文件创建在您系统上的~/.ssh
中。公钥被添加到--admin-username
选项所指定的用户的虚拟机上的authorized_keys
文件中。如需更多信息,请参阅其他身份验证方法 。例如:
[clouduser@localhost]$ az vm create \ -g azrhelclirsgrp2 -l southcentralus -n rhel-azure-vm-1 \ --vnet-name azrhelclivnet1 --subnet azrhelclisubnet1 --size Standard_A2 \ --os-disk-name vm-1-osdisk --admin-username clouduser \ --generate-ssh-keys --image rhel8 { "fqdns": "", "id": "/subscriptions//resourceGroups/azrhelclirsgrp/providers/Microsoft.Compute/virtualMachines/rhel-azure-vm-1", "location": "southcentralus", "macAddress": "", "powerState": "VM running", "privateIpAddress": "10.0.0.4", "publicIpAddress": "<public-IP-address>", "resourceGroup": "azrhelclirsgrp2"
请注意
publicIpAddress
。在以下步骤中,您需要这个地址来登录到虚拟机。启动 SSH 会话并登录到虚拟机。
[clouduser@localhost]$ ssh -i /home/clouduser/.ssh/id_rsa clouduser@<public-IP-address>. The authenticity of host ',<public-IP-address>' can't be established. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '<public-IP-address>' (ECDSA) to the list of known hosts. [clouduser@rhel-azure-vm-1 ~]$
如果您看到用户提示,则代表成功部署了 Azure 虚拟机。
现在,您可以进到 Microsoft Azure 门户网站,并检查审计日志和资源的属性。您可以在此门户中直接管理虚拟机。如果要管理多个虚拟机,您应该使用 Azure CLI。Azure CLI 为您在 Azure 中的资源提供了一个强大的接口。在 CLI 中输入 az --help
,或参阅 Azure CLI 命令参考 来了解更多有关您在 Microsoft Azure 中管理虚拟机的命令。