快速入門:在 Azure 入口網站中建立 Linux 虛擬機器Quickstart: Create a Linux virtual machine in the Azure portal

您可以透過 Azure 入口網站建立 Azure 虛擬機器 (VM)。Azure virtual machines (VMs) can be created through the Azure portal. Azure 入口網站是以瀏覽器為基礎的使用者介面,可用來建立 Azure 資源。The Azure portal is a browser-based user interface to create Azure resources. 本快速入門說明如何使用 Azure 入口網站,來部署執行 Ubuntu 18.04 LTS 的 Linux 虛擬機器 (VM)。This quickstart shows you how to use the Azure portal to deploy a Linux virtual machine (VM) running Ubuntu 18.04 LTS. 為了查看作用中的 VM,您還會以 SSH 連線至 VM,並安裝 NGINX 網頁伺服器。To see your VM in action, you also SSH to the VM and install the NGINX web server.

如果您沒有 Azure 訂用帳戶,請在開始前建立 免費帳戶If you don't have an Azure subscription, create a free account before you begin.

建立 SSH 金鑰組Create SSH key pair

您必須要有 SSH 金鑰組,才能完成本快速入門的操作。You need an SSH key pair to complete this quickstart. 如果您已經擁有 SSH 金鑰組,則可略過此步驟。If you already have an SSH key pair, you can skip this step.

開啟 Bash 殼層,然後使用 ssh-keygen 來建立 SSH 金鑰組。Open a bash shell and use ssh-keygen to create an SSH key pair. 如果本機電腦上沒有 Bash 殼層,則可以使用 Azure Cloud ShellIf you don't have a bash shell on your local computer, you can use the Azure Cloud Shell.

  1. 登入 Azure 入口網站Sign in to the Azure portal.
  2. 在頁面頂端的功能表中,選取 >_ 圖示以開啟 Cloud Shell。In the menu at the top of the page, select the >_ icon to open Cloud Shell.
  3. 請確定 CloudShell 在左上方顯示 BashMake sure the CloudShell says Bash in the upper left. 如果其顯示 PowerShell,請使用下拉式清單來選取 [Bash] ,然後選取 [確認] 以變更為 Bash 殼層。If it says PowerShell, use the drop-down to select Bash and select Confirm to change to the Bash shell.
  4. 輸入 ssh-keygen -t rsa -b 2048 以建立 ssh 金鑰。Type ssh-keygen -t rsa -b 2048 to create the ssh key.
  5. 系統會提示您輸入用來儲存金鑰組的檔案。You will be prompted to enter a file in which to save the key pair. 只要按 Enter 鍵即可儲存在預設位置 (以括弧列出)。Just press Enter to save in the default location, listed in brackets.
  6. 系統會要求您輸入複雜密碼。You will be asked to enter a passphrase. 您可以輸入 SSH 金鑰的複雜密碼,或按 Enter 鍵以無複雜密碼的狀態繼續進行。You can type a passphrase for your SSH key or press Enter to continue without a passphrase.
  7. ssh-keygen 命令會在 ~/.ssh directory 中產生具有預設名稱 id_rsa 的公開和私密金鑰。The ssh-keygen command generates public and private keys with the default name of id_rsa in the ~/.ssh directory. 此命令會傳回公開金鑰的完整路徑。The command returns the full path to the public key. 請使用公開金鑰的路徑,透過輸入 cat ~/.ssh/id_rsa.pub 來以 cat 顯示其內容。Use the path to the public key to display its contents with cat by typing cat ~/.ssh/id_rsa.pub.
  8. 複製此命令的輸出,並將其儲存在某處以供本文稍後使用。Copy the output of this command and save it somewhere to use later in this article. 這是您的公開金鑰,您會在設定用來登入 VM 的系統管理員帳戶時用到它。This is your public key and you will need it when configuring your administrator account to log in to your VM.

登入 AzureSign in to Azure

請先登入 Azure 入口網站 (如果您尚未登入)。Sign in to the Azure portal if you haven't already.

建立虛擬機器Create virtual machine

  1. 選擇 Azure 入口網站左上角的 [建立資源] 。Choose Create a resource in the upper left corner of the Azure portal.

  2. 在 [熱門] 中,選取 [Ubuntu Server 18.04 LTS] 。In Popular, select Ubuntu Server 18.04 LTS.

  3. 在 [基本資料] 索引標籤中的 [專案詳細資料] 底下,確認已選取正確的訂用帳戶,然後在 [資源群組] 下方選擇 [新建] 。In the Basics tab, under Project details, make sure the correct subscription is selected and then choose to Create new under Resource group. 輸入 myResourceGroup 作為資源群組的名稱,然後選擇 [確定] 。Type myResourceGroup for the name of the resource group and then choose OK.

    為您的 VM 建立新的資源群組

  4. 在 [執行個體詳細資料] 底下,輸入 myVM 作為 [虛擬機器名稱] ,然後選擇 [美國東部] 作為您的 [區域] 。Under Instance details, type myVM for the Virtual machine name and choose East US for your Region. 其他部分保留預設值。Leave the other defaults.

    執行個體詳細資料區段

  5. 在 [系統管理員帳戶] 下方選取 [SSH 公開金鑰] ,輸入您的使用者名稱,然後貼上您的公開金鑰。Under Administrator account, select SSH public key, type your user name, then paste in your public key. 請移除公開金鑰中的任何前置或尾端的空白字元。Remove any leading or trailing white space in your public key.

    系統管理員帳戶

  6. 在 [輸入連接埠規則] > [公用輸入連接埠] 下方,選擇 [允許選取的連接埠] ,然後從下拉式清單中選取 [SSH (22)] 和 [HTTP (80)] 。Under Inbound port rules > Public inbound ports, choose Allow selected ports and then select SSH (22) and HTTP (80) from the drop-down.

    開啟 RDP 和 HTTP 的連接埠

  7. 保留其餘預設值,然後在頁面底部選取 [檢閱 + 建立] 按鈕。Leave the remaining defaults and then select the Review + create button at the bottom of the page.

  8. 在 [建立虛擬機器] 頁面上,您可以看到即將建立的 VM 詳細資料。On the Create a virtual machine page, you can see the details about the VM you are about to create. 準備完成後,請選取 [建立] 。When you are ready, select Create.

可能需要幾分鐘的時間才能部署好 VM。It will take a few minutes for your VM to be deployed. 部署完成時,請前往下一節。When the deployment is finished, move on to the next section.

連線至虛擬機器Connect to virtual machine

建立與 VM 的 SSH 連線。Create an SSH connection with the VM.

  1. 在 VM 的 [概觀] 頁面上選取 [連線] 按鈕。Select the Connect button on the overview page for your VM.

    入口網站 9

  2. 在 [連線至虛擬機器] 頁面中,維持預設選項,以便使用 IP 位址透過連接埠 22 進行連線。In the Connect to virtual machine page, keep the default options to connect by IP address over port 22. 使用 VM 本機帳戶登入中,會顯示連線命令。In Login using VM local account a connection command is shown. 選取按鈕以複製該命令。Select the button to copy the command. 下列範例說明 SSH 連線命令的內容:The following example shows what the SSH connection command looks like:

    ssh azureuser@10.111.12.123
    
  3. 使用和您建立 SSH 金鑰組時所用的同一個 Bash 殼層 (您可以重新開啟 Cloud Shell,方法是再次選取 >_ 或移至 https://shell.azure.com/bash) ,將 SSH 連線命令貼到殼層中,以建立 SSH 工作階段。Using the same bash shell you used to create your SSH key pair (you can reopen the Cloud Shell by selecting >_ again or going to https://shell.azure.com/bash), paste the SSH connection command into the shell to create an SSH session.

安裝 Web 伺服器Install web server

若要查看作用中的 VM,請安裝 NGINX 網頁伺服器。To see your VM in action, install the NGINX web server. 從 SSH 工作階段更新套件來源,然後安裝最新的 NGINX 套件。From your SSH session, update your package sources and then install the latest NGINX package.

sudo apt-get -y update
sudo apt-get -y install nginx

完成時,輸入 exit 來離開 SSH 工作階段。When done, type exit to leave the SSH session.

檢視作用中的網頁伺服器View the web server in action

使用所選的網頁瀏覽器來查看預設 NGINX 歡迎使用頁面。Use a web browser of your choice to view the default NGINX welcome page. 輸入 VM 的公用 IP 位址作為網址。Type the public IP address of the VM as the web address. 您可以在 VM 的 [概觀] 頁面找到公用 IP 位址,也可以在您稍早使用的 SSH 連接字串中找到。The public IP address can be found on the VM overview page or as part of the SSH connection string you used earlier.

預設 NGINX 網站

清除資源Clean up resources

若不再需要,您可以刪除資源群組、虛擬機器和所有相關資源。When no longer needed, you can delete the resource group, virtual machine, and all related resources. 若要這樣做,請選取虛擬機器的資源群組,選取 [刪除] ,然後確認要刪除的資源群組名稱。To do so, select the resource group for the virtual machine, select Delete, then confirm the name of the resource group to delete.

後續步驟Next steps

在此快速入門中,您已部署簡單的虛擬機器、建立網路安全性群組和規則,並已安裝基本的 Web 伺服器。In this quickstart, you deployed a simple virtual machine, created a Network Security Group and rule, and installed a basic web server. 若要深入了解 Azure 虛擬機器,請繼續 Linux VM 的教學課程。To learn more about Azure virtual machines, continue to the tutorial for Linux VMs.