2014年2月5日 星期三

初探 Google Cloud Platform - 2. How to login and manage instance




接續上一篇初探 Google Cloud Platform - 1. Create instance,關於如何用SSH登入VM我一直有疑惑,後來查了一下才知道,原來Google Cloud Platform 有提供兩種登入方式:

本篇文章主要還是在介紹使用gcutil的方式login,因為如果要搭配使用Google Cloud SDK 以及大量deploy Hadoop Cluster 還是必須學會使用這種認證方式。




Install Goolge Cloud SDK

1. 下載SDK 自動安裝檔

$ curl https://dl.google.com/dl/cloudsdk/release/install_google_cloud_sdk.bash | bash 

2. 指定安裝路徑和PATH變數 (自動安裝檔預設使用bash像我是用zsh就必須另外設定)

3. Authentication,執行以下指令

$ gcloud auth login 

Your browser has been opened to visit: 

    https://accounts.google.com/o/oauth2/auth?scope=https%3A%2%2Fwww.googleapis.com%2Fauth%2Fa...... 

(sdk 會自動彈跳出瀏覽器,顯示以下資訊要求你的授權 )


接下來回到console 會繼續要你輸入你的專案ID

You can view your existing projects and create new ones in the Google
Developers Console at: https://cloud.google.com/console. If you have a
project ready, you can enter it now.

Enter your Google Cloud project ID (or leave blank to not set): test-hadoop-cluster 

You are logged in as xxxxx@gmail.com.


接下來我們就可以利用gutil ssh 的指令來登入VM

$ gcutil --project=test-hadoop-cluster ssh test-vm
NFO: Zone for vm-test detected as us-central1-a.
WARNING: You don't have an ssh key for Google Compute Engine. Creating one now...
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
INFO: Updated project with new ssh key. It can take several minutes for the instance to pick up the key.
INFO: Waiting 120 seconds before attempting to connect.
NFO: Running command line: ssh -o UserKnownHostsFile=/dev/null -o CheckHostIP=no -o StrictHostKeyChecking=no -i /Users/xxxxx/.ssh/google_compute_engine -A -p 22 xxxxx@173.255.112.xxx --
Warning: Permanently added '173.255.112.xxx' (RSA) to the list of known hosts.
X11 forwarding request failed on channel 0


Update:
使用 gcutil 的方式登入,也可以改成用以下指令:

ssh -o UserKnownHostsFile=/dev/null -o CheckHostIP=no -o StrictHostKeyChecking=no -i $HOME/.ssh/google_compute_engine -A -p 22 $USER@TYPE-GOOGLE-COMPUTE-ENGINE-PUBLIC-IP-HERE

沒有留言 :