本頁說明安裝 Google Cloud SDK 並將其初始化的方式,以及如何從指令列執行核心 gcloud
指令。
事前準備
如果您還沒有 Google Cloud Platform 專案,請建立 Google Cloud Platform 專案。
請確認您的系統已安裝 Python 2.7:
python -V
下載最適合您作業系統的封存檔。大多數的機器會執行 64 位元套件。
平台 套件 大小 SHA256 總和檢查碼 macOS 64 位元 (x86_64)
google-cloud-sdk-245.0.0-darwin-x86_64.tar.gz 19.6 MB 78cbe75ebf17599217d4a6cb81897897faa72d6e5e0c515a8532c8827de59af7 macOS 32 位元 (x86)
google-cloud-sdk-245.0.0-darwin-x86.tar.gz 19.6 MB 3ca3575f19a21a589a75d2ed3c2a62af7d1be12482ad4cf3efba87e071977a61 將封存檔解壓縮到您檔案系統上的任何位置,最好是主目錄。在 macOS 上,可以在偏好位置開啟
.tar.gz
封存檔來完成此作業。選用步驟: 如在使用gcloud
指令時發生問題,請確認您的$PATH
定義正確。使用安裝指令碼,將 Cloud SDK 工具新增到您的路徑。您也可以在安裝過程中,選擇在您的bash
殼層和使用統計資料收集中使用指令完成功能。請使用下列指令執行指令碼:./google-cloud-sdk/install.sh
重新啟動您的終端機,變更才會生效。
或者,您可以透過完整路徑叫用執行檔下載封存,並於解壓縮後呼叫 Cloud SDK。
初始化 SDK
使用 gcloud init
指令執行數個常見的 SDK 設定工作。這些包含使用您的使用者帳戶憑證和設定預設的 SDK 配置來授權 SDK 工具存取 Google Cloud Platform。
如要初始化 SDK:
在命令提示字元中輸入以下指令:
gcloud init
附註:如要避免指令啟動網路瀏覽器,請改用
gcloud init --console-only
。如果要在不開啟網路瀏覽器並以非互動的方式進行授權,請使用Google Cloud Platform 主控台建立具有適當範圍的服務帳戶,並透過對應的 JSON 金鑰檔案使用gcloud auth activate-service-account
。使用 Google 使用者帳戶並接受登入選項:
To continue, you must log in. Would you like to log in (Y/n)? Y
在您的瀏覽器上,於系統提示時登入 Google 使用者帳戶,按一下 [Allow] (允許) 以授予存取 Google Cloud Platform 資源的權限。
在命令提示字元中,從具有擁有者、編輯者或檢視者權限的清單上選取 Cloud Platform 專案:
Pick cloud project to use: [1] [my-project-1] [2] [my-project-2] ... Please enter your numeric choice:
如果您只有一項專案,則
gcloud init
會自動為您選取。如果您已啟用 Google Compute Engine API,
gcloud init
可讓您選取預設 Compute Engine 區域:Which compute zone would you like to use as project default? [1] [asia-east1-a] [2] [asia-east1-b] ... [14] Do not use default zone Please enter your numeric choice:
gcloud init
會確認您已成功完成設定步驟:gcloud has now been configured! You can use [gcloud config] to change more gcloud settings. Your active configuration is: [default]
執行核心 gcloud 指令
執行下列 gcloud
指令來檢視您的 SDK 安裝相關資訊:
如果要列出本機系統上已儲存憑證的帳戶:
gcloud auth list
gcloud
會顯示具有憑證之帳戶的清單:Credentialed Accounts ACTIVE ACCOUNT * example-user-1@gmail.com example-user-2@gmail.com
如何列出您所使用 SDK 配置中的屬性:
gcloud config list
gcloud
會顯示屬性清單:[core] account = example-user-1@gmail.com disable_usage_reporting = False project = example-project
如何查看您的 Cloud SDK 安裝和使用中 SDK 設定的相關資訊:
gcloud info
gcloud
會顯示您的 Cloud SDK 安裝相關摘要資訊,這包含您系統中的相關資訊、已安裝 SDK 元件、使用中的使用者帳戶與目前專案,以及使用中 SDK 設定的屬性。如何查看
gcloud
指令和指令列中的其他主題相關資訊:gcloud help
舉例來說,如果您想查看
gcloud compute instances create
的說明:gcloud help compute instances create
gcloud
會顯示包含指令說明、指令標記和引數的清單,以及如何使用它的說明主題。
後續步驟
- 請閱讀
gcloud
工具指南以取得gcloud
指令列工具的基本說明,包含重要概念、指令慣例和實用提示的快速簡介。 - 請閱讀
gcloud
參考指南以取得每個gcloud
指令的詳細介紹頁面,包含說明、標記和範例等等。您可以使用這些指令在 Google Cloud Platform 上執行各種工作。 - 使用 Cloud SDK 元件管理員安裝如 App Engine 模擬器或
kubectl
等的附加元件。