[article introduction]
Azure Cloud Shell is an interactive verified shell that can be accessed through a browser for managing azure resources. It enables users to flexibly choose the shell experience that is most suitable for their working mode. This article mainly focuses on the life cycle management of Linux virtual machines (including start, stop, restart, etc.)
[previous articles]
[1024 ways to play Microsoft Azure] i. quickly start to build the pagoda management panel in one minute
[1024 ways of playing Microsoft Azure] II. Construction of secure attack and defense shooting range system based on Azure cloud platform
[1024 ways to play Microsoft Azure] III. build Discuz forum based on Azure cloud platform
[1024 ways to play Microsoft Azure] IV. create a personal cloud disk by using Azure Virtual machines and sling a cloud disk at a high speed
[1024 ways to play Microsoft Azure] v. one stop creation of Linux VM based on Azure Cloud Shell
[1024 ways to play Microsoft Azure] 6. Use Azure Cloud Shell to manage the life cycle of Linux VirtualMachines
[Azure Cloud Shell function introduction and limitations]
-
Function introduction
Azure Cloud Shell is an interactive verified shell that can be accessed through a browser for managing azure resources. It gives users the flexibility to choose the shell experience that best suits their way of working, whether Bash or PowerShell. -
Conditional restrictions
- The Cloud Shell runs on a temporary host provided by the user per session
- The Cloud Shell will time out after 20 minutes of no interactive activity
- Cloud Shell needs to mount Azure file share
- Cloud Shell uses the same Azure file share for Bash and PowerShell
- A computer will be assigned to the Cloud Shell for each user account
- Cloud Shell uses the 5-GB image saved in the file share to persist $HOME
- In Bash, permissions are set by regular Linux users
[operation steps]
1, Query Azure public image through Azure Cloud Shell
① If we want to query the available public image list, we can use az vm image list command in Azure Cloud Shell. The command format is as follows:
az vm image list --output table
② Execute the following code to echo
ma@Azure:~$ az vm image list --output table You are viewing an offline list of images, use --all to retrieve an up-to-date list Offer Publisher Sku Urn UrnAlias Version ---------------------------- ---------------------- ------------------ -------------------------------------------------------------- ------------------- --------- CentOS OpenLogic 7.5 OpenLogic:CentOS:7.5:latest CentOS latest debian-10 Debian 10 Debian:debian-10:10:latest Debian latest flatcar-container-linux-free kinvolk stable kinvolk:flatcar-container-linux-free:stable:latest Flatcar latest openSUSE-Leap SUSE 42.3 SUSE:openSUSE-Leap:42.3:latest openSUSE-Leap latest RHEL RedHat 7-LVM RedHat:RHEL:7-LVM:latest RHEL latest SLES SUSE 15 SUSE:SLES:15:latest SLES latest UbuntuServer Canonical 18.04-LTS Canonical:UbuntuServer:18.04-LTS:latest UbuntuLTS latest WindowsServer MicrosoftWindowsServer 2019-Datacenter MicrosoftWindowsServer:WindowsServer:2019-Datacenter:latest Win2019Datacenter latest WindowsServer MicrosoftWindowsServer 2016-Datacenter MicrosoftWindowsServer:WindowsServer:2016-Datacenter:latest Win2016Datacenter latest WindowsServer MicrosoftWindowsServer 2012-R2-Datacenter MicrosoftWindowsServer:WindowsServer:2012-R2-Datacenter:latest Win2012R2Datacenter latest WindowsServer MicrosoftWindowsServer 2012-Datacenter MicrosoftWindowsServer:WindowsServer:2012-Datacenter:latest Win2012Datacenter latest WindowsServer MicrosoftWindowsServer 2008-R2-SP1 MicrosoftWindowsServer:WindowsServer:2008-R2-SP1:latest Win2008R2SP1 latest
③ At the same time, we can filter out the images containing "Centos" operating system by executing az vm image list --offer CentOS --all --output table command (the query time will be between 1 minute and 3 minutes)
CentOS OpenLogic 7.7 OpenLogic:CentOS:7.7:7.7.2020111300 7.7.2020111300 CentOS OpenLogic 7.7 OpenLogic:CentOS:7.7:7.7.2021020400 7.7.2021020400 php-7-3-with-centos-7-8 cognosys php-7-3-with-centos-7-8 cognosys:php-7-3-with-centos-7-8:php-7-3-with-centos-7-8:1.2019.1010 1.2019.1010 CentOS OpenLogic 7_4 OpenLogic:CentOS:7_4:7.4.20200220 7.4.20200220 CentOS OpenLogic 7_4-gen2 OpenLogic:CentOS:7_4-gen2:7.4.20200220 7.4.20200220 php-7-3-with-centos-7-9 cognosys php-7-3-with-centos-7-9 cognosys:php-7-3-with-centos-7-9:php-7-3-with-centos-7-9:1.2019.1010 1.2019.1010 CentOS OpenLogic 7_5-gen2 OpenLogic:CentOS:7_5-gen2:7.5.20200214 7.5.20200214 CentOS OpenLogic 7_6-gen2 OpenLogic:CentOS:7_6-gen2:7.6.20200213 7.6.20200213
④ Later, if you want to use a specific image to deploy the virtual machine, you can specify the image you need by specifying the version number of the image. If you want to use the latest version of the image, you can obtain the latest distribution version by adding the "latest" parameter. For example, suppose we want to create a Linux virtual machine, The Linux virtual machine information is as follows:
- Virtual machine name: myVM2
- The virtual machine image is the latest release of Centos 7.7
- The remote connection authentication method is generate SSH keys
⑤ Execute the following commands according to the required information
az vm create --resource-group myResourceGroupVM --name myVM2 --image OpenLogic:CentOS:7.7:latest --generate-ssh-keys
⑥ The execution is completed, as shown in the figure below
⑦ Return to the VM console to view the relevant information and find that it is consistent with the version information we created
2, Query Azure VM instance specification parameters through Azure Cloud Shell
2.1 comparison of example parameters and specifications
Generally, we will select the configuration parameters before choosing to use Auzre VM, such as how many CPU s and memory virtual machines we want to buy, what types of virtual machines we need to carry our business parameters, etc. we must do a configuration selection before choosing to buy servers with different instance specifications, Azure VM types for different business scenarios are listed below
Specification cluster | Instance specification | Suitable business scenarios |
---|---|---|
Universal type | B, Dsv3, Dv3, DSv2, Dv2, Av2, DC | It is mainly suitable for setting up scenarios of front and back end, middleware, development and testing of web applications |
Computational type | Fsv2 | With high CPU and high memory ratio, it is mainly suitable for applications with medium traffic |
Memory enhanced | Esv3,Ev3,M,DSv2,Dv2 | With high memory, it is mainly suitable for medium to large cache databases and relational databases |
Storage enhanced | Lsv2,Ls | With high disk throughput and IO, it is mainly suitable for building various big data and Nosql database scenarios |
GPU type | NV,NVv2,NC,NCv2,NCv3,ND | Graphics rendering scene for video, picture, audio processing and GPU acceleration |
High performance | H | With strong CPU processing capacity and optional high throughput network interface, it is suitable for business scenarios such as deep learning |
2.2 instance parameter query
If we want to query the list of VM instance types available in a region, we can query through AZ VM list sizes command. For example, the following parameters can query the instance specifications available in the eastern United States and output them in the form of table. We can query through the following commands
az vm list-sizes --location eastus --output table
The query command output is as follows (instance specifications available in the eastern United States): MaxDataDiskCount MemoryInMb Name NumberOfCores OsDiskSizeInMb ResourceDiskSizeInMb ------------------ ------------ ------------------------- --------------- ---------------- ---------------------- 2 512 Standard_B1ls 1 1047552 4096 2 2048 Standard_B1ms 1 1047552 4096 2 1024 Standard_B1s 1 1047552 4096 4 8192 Standard_B2ms 2 1047552 16384 4 4096 Standard_B2s 2 1047552 8192 8 16384 Standard_B4ms 4 1047552 32768 16 32768 Standard_B8ms 8 1047552 65536 16 49152 Standard_B12ms 12 1047552 98304 32 65536 Standard_B16ms 16 1047552 131072 32 81920 Standard_B20ms 20 1047552 16384
3, Dynamic configuration change of Azure VM instance specification through Azure Cloud Shell
3.1 viewing the current VM size
az vm show --resource-group myResourceGroupVM --name myVM --query hardwareProfile.vmSize
Before adjustment, you need to query whether the Azure cluster is available
az vm list-vm-resize-options --resource-group myResourceGroupVM --name myVM --query [].name
The size is available and can be adjusted directly from the power on state
az vm resize --resource-group myResourceGroupVM --name myVM --size Standard_DS4_v2
The size is unavailable. You need to deallocate the VM before resizing
az vm deallocate --resource-group myResourceGroupVM --name myVM
4, Manage Azure VM instance status through Azure Cloud Shell
4.1 Azure VM instance status
The state of a VM instance is divided into different states (starting, running, stopping, stopped, deallocating, and deallocated). The following table explains and describes the different states of the VM instance life cycle
Instance status | describe |
---|---|
Starting | The virtual machine is starting |
function | The virtual machine is running |
Stopping | The virtual machine is stopping |
Stopped | Virtual machine stopped |
Deallocating | The virtual machine is being deallocated |
Deallocated | The virtual machine has been removed from the hypervisor but is still in use in the control panel |
- | The virtual machine state is unknown |
4.2 querying Auzre VM status
Query the current virtual machine status through AZ VM get instance view command, and execute the following command
az vm get-instance-view \ --name myVM2 \ --resource-group myResourceGroupVM \ --query instanceView.statuses[1] --output table
After execution, as shown in the following figure:
4.3 stop Auzre VM
To stop the currently started virtual machine or change the virtual machine from the start state to the stop state, you can stop the virtual machine through the "az vm stop" command
AZ VM stop -- resource group resource group name -- name virtual machine name
For example, to change the virtual machine name myVM2 from running state to stopped state, you can execute the following commands
az vm stop --resource-group myResourceGroupVM --name myVM2
After execution, as shown in the following figure
View through the VM portal. The current virtual machine status is stopped, as shown in the following figure
4.4 start Auzre VM
To change the stopped Auzre VM state to running, you can start the Azure VM virtual machine through the "az vm start" command
For example, to change the virtual machine name myVM2 from the stop state to the start state, execute the following commands
az vm start --resource-group myResourceGroupVM --name myVM2
After execution, as shown in the following figure
View through the VM portal. The current virtual machine state is changed from the stopped state to the running state, as shown in the following figure
The above content is a tutorial on life cycle management of Linux VirtualMachines using Azure Cloud Shell. Have you learned it?