More about Linux on Azure
- Linux on Azure: Optimizing Cost, Performance, and Security
- Azure Blob as File System on Linux: What You Need to Know Before You Try
- Linux NFS Server: How to Set Up Server and Client
- Azure CLI Linux: The Basics, Tips, and a Quick Tutorial
- Linux NFS: The Basics and How to Run NFS in the Cloud
- Azure Linux VM Pricing: Cost Models and Best Practices
- Linux on Azure Workload Migration: Challenges and Solutions
- Ready to Solve Your Enterprise Linux File Requirements in Azure?
- Build Your Own Azure NFS? Wrestling Linux File Shares into Cloud
Subscribe to our blog
Thanks for subscribing to the blog.
December 1, 2020
Topics: Azure NetApp Files AzureElementary8 minute read
What is Azure Command Line?
Azure Command Line Interface (Azure CLI) is a convenient way to manage, update, and create resources on the Microsoft Azure cloud platform. Azure CLI can be used for any Azure service, and it is designed with automation in mind.
The Azure CLI allows you to easily work in all popular programming languages and environments. In this article we focus on using the Azure CLI in an Azure Linux environment.
- It can be installed in Windows, MacOS and Linux environments.
- You can run it from Docker and Azure Cloud Shell.
It also provides powerful features you can use to automate resources on Azure:
- Support long-term operation.
- Supports one or multiple Azure subscriptions for each command
- Can return query results in an output format of your choice
- Can work in a multicloud environment
- Offers configurable logging, data collection, and default arguments
- Can be deployed using ResourceManager templates
In this article, you will learn:
- Install Azure CLI with apt
- 3 Tips for Using Azure CLI Effectively
- Quick Tutorial: Create a Linux virtual Machine with the Azure CLI
- Linux on Azure with Azure NetApp Files
Install Azure CLI with apt
If you use the distribution provided by apt (such as Debian or Ubuntu), or use the x86_64 package in the Azure CLI—note the package was tested and is compatible with the following products:
- Ubuntu—trusty, bionic, xenial, eoan, focal
- Debian—jessie, buster, stretch
There are two ways to install Azure CLI using apt-compatible deployment. One is to run a general installation command script, and the other is a step-by-step process that can be run directly.
Install with One Command
Azure provides and maintains scripts that can run all installation commands using one line of code. You can run these one line scripts using curl. An alternative is downloading the script into a file, where you can check it before actually running. Here is a one-line script for installing the Azure CLI:
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
Manual Install Instructions
If you are not interested in running the script as root, or the one-line script does not work, follow the steps below to install Azure CLI.
- Get the software packages required for the installation process.
sudo apt-get update
sudo apt-get install ca-certificates curl apt-transport-https lsb-release gnupg
- To get access to the CLI, you’ll need to download a security key provided by Microsoft
curl -sL https://packages.microsoft.com/keys/microsoft.asc |
gpg --dearmor |
sudo tee /etc/apt/trusted.gpg.d/microsoft.gpg > /dev/null
- Add the Azure CLI repo.
AZ_REPO=$(lsb_release -cs)
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" |
sudo tee /etc/apt/sources.list.d/azure-cli.list
- Update the repository data and install the package.
sudo apt-get update
sudo apt-get install azure-cli
- Use the az command to start the Azure CLI. Use the azlogin command to log in.
3 Tips for Using Azure CLI Effectively
The following three tips will help you make the most out of your use of Azure CLI.
Output Formatting
- The default output format of the Azure CLI is JSON, and is intended to provide as much information as possible. If other formats are needed, use the --output option to overwrite a single command call, or use az configure to update global output configuration.
- The JSON format contains double quotes and is usually not suitable for scripting.
- The table command is particularly useful for getting summarized information from the CLI. If you need to see different fields in the table, use --query to specify your own format.
- tsv can help you create brief outputs and is useful for scripts, because it strips double quotes. Use the --query parameter to specify the required format for the TSV files.
Generic Update Arguments
Most CLI update commands have three common parameters: --add, --set and --remove. Although these options are powerful, they are generally not as useful as the strongly typed options commonly used in update commands. The CLI provides strongly typed arguments for the most common situations for ease of use. However, if the property you need is not listed, you can rely on generic update arguments, to avoid waiting for a new release of the CLI.
The generic update syntax is not the easiest to use and requires a little patience. You must make sure that the Generic Update Arguments group exists. If not, you need to create a support ticket to make this group available as part of the update operation.
Once you have the group, try the following:
- The show command displays the path to be used in the shared arguments
- The update operation’s dot syntax can be useful to get lists of attributes or available commands
- Run az vm update -h to see working examples.
Managing Concurrent Users
Azure CLI is often used on machines used to build software packages using CI/CD systems such as Jenkins. These types of machines commonly run several builds at the same time, with different users running different builds. This creates a need to log into the CLI several times with different users.
To avoid an issue where the same login token will be shared between all the builds, on each build system, set the AZURE_CONFIG_DIR environment variable to a directory that contains a correct login token for that build system.
Quick Tutorial #1: Create a Linux Virtual Machine with the Azure CLI
Next, see how to deploy a Linux virtual machine (VM) in Azure using the Azure Command Line Interface (CLI).
Related content: read our guide to Azure Linux VMs
Launch Azure Cloud Shell
Azure Cloud Shell is a free interactive shell that can be used to complete the steps in this tutorial. All popular Azure tools are pre-installed and configured to work with your account. You can open CloudShell from a browser tab using this URL: https://shell.azure.com/bash
Create a Resource Group
Use the az group create command to create a resource group. Azure resource groups are logical containers in which Azure resources are organized and managed. See an example below:
az group create --name myResourceGroup --location eastus
Create a Virtual Machine
Use the azvmcreate command to create a virtual machine. Below is an example showing how to create a VM named myVM and adds a user account to it.
The --generate-ssh-keys option is used to automatically generate SSH keys and save them in the standard key location (~/.ssh). The --ssh-key-value parameter lets you specify which set of keys to use in the vm create operation. It can take a few minutes for the VM to be launched.
az vm create --resource-group myResourceGroup --name myVM \
--image UbuntuLTS --admin-username azureuser --generate-ssh-keys
Quick Tutorial #2: Create an NFS volume with Azure NetApp Files
Azure NetApp Files is a cloud service provided by Azure and NetApp, which lets you manage file shares in Linux with enterprise-grade performance and built-in high availability.
You must first register for Azure NetApp Files and create a NetApp account - see instructions here.
Set Up a Capacity Pool for Your File Share
Use this command to create a capacity pool, which you can later use to create enterprise-grade NFS volumes and mount them to Linux VMs in Azure, or to Linux machines running on premises.
Under service-level, you can select Standard, Premium, or Ultra to define the performance and availability you need from your file shares (learn about service levels).
az netappfiles pool create \
--resource-group {your-resource-group} \
--location {required-location} \
--account-name {your-account} \
--pool-name "mypool1" --size {size-in-TB} \
--service-level "Premium"
Create an NFS Volume
First, create a virtual network. We will not create a subnet at this stage, in the next step we’ll create a delegated subnet.
az network vnet create --resource-group {your-resource-group} \
--name "myvnet1" --location {required-location} \
--address-prefix "10.7.0.0/16"
Now let’s create the delegated subnet, this will allow the NFS volume to run privately and securely.
az network vnet subnet create --resource-group {your-resource-group} \
--vnet-name "myvnet1" --name "mysubnet1" \
--address-prefixes "10.7.0.0/24" \
--delegations "Microsoft.NetApp/volumes"
Finally, we can create the volume itself. Note that the file path you provide must be unique to the Azure subscription and region, you cannot create another NFS share on the same path.
Under protocol-types, select the NFS version your applications support - Azure NetApp Files support NFSv3 and NFSv4.1.
az netappfiles volume create --resource-group {your-resource-group} \
--location {required-location} --account-name {your-account} \
--pool-name "mypool1" --name "myvol1" \
--service-level $SERVICE_LEVEL \
--vnet "myvnet1" \
--subnet "mysubnet1" \
--usage-threshold {size-in-TB} \
--file-path {unique-file-path} \
--protocol-types "NFSv3"
Linux on Azure with Azure NetApp Files
Azure NetApp Files is a Microsoft Azure file storage service built on NetApp technology, giving you the file capabilities in Azure even your core business applications require.
Get enterprise-grade data management and storage to Azure so you can manage your workloads and applications with ease, and move all of your file-based applications to the cloud.
Azure NetApp Files solves availability and performance challenges for enterprises that want to move mission-critical applications to the cloud, including workloads like HPC, SAP, Linux, Oracle and SQL Server workloads, Windows Virtual Desktop, and more.
In particular, Azure NetApp Files allows you to migrate your Linux applications to Azure–even your business-critical workloads–with extreme file throughput with sub-millisecond response times.
Want to get started? See Azure NetApp Files for yourself with a free demo.