本教學課程示範如何在 Compute Engine 的 Microsoft Windows 虛擬機器 (VM) 執行個體上設定 Chrome 遠端桌面。如需 Linux VM 的個別操作說明,請參閱「Linux 虛擬機器」。Chrome 遠端桌面可讓您使用本機電腦或行動裝置的圖形使用者介面遠端存取應用程式。
按照本教學課程操作時,預設防火牆規則會允許 Chrome 遠端桌面連線,因此您不需要設定任何額外的防火牆規則。
VM 必須能存取網際網路 (透過外部 IP 位址或 Cloud NAT),且您必須使用 Google 帳戶進行驗證和授權。
本文將說明設定 Chrome 遠端桌面的兩種方法:
使用 Windows 遠端桌面通訊協定 (RDP) 的互動式方法。
這個方法需要使用 RDP 用戶端,從本機直接存取 VM,但這可能不適用於所有情況。
使用開機指令碼的非互動式方法,在建立 VM 時安裝及設定 Chrome 遠端桌面。
如果防火牆禁止直接存取 VM,或是您無法存取 RDP 用戶端 (例如在 ChromeOS 上),就應使用這個方法。
本教學課程假設您熟悉 Microsoft Windows 和 PowerShell 指令列。
如要瞭解建立虛擬工作站的其他選項,請參閱「建立虛擬工作站」。
目標
- 建立要用以執行 Chrome 遠端桌面的 Windows Compute Engine VM 執行個體。
- 在 VM 執行個體上安裝及設定 Chrome 遠端桌面服務。
- 從您的本機電腦連線至 VM 執行個體上的桌面環境。
費用
本教學課程使用 Google Cloud的計費元件,包括:
- Compute Engine
使用 Pricing Calculator 可根據您的預測使用量來產生費用預估。
事前準備
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Compute Engine API.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Compute Engine API.
-
Make sure that you have the following role or roles on the project: roles/compute.admin
Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
Grant the roles
-
In the Google Cloud console, go to the IAM page.
前往 IAM - 選取專案。
- 按一下「授予存取權」 。
-
在「New principals」(新增主體) 欄位中,輸入您的使用者 ID。 這通常是 Google 帳戶的電子郵件地址。
- 在「Select a role」(選取角色) 清單中,選取角色。
- 如要授予其他角色,請按一下 「新增其他角色」,然後新增每個其他角色。
- 按一下 [Save]。
- 在本機電腦上使用 Google Chrome 瀏覽器。
- 如果使用互動式方法,本機電腦必須有 RDP 用戶端,且能直接連線至遠端 VM 執行個體。
-
完成本文所述工作後,您可以刪除已建立的資源,避免繼續計費。詳情請參閱清除所用資源一節。
使用 RDP 進行互動式安裝
如要以互動方式安裝 Chrome 遠端桌面,您必須使用遠端桌面通訊協定用戶端連線至遠端 VM。在本教學課程中,您會在預設 VPC 中建立 VM,並使用預設防火牆規則,將 RDP 通訊埠 3339 公開至網際網路。
如果您的環境不允許這麼做,請使用本文稍後說明的非互動式方法。
建立 Compute Engine 執行個體
為符合本教學課程的目的,請使用預設機器類型。如果您要將這項設定用於自己的環境,可能需要調整機型、名稱、區域、開機磁碟大小或其他設定。
主控台
- 前往 Google Cloud 控制台的「VM Instances」(VM 執行個體) 頁面:
點選「建立」。
將執行個體名稱設為
crdhost
。勾選「啟用顯示裝置」核取方塊,因為 Chrome 遠端桌面需要 Windows VM 上的顯示裝置。
在「Boot disk」(開機磁碟) 下方,按一下「Change」(變更) 開啟「Boot disk」(開機磁碟) 面板。
在「作業系統」清單中,選取「Windows Server」。
在「Version」(版本) 清單中,選取「Windows Server 2022 Datacenter」。
按一下「選取」即可關閉面板。
點選「建立」。
Cloud Shell
開啟 Cloud Shell。
設定偏好的可用區:
ZONE=us-central1-b REGION=us-central1 gcloud config set compute/zone "${ZONE}"
使用 Windows Server 2022 Datacenter 的應用程式映像檔建立 Compute Engine 執行個體:
gcloud compute instances create crdhost \ --machine-type=e2-medium \ --scopes=cloud-platform \ --enable-display-device \ --image-family=windows-2022 \ --image-project=windows-cloud \ --boot-disk-size=50GB \ --boot-disk-device-name=crdhost
這項指令會建立 Windows Server 2022 虛擬機器,並附加顯示裝置 (Windows VM 上的 Chrome 遠端桌面需要此裝置)、50 GB 的開機磁碟,以及授予執行個體Google Cloud API 的完整存取權。
忽略磁碟效能警告,因為本教學課程不需要高效能。
使用遠端桌面通訊協定連線至 VM 執行個體
前往 Google Cloud 控制台的「VM instances」(VM 執行個體) 頁面。
確認
crdhost
執行個體名稱旁顯示綠色勾號 check,表示執行個體已準備就緒。按一下執行個體名稱
crdhost
,開啟「VM instance details」(VM 執行個體詳細資料) 頁面。在「遠端存取」下方,按一下「設定 Windows 密碼」,然後按一下「設定」,在遠端電腦上建立帳戶。
系統會為您產生密碼。記下密碼或複製到安全的臨時檔案。
如要連線至遠端執行個體,請按一下「RDP」按鈕旁邊的箭頭 arrow_drop_down,然後選取「下載遠端桌面協定檔案」。你可以使用偏好的遠端桌面協定用戶端開啟遠端桌面協定檔案。
當遠端桌面協定用戶端提示輸入您密碼時,請輸入之前產生的密碼。
當系統詢問您是否要讓網路上的其他電腦和裝置偵測到您的電腦時,請按一下「否」。
如果「伺服器管理員」資訊主頁已開啟,請將其關閉。
安裝 Chrome 遠端桌面服務
下一步是在 VM 執行個體上安裝 Google Chrome 和 Chrome 遠端桌面服務。
在遠端桌面協定工作階段中,按一下 Windows 工作列上的「開始」,輸入
PowerShell
,然後選取 Windows PowerShell 應用程式。在 PowerShell 提示中,下載並執行 Chrome 遠端桌面主機安裝程式。
$installer = "$env:TEMP\chromeremotedesktophost.msi" $uri = 'https://dl.google.com/edgedl/chrome-remote-desktop/chromeremotedesktophost.msi' (New-Object Net.WebClient).DownloadFile($uri,"$installer") Start-Process $installer -Wait Remove-Item $installer
出現提示時,請確認您要讓安裝程式進行變更。
設定 Chrome 遠端桌面服務
現在請產生 Windows 指令,啟動 Chrome 遠端桌面服務並連結至 Google 帳戶。
在本機電腦上使用 Chrome 瀏覽器,前往 Chrome 遠端桌面指令列設定頁面。
如果您尚未登入,請使用 Google 帳戶登入。這是將會用於授權遠端存取權的帳戶。
在「Set up another computer」頁面上,依序按一下「Begin」和「Next」。
按一下 [授權]。
您需要允許 Chrome 遠端桌面存取您的帳戶。如果您允許,頁面會顯示數個指令列,其中一個是 Windows (Powershell),如下所示:
& "${Env:PROGRAMFILES(X86)}\Google\Chrome Remote Desktop\CurrentVersion\remoting_start_host.exe" ` --code="4/ENCODED_AUTHENTICATION_TOKEN" ` --redirect-url="https://remotedesktop.google.com/_/oauthredirect" ` --name=$Env:COMPUTERNAME
按一下「複製」content_copy,將指令列複製到剪貼簿。
在 RDP 工作階段的 Powershell 提示中,貼上您剛複製的指令列,然後按下 Enter 鍵。
出現提示時,請確認您要允許應用程式進行變更。
當您看到提示時,請輸入 6 位數的 PIN 碼。這個數字會在您之後連線時用於進一步的授權。
指令執行完畢後,遠端桌面服務就會啟動。
關閉 Powershell 視窗。
關閉 RDP 工作階段。
您現在可以使用 Chrome 遠端桌面連線至 VM。
非互動式安裝
在這個方法中,您會將 VM 執行個體設定為具有開機指令碼,在建立 VM 時執行。
採用這種做法時,VM 不必從網際網路直接存取,但仍需存取網際網路。
授權 Chrome 遠端桌面服務
現在請產生 Windows 指令,稍後會在 specialize 指令碼中使用。 在此程序中,您會提供指令中包含的授權資訊。
在本機電腦上使用 Chrome 瀏覽器,前往 Chrome 遠端桌面指令列設定頁面。
如果您尚未登入,請使用 Google 帳戶登入。這是將會用於授權遠端存取權的帳戶。
依序點選「開始」和「下一步」。
按一下 [授權]。
允許 Chrome 遠端桌面存取您的帳戶。
現在頁面包含數個指令列,其中一個是 Windows (Cmd),如下所示:
"%PROGRAMFILES(X86)%\Google\Chrome Remote Desktop\CurrentVersion\remoting_start_host.exe" --code="4/ENCODED_AUTHENTICATION_TOKEN" --redirect-url="https://remotedesktop.google.com/_/oauthredirect" --name=%COMPUTERNAME%
--code
旗標包含專屬的短期 OAuth 權杖。指令列中的授權碼有效期限只有幾分鐘的時間,而且只能使用一次。
請保持開啟這個頁面。
將啟動指令複製到 Cloud Shell
下一步是在 Cloud Shell 執行個體中建立檔案,其中包含您剛才產生的啟動指令。
開啟 Cloud Shell。
建立開機指令的檔案:
cat > crd-auth-command.txt
前往含有 Chrome 遠端桌面啟動指令的頁面,然後複製「Windows (Cmd)」指令列。
在 Cloud Shell 中貼上指令,將其新增至檔案。
按下 Enter 鍵結束行,然後按下 Ctrl-D 鍵關閉檔案。
建立開機指令碼
複製下列程式碼區塊,然後貼到 Cloud Shell。
cat << "EOF" > crd-sysprep-script.ps1 <# .SYNOPSIS GCESysprep specialize script for unattended Chrome Remote Desktop installation. #> $ErrorActionPreference = 'stop' function Get-Metadata([String]$metadataName) { try { $value = (Invoke-RestMethod ` -Headers @{'Metadata-Flavor' = 'Google'} ` -Uri "http://metadata.google.internal/computeMetadata/v1/instance/attributes/$metadataName") } catch { # Report but ignore REST errors. Write-Host $_ } if ($value -eq $null -or $value.Length -eq 0) { throw "Metadata value for ""$metadataName"" not specified. Skipping Chrome Remote Desktop service installation." } return $value } # Get config from metadata # $crdCommand = Get-Metadata('crd-command') $crdPin = Get-Metadata('crd-pin') $crdName = Get-Metadata('crd-name') if ($crdPin -isNot [Int32] -or $crdPin -gt 999999 -or $crdPin -lt 0) { throw "Metadata ""crd-pin""=""$crdPin"" is not a 6 digit number. Skipping Chrome Remote Desktop service installation." } # Prefix $crdPin with zeros if required. $crdPin = $crdPin.ToString("000000"); # Extract the authentication code and redirect URL arguments from the # remote dekstop startup command line. # $crdCommandArgs = $crdCommand.Split(' ') $codeArg = $crdCommandArgs | Select-String -Pattern '--code="[^"]+"' $redirectArg = $crdCommandArgs | Select-String -Pattern '--redirect-url="[^"]+"' if (-not $codeArg) { throw 'Cannot get --code= parameter from crd-command. Skipping Chrome Remote Desktop service installation.' } if (-not $redirectArg) { throw 'Cannot get --redirect-url= parameter from crd-command. Skipping Chrome Remote Desktop service installation.' } Write-Host 'Downloading Chrome Remote Desktop.' $installer = "$env:TEMP\chromeremotedesktophost.msi" $uri = 'https://dl.google.com/edgedl/chrome-remote-desktop/chromeremotedesktophost.msi' (New-Object Net.WebClient).DownloadFile($uri,"$installer") Write-Host 'Installing Chrome Remote Desktop.' & msiexec.exe /I $installer /qn /quiet | Out-Default Remove-Item $installer Write-Host 'Starting Chrome Remote Desktop service.' & "${env:ProgramFiles(x86)}\Google\Chrome Remote Desktop\CurrentVersion\remoting_start_host.exe" ` $codeArg $redirectArg --name="$crdName" -pin="$crdPin" | Out-Default Write-Host 'Downloading Chrome.' $installer = "$env:TEMP\chrome_installer.exe" $uri = 'https://dl.google.com/chrome/install/latest/chrome_installer.exe' (New-Object Net.WebClient).DownloadFile($uri,"$installer") Write-Host 'Installing Chrome.' & $installer /silent /install | Out-Default Remove-Item $installer EOF
這個程式碼區塊是 PowerShell 指令碼,會在建立 VM 時執行。這個指令會執行下列動作:
- 下載並安裝 Chrome 遠端桌面主機服務。
- 擷取下列中繼資料參數:
crd-command
- Windows 驗證和啟動指令。crd-pin
- 用於額外驗證的 6 位數 PIN 碼。crd-name
- 這個執行個體的名稱。
- 設定及啟動 Chrome 遠端桌面主機服務。
- 下載並安裝 Chrome 瀏覽器。
建立新的 Windows 虛擬機器
現在,請使用先前建立的檔案建立新的 Windows VM,以便設定及安裝 Chrome 遠端桌面。
在本教學課程中,我們將使用 e2-medium
機器類型。如果您要在自己的環境中使用這項功能,可能需要調整機器類型、名稱、地區、開機磁碟大小或其他設定。
在 Cloud Shell 中設定偏好的可用區:
ZONE=us-central1-b REGION=us-central1 gcloud config set compute/zone "${ZONE}"
設定 6 位數 PIN 碼,做為 Chrome 遠端桌面的額外驗證方式:
CRD_PIN=your-pin
將 your-pin 改為 6 位數。
為這個 VM 執行個體設定名稱:
INSTANCE_NAME=crdhost
建立執行個體:
gcloud compute instances create ${INSTANCE_NAME} \ --machine-type=e2-medium \ --scopes=cloud-platform \ --enable-display-device \ --image-family=windows-2022 \ --image-project=windows-cloud \ --boot-disk-size=50GB \ --boot-disk-device-name=${INSTANCE_NAME} \ --metadata=crd-pin=${CRD_PIN},crd-name=${INSTANCE_NAME} \ --metadata-from-file=crd-command=crd-auth-command.txt,sysprep-specialize-script-ps1=crd-sysprep-script.ps1
這個指令會在預設 VPC 中建立 Windows Server 2022 虛擬機器,並附加顯示裝置 (Windows VM 上的 Chrome 遠端桌面需要此裝置)、50 GB 的開機磁碟,以及授予執行個體 Google Cloud API 的完整存取權。
中繼資料值會指定專屬指令碼、Windows 開機命令列,以及啟動 Chrome 遠端桌面服務所需的參數。
監控 VM 啟動程序
如要確認開機指令碼是否成功執行,請檢查建立 VM 時記錄到 VM 序列埠的訊息。
在 Cloud Shell 中,顯示 VM 啟動期間記錄的訊息:
gcloud compute instances tail-serial-port-output ${INSTANCE_NAME}
如果 Chrome 遠端桌面設定成功,您會看到下列記錄檔行:
Found sysprep-specialize-script-ps1 in metadata. sysprep-specialize-script-ps1: Downloading Chrome Remote Desktop. sysprep-specialize-script-ps1: Installing Chrome Remote Desktop. sysprep-specialize-script-ps1: Downloading Chrome. sysprep-specialize-script-ps1: Installing Chrome. sysprep-specialize-script-ps1: Starting Chrome Remote Desktop service. Finished running specialize scripts.
您也可能會看到下列這行:
sysprep-specialize-script-ps1: ... Failed to read 'C:\ProgramData\Google\Chrome Remote Desktop\host_unprivileged.json'.: The system cannot find the path specified. (0x3)
這是正常現象,可以忽略。
如果無法啟動 Chrome 遠端桌面服務,系統會顯示指出問題的錯誤訊息,例如:
sysprep-specialize-script-ps1: Couldn't start host: OAuth error.
這項錯誤表示 Chrome 遠端桌面驗證頁面的 OAuth 權杖已失效,可能是因為權杖已使用過或已過期。
如要修正這項錯誤,請使用遠端桌面協定連線,並按照先前的說明執行互動式設定,或刪除 VM 並重試設定程序。
當序列埠監控器中顯示以下訊息時,表示 VM 已準備就緒。
GCEInstanceSetup: ------------------------------------------------------------ GCEInstanceSetup: Instance setup finished. crdhost is ready to use. GCEInstanceSetup: ------------------------------------------------------------
按下 Ctrl-C 即可停止顯示啟動訊息。
建立 Windows 使用者帳戶
前往 Google Cloud 控制台的「VM instances」(VM 執行個體) 頁面。
按一下執行個體名稱
crdhost
,開啟「VM instance details」(VM 執行個體詳細資料) 頁面。在「遠端存取」下方,按一下「設定 Windows 密碼」,然後按一下「設定」,在遠端電腦上建立帳戶。
系統會為您產生密碼。記下使用者名稱和密碼,或複製到安全的暫時性檔案。
使用 Chrome 遠端桌面連線至 VM 執行個體
您可以使用 Chrome 遠端桌面網頁應用程式連線至 VM 執行個體。
在本機電腦上,前往 Chrome 遠端桌面網站。
按一下「存取我的電腦」。
如果您尚未登入 Google,請使用您用於設定 Chrome 遠端桌面服務的 Google 帳戶登入。
您會在「Remote Devices」清單中看見新的 VM 執行個體
crdhost
。按一下遠端桌面執行個體的名稱。
系統出現提示時,輸入您之前建立的 PIN 碼,然後按一下箭號按鈕 arrow_forward 進行連線。
您現在已連線至遠端 Compute Engine 執行個體上的 Windows 登入畫面。
如果系統提示您,請一律允許遠端桌面應用程式讀取剪貼簿,並允許您在本機和遠端應用程式之間複製及貼上內容。
按下任意鍵,然後輸入先前產生的 Windows 使用者密碼。請注意,預設的遙控器鍵盤採用美式英文配置,因此輸入的字元可能與本機鍵盤上的字元不符。您也無法複製及貼上密碼。
您現在已連線並登入遠端 Windows 桌面。
改善遠端桌面體驗
本節提供變更設定的操作說明,可協助您改善遠端桌面體驗。
安裝 Chrome 遠端桌面應用程式
Chrome 遠端桌面應用程式提供獨立的視窗體驗,並允許在遠端系統上使用通常會遭 Chrome 攔截的鍵盤快速鍵。
如果未安裝這個應用程式,請按照下列步驟操作:
- 將滑鼠移至視窗側邊時,會出現 chevron_left 按鈕,點選即可開啟「工作階段選項」面板。
- 在「安裝應用程式」部分中,按一下「開始」。
- 按一下 [安裝]。
遠端桌面連線會在專屬應用程式視窗中重新開啟。
如要將任何遠端桌面工作階段從 Chrome 分頁移至應用程式視窗,請按一下網址列中的「以...開啟」open_in_new圖示。
提高螢幕解析度
您可以修改預設的遠端桌面解析度,使其更符合本機電腦的桌面解析度。
- 在遠端桌面的背景上按一下滑鼠右鍵,然後選取「顯示設定」。
- 在「解析度」下拉式清單中,選取其他螢幕解析度。
- 在對話方塊中確認新的螢幕解析度。
重新啟用服務
如果您在用戶端應用程式中錯誤地停用了遠端執行個體的連線,可以重新設定服務並按照設定 Chrome 遠端桌面服務的操作說明重新啟用連線。
清除所用資源
如要避免系統向您的 Google Cloud 帳戶收取本教學課程中所用資源的相關費用,請刪除含有該項資源的專案,或者保留專案但刪除個別資源。
刪除專案
如要避免付費,最簡單的方法就是刪除您為了本教學課程所建立的專案。
如要刪除專案:
- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.
刪除 Compute Engine 執行個體
您不必刪除完整專案,而是可以刪除針對本教學課程建立的 VM 執行個體:
找出您之前建立的執行個體名稱 (
crdhost
),並選取旁邊的核取方塊。點選頁面頂端的 [Delete] (刪除) 按鈕。
刪除執行個體需要一些時間。
取消執行個體的 Chrome 遠端桌面授權
如果您不想再連線至 VM 執行個體,可以將其停用,並從「Remote Devices」清單中移除該執行個體。
- 在本機電腦上,前往 Chrome 遠端桌面遠端裝置清單網站。
- 按一下執行個體名稱旁的
crdhost
。 - 按一下 [OK] 以確認停用該遠端裝置連線。
後續步驟
- 瞭解如何在 Linux 虛擬機器上設定 Chrome 遠端桌面。
- 瞭解建立虛擬工作站的其他選項。
- 探索 Google Cloud 的參考架構、圖表和最佳做法。 歡迎瀏覽我們的雲端架構中心。