练习 - 在 VM 上安装软件

已完成

我们最不希望在 VM 上尝试的便是安装 Web 服务器。 最易于安装的包之一是 nginx

安装 NGINX Web 服务器

  1. 查找 SampleVM Linux 虚拟机的公共 IP 地址。

    az vm list-ip-addresses --name SampleVM --output table
    
  2. 接下来,请使用上一步中的公共 IP 地址打开与 SampleVMssh连接。

    ssh azureuser@<PublicIPAddress>
    
  3. 登录虚拟机后,运行下面的命令以安装 nginx Web 服务器。 此命令需要花费一些时间来完成。

    sudo apt-get -y update && sudo apt-get -y install nginx
    
  4. 退出安全外壳:

    exit
    

检索默认页面

  1. 在 Azure Cloud Shell 中,使用 curl,通过运行以下命令(将 <PublicIPAddress> 替换为之前找到的公共 IP),从 Linux Web 服务器读取默认页面。 也可以打开新的浏览器标签页,并尝试转到公共 IP 地址。

    curl -m 80 <PublicIPAddress>
    

    此命令会失败,因为 Linux 虚拟机不会通过可保护与虚拟机的网络连接的网络安全组公开端口 80 (http)。 可运行 Azure CLI 命令 vm open-port 修复该故障。

  2. 在 Cloud Shell 中输入以下命令以打开端口 80:

    az vm open-port \
        --port 80 \
        --resource-group <rgn>[sandbox resource group name]</rgn> \
        --name SampleVM
    

    需要一段时间,才能添加网络规则,并通过防火墙打开端口。

  3. 再次运行命令 curl

    curl -m 80 <PublicIPAddress>
    

    这次它应返回类似下面的数据。 也可以在浏览器中查看该页面。

    <!DOCTYPE html>
    <html>
    <head>
    <title>Welcome to nginx!</title>
    <style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
    </style>
    </head>
    <body>
    <h1>Welcome to nginx!</h1>
    <p>If you see this page, the nginx web server is successfully installed and
    working. Further configuration is required.</p>
    
    <p>For online documentation and support, refer to
    <a href="http://nginx.org/">nginx.org</a>.<br/>
    Commercial support is available at
    <a href="http://nginx.com/">nginx.com</a>.</p>
    
    <p><em>Thank you for using nginx.</em></p>
    </body>
    </html>