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
# Quickstart: Create a Linux server VM by using the Azure CLI in Azure Stack Hub
16
12
17
13
You can create an Ubuntu Server 20.04 LTS virtual machine (VM) by using the Azure CLI. In this article, you create and use a virtual machine. This article also shows you how to:
@@ -30,7 +26,7 @@ Before you begin, make sure you have the following prerequisites:
30
26
31
27
* Azure Stack Hub requires a specific version of the Azure CLI to create and manage its resources. If you don't have the Azure CLI configured for Azure Stack Hub, sign in to a Windows-based external client if you're connected through VPN, and follow the instructions for [installing and configuring the Azure CLI](azure-stack-version-profiles-azurecli2.md).
32
28
33
-
* A public Secure Shell (SSH) key with the name `id_rsa.pub` saved in the **.ssh** directory of your Windows user profile. For more information about creating SSH keys, see [Use an SSH key pair with Azure Stack Hub](azure-stack-dev-start-howto-ssh-public-key.md).
29
+
* A public Secure Shell (SSH) key with the name **id_rsa.pub** saved in the **.ssh** directory of your Windows user profile. For more information about creating SSH keys, see [Use an SSH key pair with Azure Stack Hub](azure-stack-dev-start-howto-ssh-public-key.md).
34
30
35
31
## Create a resource group
36
32
@@ -39,24 +35,66 @@ A resource group is a logical container where you can deploy and manage Azure St
39
35
> [!NOTE]
40
36
> We assigned values for all variables in the following code examples. However, you can assign your own values.
41
37
42
-
The following example creates a resource group named myResourceGroup in the local location:
38
+
The following example creates a resource group named myResourceGroup with a random suffix in the local location:
43
39
44
40
```azurecli
45
-
az group create --name myResourceGroup --location local
Create a virtual machine by using the [az vm create](/cli/azure/vm#az-vm-create) command. The following example creates a VM named myVM. The example uses `Demouser` as the admin username and `Demouser@123` as the admin password. Change these values to something that's appropriate for your environment.
66
+
Create a virtual machine by using the [az vm create](/cli/azure/vm#az-vm-create) command. The following example creates a VM named myVM. The example uses `Demouser` as the admin username. Change these values to something that's appropriate for your environment.
The public IP address is returned in the `PublicIpAddress` parameter. Note the address for later use with the virtual machine.
@@ -66,45 +104,83 @@ The public IP address is returned in the `PublicIpAddress` parameter. Note the a
66
104
Because this virtual machine runs the IIS web server, you must open port 80 to internet traffic. To open the port, use the [az vm open-port](/cli/azure/vm) command:
67
105
68
106
```azurecli
69
-
az vm open-port --port 80 --resource-group myResourceGroup --name myVM
107
+
az vm open-port --port 80 --resource-group $RESOURCE_GROUP --name $VM_NAME
70
108
```
71
109
72
-
## Use SSH to connect to the virtual machine
110
+
Results:
111
+
112
+
```JSON
113
+
{
114
+
"endPort": 80,
115
+
"name": "openPort80",
116
+
"port": 80,
117
+
"protocol": "Tcp",
118
+
"provisioningState": "Succeeded",
119
+
"resourceGroup": "myResourceGroupxxx",
120
+
"startPort": 80
121
+
}
122
+
```
73
123
74
-
From a client computer with SSH installed, connect to the virtual machine. If you work on a Windows client, use [PuTTY](https://www.putty.org/) to create the connection. To connect to the virtual machine, use the following command:
124
+
## Use SSH to connect to the virtual machine
75
125
76
-
```bash
77
-
ssh <publicIpAddress>
78
-
```
126
+
From a client computer with SSH installed, connect to the virtual machine. If you work on a Windows client, use [PuTTY](https://www.putty.org/) to create the connection. To connect to the virtual machine, you can use the `ssh` command.
79
127
80
128
## Install the NGINX web server
81
129
82
130
To update package resources and install the latest NGINX package, run the following script:
extracted=$(echo "$value"| awk '/\[stdout\]/,/\[stderr\]/'| sed '/\[stdout\]/d'| sed '/\[stderr\]/d')
136
+
echo"$extracted"
92
137
```
93
138
94
139
## View the NGINX welcome page
95
140
96
-
With the NGINX web server installed, and port 80 open on your virtual machine, you can access the web server by using the virtual machine's public IP address. To do so, open a browser, and go to ```http://<public IP address>```.
97
-
98
-

141
+
With the NGINX web server installed, and port 80 open on your virtual machine, you can access the web server by using the virtual machine's public IP address. To do so, open a browser, and go to `http://<public IP address>`. Alternatively, you can use the **curl** command to view the NGINX welcome page:
99
142
100
-
## Clean up resources
143
+
```bash
144
+
export PUBLIC_IP=$(az vm show -d -g $RESOURCE_GROUP -n $VM_NAME --query publicIps -o tsv)
101
145
102
-
Clean up the resources that you don't need any longer. You can use the [az group delete](/cli/azure/group#az-group-delete) command to remove them. Run the following command:
extracted=$(echo "$value"| awk '/\[stdout\]/,/\[stderr\]/'| sed '/\[stdout\]/d'| sed '/\[stderr\]/d')
149
+
echo"$extracted"
150
+
```
103
151
104
-
```azurecli
105
-
az group delete --name myResourceGroup
152
+
Results:
153
+
154
+
```html
155
+
<!DOCTYPE html>
156
+
<html>
157
+
<head>
158
+
<title>Welcome to nginx!</title>
159
+
<style>
160
+
body {
161
+
width: 35em;
162
+
margin: 0auto;
163
+
font-family: Tahoma, Verdana, Arial, sans-serif;
164
+
}
165
+
</style>
166
+
</head>
167
+
<body>
168
+
<h1>Welcome to nginx!</h1>
169
+
<p>If you see this page, the nginx web server is successfully installed and
170
+
working. Further configuration is required.</p>
171
+
172
+
<p>For online documentation and support please refer to
173
+
<ahref="http://nginx.org/">nginx.org</a>.<br/>
174
+
Commercial support is available at
175
+
<ahref="http://nginx.com/">nginx.com</a>.</p>
176
+
177
+
<p><em>Thank you for using nginx.</em></p>
178
+
</body>
179
+
</html>
106
180
```
107
181
182
+

183
+
108
184
## Next steps
109
185
110
-
In this quickstart, you deployed a basic Linux server virtual machine with a web server. To learn more about Azure Stack Hub virtual machines, see [Considerations for virtual machines in Azure Stack Hub](azure-stack-vm-considerations.md).
186
+
In this quickstart, you deployed a basic Linux server virtual machine with a web server. To learn more about Azure Stack Hub virtual machines, see [Considerations for virtual machines in Azure Stack Hub](azure-stack-vm-considerations.md).
0 commit comments