[GCloud] 讓 gcloud 連到新的 Google 帳戶下的 Google Cloud Platform
前一陣子,家人也加入了 Google Cloud Platform 的行列,
在上面架了 WordPress 的網站,因此我也會上去虛擬機器上看看狀況。
原本的 gcloud 指令只能運作在我自己的 Google 帳號之下,
想要讓 gcloud 可以操作家人的 Google 帳號的話,
其實也蠻簡單的,簡單記錄一下吧~
先看一下目前 gcloud 的設定檔,只有 default 這一筆:
testuser@localhost ~ $ gcloud config configurations list NAME IS_ACTIVE ACCOUNT PROJECT DEFAULT_ZONE DEFAULT_REGION default True myself@gmail.com ephrain-blog asia-east1-a asia-east1
我們可以執行 gcloud init 指令,
在一開始使用 gcloud 時就曾執行過這個命令,但重新執行時,
還可以選擇是要重設目前的組態,還是建立新的組態~
按下 2 就能建立新的組態:
testuser@localhost ~ $ gcloud init Welcome! This command will take you through the configuration of gcloud. Settings from your current configuration [default] are: compute: region: asia-east1 zone: asia-east1-a core: account: myself@gmail.com disable_usage_reporting: 'False' project: ephrain-blog Pick configuration to use: [1] Re-initialize this configuration [default] with new settings [2] Create a new configuration Please enter your numeric choice: 2
取一下新組態的名稱 (這邊我取名為 family):
Enter configuration name. Names start with a lower case letter and contain only lower case letters a-z, digits 0-9, and hyphens '-': family Your current configuration has been set to: [family]
選擇要與哪個 Google 帳戶連結~
這邊可以選擇這機器上有登入過的 Google 帳戶,或是要登入一個新的帳戶~
因為我之前就登入過家人的帳戶 (來申請 Google Cloud Platform) 了,
因此就直接選擇家人的 Google 帳戶:
You can skip diagnostics next time by using the following flag: gcloud init --skip-diagnostics Network diagnostic detects and fixes local network connection issues. Checking network connection...done. Reachability Check passed. Network diagnostic (1/1 checks) passed. Choose the account you would like to use to perform operations for this configuration: [1] myself@gmail.com [2] family@gmail.com [3] Log in with a new account Please enter your numeric choice: 2
接著選擇家人在 Google Cloud Platform 上的專案名稱:
You are logged in as: [family@gmail.com]. Pick cloud project to use: [1] blog-family [2] Create a new project Please enter numeric choice or text value (must exactly match list item): 1
接下來問你是不是要做一些虛擬機器上的設定,選 Y 或 N 都可以。
我是選擇了 Y:
Your current project has been set to: [blog-family]. Do you want to configure Google Compute Engine (https://cloud.google.com/compute) settings (Y/n)? y
設定一下這個虛擬機器應該要在哪個區域的 data center 上:
Which Google Compute Engine zone would you like to use as project default? If you do not specify a zone via a command line flag while working with Compute Engine resources, the default is assumed. [1] asia-east1-c [2] asia-east1-a [3] asia-east1-b [4] asia-northeast1-a [5] asia-northeast1-c [6] asia-northeast1-b [7] asia-southeast1-a [8] asia-southeast1-b [9] australia-southeast1-b [10] australia-southeast1-c [11] australia-southeast1-a [12] europe-west1-b [13] europe-west1-c [14] europe-west1-d [15] europe-west2-a [16] europe-west2-b [17] europe-west2-c [18] europe-west3-b [19] europe-west3-c [20] europe-west3-a [21] southamerica-east1-c [22] southamerica-east1-a [23] southamerica-east1-b [24] us-central1-f [25] us-central1-c [26] us-central1-b [27] us-central1-a [28] us-east1-c [29] us-east1-b [30] us-east1-d [31] us-east4-a [32] us-east4-b [33] us-east4-c [34] us-west1-c [35] us-west1-b [36] us-west1-a [37] Do not set default zone Please enter numeric choice or text value (must exactly match list item): 2
這個新增的設定就已經完成了,而且 gcloud 的預設值會換成這個新的組態:
Your project default Compute Engine zone has been set to [asia-east1-a]. You can change it by running [gcloud config set compute/zone NAME]. Your project default Compute Engine region has been set to [asia-east1]. You can change it by running [gcloud config set compute/region NAME]. Your Google Cloud SDK is configured and ready to use! * Commands that require authentication will use family@gmail.com by default * Commands will reference project `blog-family` by default * Compute Engine commands will use region `asia-east1` by default * Compute Engine commands will use zone `asia-east1-a` by default Run `gcloud help config` to learn how to change individual settings This gcloud configuration is called [family]. You can create additional configurations if you work with multiple accounts and/or projects. Run `gcloud topic configurations` to learn more. Some things to try next: * Run `gcloud --help` to see the Cloud Platform services you can interact with. And run `gcloud help COMMAND` to get help on any gcloud command. * Run `gcloud topic -h` to learn about advanced features of the SDK like arg files and output formatting
重新用 gcloud config configuration list 看一下… 新增的 family 組態有出現:
testuser@localhost ~ $ gcloud config configurations list NAME IS_ACTIVE ACCOUNT PROJECT DEFAULT_ZONE DEFAULT_REGION default False myself@gmail.com ephrain-blog asia-east1-a asia-east1 family True family@gmail.com blog-family asia-east1-a asia-east1
注意 IS_ACTIVE 是 True,代表這個新增的組態是作用中的組態,
執行所有 gcloud 相關的指令,都是對這個新組態的 Google Cloud Platform 操作囉:
testuser@localhost ~ $ gcloud compute instances list NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS wordpress-multisite-1-vm asia-east1-a g1-small 10.140.0.3 104.199.255.229 RUNNING
(本頁面已被瀏覽過 2,876 次)