筆記:google cloud sdk 命令列工具
直接以命令操作 google cloud 的工具
https://cloud.google.com/sdk/
直接下載 (分 Linux / MacOS / Windows 三種版本)
https://cloud.google.com/sdk/downloads#versioned
下載、解壓縮
$ zcat google-cloud-sdk-182.0.0-linux-x86_64.tar.gz |tar xfv -
解開後 放在 google-cloud-sdk 目錄底下 (解開後 大約 126MB)
$ cd google-cloud-sdk
第一次使用:
~/google-cloud-sdk$ bin/gcloud auth login
Go to the following link in your browser:
https://accounts.google.com/o/oauth2/auth?redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&prompt=select_account&response_type=code&client_id=xxxxxxxxx.apps.googleusercontent.com&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faccounts.reauth&access_type=offline
Enter verification code:
畫面顯示上面這網址,把它複製到瀏覽器,會要求你登入 google ,然後顯示一串認證文字
類似這樣 4/AIVX0y_pP2AIbEnV3KzuSUNbRLQxxxxccccsss
把這文字貼到端機可
以上就表示當執行 gcloud 時
會以你的 google 帳號權限去操作 GCP
一些操作 GCP 範例
要先指定操作哪個 PROJECT:
~/google-cloud-sdk$ bin/gcloud config set project [PROJECT_ID]
Updated property [core/project].
**注意,這裡是帶入 PROJECT_ID 而不是 PROJECT NAME
顯示已經有哪些 snapshot
~/google-cloud-sdk$ bin/gcloud compute snapshots list
NAME DISK_SIZE_GB SRC_DISK STATUS
snapshot-disk-pd1-20170827-154411 6000 asia-east1-c/disks/disk-pd1 READY
snapshot-disk-pd1-20171013-114137 6000 asia-east1-c/disks/disk-pd1 READY
snapshot-disk-pd1-20171021-233402 6000 asia-east1-c/disks/disk-pd1 READY
snapshot-disk-pd1-20171028-112933 6000 asia-east1-c/disks/disk-pd1 READY
列出有哪些硬碟
~/google-cloud-sdk$ bin/gcloud compute disks list
NAME ZONE SIZE_GB TYPE STATUS
disk-pd1 asia-east1-c 6000 pd-standard READY
disk-pd2 asia-east1-c 2000 pd-ssd READY
列出有哪些硬碟 (JSON格式)
~/google-cloud-sdk$ bin/gcloud compute disks list --format json
[
{
"creationTimestamp": "2015-06-05T01:43:56.621-07:00",
"id": "5344671629204811111",
"kind": "compute#disk",
"labelFingerprint": "42WmSp11111=",
"lastAttachTimestamp": "2015-06-05T01:44:27.052-07:00",
"name": "disk-pd1",
"selfLink": "https://www.googleapis.com/compute/v1/projects/hello1234/zones/asia-east1-c/disks/disk-pd1",
"sizeGb": "6000",
"status": "READY",
"type": "https://www.googleapis.com/compute/v1/projects/hello1234/zones/asia-east1-c/diskTypes/pd-standard",
"users": [
"https://www.googleapis.com/compute/v1/projects/hello1234/zones/asia-east1-c/instances/instance-xxxx"
],
"zone": "https://www.googleapis.com/compute/v1/projects/hello1234/zones/asia-east1-c"
},
..略...
對某個硬碟做 snapshot
~/google-cloud-sdk$ bin/gcloud compute disks snapshot [disk name] --snapshot-name [snapshot名稱] --zone asia-east1-c
例如
~/google-cloud-sdk$ bin/gcloud compute disks snapshot disk-pd1 -snapshot-name disk-pd1-20171211 --zone asia-east1-c
打 bin/gcloud 有更多 help
**相關的認證資料,都放在
~/.config
相關文章