You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/virtual-machines/linux/quick-create-cli.md
+72-17Lines changed: 72 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,32 +29,44 @@ To open the Cloud Shell, just select **Try it** from the upper right corner of a
29
29
30
30
If you prefer to install and use the CLI locally, this quickstart requires Azure CLI version 2.0.30 or later. Run `az --version` to find the version. If you need to install or upgrade, see [Install Azure CLI](/cli/azure/install-azure-cli).
31
31
32
+
## Define Environment Variables
33
+
Environment variables are commonly used in Linux to centralize configuration data to improve consistency and maintainability of the system. Create the following environment variables to specify the names of resources that will be created later in this tutorial:
34
+
35
+
```azurecli-interactive
36
+
export RESOURCE_GROUP_NAME=myResourceGroup
37
+
export LOCATION=eastus
38
+
export VM_NAME=myVM
39
+
export VM_IMAGE=debian
40
+
export ADMIN_USERNAME=azureuser
41
+
```
42
+
32
43
## Create a resource group
33
44
34
-
Create a resource group with the [az group create](/cli/azure/group) command. An Azure resource group is a logical container into which Azure resources are deployed and managed. The following example creates a resource group named *myResourceGroup* in the *eastus* location:
45
+
Create a resource group with the [az group create](/cli/azure/group) command. An Azure resource group is a logical container into which Azure resources are deployed and managed.
35
46
36
47
```azurecli-interactive
37
-
az group create --name myResourceGroup --location eastus
48
+
az group create --name $RESOURCE_GROUP_NAME --location $LOCATION
38
49
```
39
50
40
51
## Create virtual machine
41
52
42
53
Create a VM with the [az vm create](/cli/azure/vm) command.
43
54
44
-
The following example creates a VM named *myVM*and adds a user account named *azureuser*. The `--generate-ssh-keys` parameter is used to automatically generate an SSH key, and put it in the default key location (*~/.ssh*). To use a specific set of keys instead, use the `--ssh-key-values` option.
55
+
The following example creates a VM and adds a user account. The `--generate-ssh-keys` parameter is used to automatically generate an SSH key, and put it in the default key location (*~/.ssh*). To use a specific set of keys instead, use the `--ssh-key-values` option.
45
56
46
57
```azurecli-interactive
47
58
az vm create \
48
-
--resource-group myResourceGroup \
49
-
--name myVM \
50
-
--image Debian \
51
-
--admin-username azureuser \
52
-
--generate-ssh-keys
59
+
--resource-group $RESOURCE_GROUP_NAME \
60
+
--name $VM_NAME \
61
+
--image $VM_IMAGE \
62
+
--admin-username $ADMIN_USERNAME \
63
+
--generate-ssh-keys \
64
+
--public-ip-sku Standard
53
65
```
54
66
55
67
It takes a few minutes to create the VM and supporting resources. The following example output shows the VM create operation was successful.
To see your VM in action, install the NGINX web server. Update your package sources and then install the latest NGINX package.
94
+
To see your VM in action, install the NGINX web server. Update your package sources and then install the latest NGINX package. The following command uses run-command to run `sudo apt-get update && sudo apt-get install -y nginx` on the VM:
By default, only SSH connections are opened when you create a Linux VM in Azure. Use [az vm open-port](/cli/azure/vm) to open TCP port 80 for use with the NGINX web server:
87
106
88
107
```azurecli-interactive
89
-
az vm open-port --port 80 --resource-group myResourceGroup --name myVM
108
+
az vm open-port --port 80 --resource-group $RESOURCE_GROUP_NAME --name $VM_NAME
90
109
```
91
110
92
111
## View the web server in action
@@ -95,12 +114,48 @@ Use a web browser of your choice to view the default NGINX welcome page. Use the
95
114
96
115

97
116
117
+
Alternatively, run the following command to see the NGINX welcome page in the terminal
118
+
119
+
```azurecli-interactive
120
+
curl $IP_ADDRESS
121
+
```
122
+
123
+
The following example shows the default NGINX web site in the terminal as successful output:
124
+
<!--expected_similarity=0.8-->
125
+
```html
126
+
<!DOCTYPE html>
127
+
<html>
128
+
<head>
129
+
<title>Welcome to nginx!</title>
130
+
<style>
131
+
body {
132
+
width: 35em;
133
+
margin: 0auto;
134
+
font-family: Tahoma, Verdana, Arial, sans-serif;
135
+
}
136
+
</style>
137
+
</head>
138
+
<body>
139
+
<h1>Welcome to nginx!</h1>
140
+
<p>If you see this page, the nginx web server is successfully installed and
141
+
working. Further configuration is required.</p>
142
+
143
+
<p>For online documentation and support please refer to
144
+
<ahref="http://nginx.org/">nginx.org</a>.<br/>
145
+
Commercial support is available at
146
+
<ahref="http://nginx.com/">nginx.com</a>.</p>
147
+
148
+
<p><em>Thank you for using nginx.</em></p>
149
+
</body>
150
+
</html>
151
+
```
152
+
98
153
## Clean up resources
99
154
100
155
When no longer needed, you can use the [az group delete](/cli/azure/group) command to remove the resource group, VM, and all related resources.
101
156
102
157
```azurecli-interactive
103
-
az group delete --name myResourceGroup
158
+
az group delete --name $RESOURCE_GROUP_NAME --no-wait --yes --verbose
0 commit comments