GCE = Google Compute Engine (IaaS雲服務)
GAE = Google App Engine (PaaS雲服務)
VM = Virtual Machine = AWS的EC2(Elastic Compute Cloud)
常看小弟文章的朋友應該很清楚小弟這幾年在網站上分享了不少雲服務的心得,而認識小弟多年的好友們更是很明白小弟分享得越多、顧問的收入就越少的一個現實,好友們也都會問:「既然這樣,為何你還要一直免費分享出去?」
小弟的想法是:「我一個人懂得善用雲服務,只對我有短暫的優勢而已;但若是讓更多台灣的企業能夠懂得善用雲服務的話,那對台灣的未來才會有更大的幫助…」。
所以就算自己還是很辛苦在想辦法賺錢,但仍然很願意把大多數的經驗分享出來,只留下一小部份做為自己現今生存所需的專業(這樣台灣的企業才會願意付費,因為網站上看不到)。
我還是很天真,對吧?!
由於我個人比較喜歡用IaaS的雲服務,PaaS是幾乎不碰的,所以今天要來分享的是在GCE上實際啟用VM的一些心得,希望能讓有興趣玩GCE的朋友們減少摸索的時間~
使用GCE的VM之前,當然一定要先看清楚服務的價格:

然後再來比較AWS的EC2價格:

很明顯地可以發現GCE有特別針對AWS的價格做了用心的應對,規格相接近的VM價格幾乎都是AWS EC2的86折(也就是86%),例如GCE的n1-standard-1h等同AWS的m1.medium;不過若是再與AWS的Reserved Instance價格相比的話,年度成本還是高於AWS的!
此外,要注意的還有GCE目前僅有US及Europe兩個Region、每個Region各有兩個Zone可以選用,不像AWS全球有8個Region(已扣除給美國政府專用的Region)、每個Region各有2-5個Zone可以選用。
接下來,我們就來實際啟用一個GCE的VM吧!
1.登入到GCE的Console中,點選至Projects選單後,再直接點選(或建一個新的)某個project name,以進入至該專案(要用滑鼠點專案名稱才有用哦)

2.進入該專案之後,會出現該專案的Overview(類似AWS的Dashboard)

3.點選Compute Engine後,進入到其管理畫面

4.點下「NEW INSTANCE」的按鈕後,便能開始進行VM的啟用了

5-1.選擇VM啟用的所在區域(Zone)

5-2.選擇VM的等級(Machine Type)

5-3.選擇VM的Boot Source

5-4.選擇VM要使用的Image (作業系統,目前僅有centos和debian可選)

5-5.關於VM的其它選項(可用預設值即可)

6.做好VM基本的選擇後,可別急著啟用(Create),接下來要教大家用自己產生的ssh key來做VM的管理,不然日後就得用GCE的gcutil來產生key才能用ssh連線管理哦~

6-1.這次我們用windows的作業系統來示範Client端如何連線至GCE的VM,首先去下載puttygen的工具,並開啟它

6-2.按下「Generate」的按鈕後,再用滑鼠在Key的空白區到處移動

6-3.之後便會產生一對Key,Public Key的內容會直接在畫面上

6-4.先把Private Key存下來Client端的電腦裡

6-5.然後把Public key的內容複製到GCE Console中的Metadata欄位,請注意在Metadata中的key一定要是sshKeys(而且只能一組,不能重覆),然後在value的欄位中輸入username:<public-key string>,例如此例是kenlee:ssh-rsa AAAA….

※關於Metadata的更多詳細說明請看google提供的文件~
7.按下「Create」後,等待VM啟用後,便能準備進行連線管理了

8-1.在Windows中使用PuTTY來連線管理GCE的VM,打開PuTTY後,輸入IP位置

8-2.然後切至Connection->SSH->Auth的畫面

8-3.載入之前用puttygen產生的private key (預設是.ppk檔)

8-4.點回Session的畫面,可以把設定存下來,下次就不必再重打

8-5.在PuTTY中按下Open的鈕之後,第一次連線會出現Security Alert,按是即可

8-6.輸入kenlee的username (步驟6-5設定的)之後便能連線準備進行VM的管理囉~
