Google Compute Engine を使ってみる(1) プロジェクト作成から Google Cloud SDK インストールまで #gcloud #gce

Google Compute Engine を使ってみました。
準備編として、プロジェクト作成から Google Cloud SDK のインストールまでの作業メモです。

Google Cloud Platform へログイン

Google Cloud Platform へアクセスし、ログインします。
既存の Google アカウントでも新規でアカウント作成してもどちらでもいいです。

プロジェクトの作成

1. Google アカウントでログイン後、Google Developers Console へアクセスします
2. [CREATE PROJECT] をクリックし、プロジェクトを作成します

  • 自動付与されている Project ID は世界に一つのユニークな ID になっています

3. 作成したプロジェクトを選択し、[Compute Engine] をクリックします
4. Compute Engine を使うには支払い情報の登録が必要です的な画面が表示されるので、[Enable Billing] をクリックしてクレジットカード情報を登録します
5. クレジットカード情報の登録が終わると、Compute Engine が使えるようになります

Google Cloud SDK のインストール

System Requirements: Google Cloud SDK runs on Windows, Mac OS X and Linux, and requires Python 2.7.x. Some of the individual tools bundled with Cloud SDK have more stringent requirements: using App Engine tools for Java development requires Java 1.7+, and using SSH functionality from gcutil tool on Windows requires a 32-bit Cygwin installation.

ということで、Python 2.7 系が必要です。
App Engine は使用しないので、Jave は不要です。
1. Python 2.7.x のインストール
システムにインストールされているものでも、新規にインストールしてもどちらでもかまいません。
pyenv で Python をインストールする場合は、以下のエントリを参照してください。

2. Cloud SDK のインストール

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

インストール先とか聞かれるので、環境にあわせて設定します。

Directory to extract under (this will create a directory google-cloud-sdk) (/Users/hogehoge):   <- Cloud SDK のインストール先

Do you want to help improve the Google Cloud SDK (Y/n)?       <- Cloud SDK の改善に協力するか

This will install all the core command line tools necessary for working with
the Google Cloud Platform.
.....
  [1]  Java
  [2]  Python and PHP
  [3]  Go
  [4]  No App Engine (you can install App Engine tools later)
Please enter your numeric choice (4):     <- インストールする SDK の選択、GCE のみ使用の場合は [4] を選択

Enter path to an rc file to update, or leave blank to use
[/Users/hogehoge/.bash_profile]:      <- 環境変更のためのシェル設定ファイル

Modify profile to update your $PATH? (Y/n)?       <- 環境変数 PATH を変更するか

Modify profile to enable bash completion? (Y/n)?     <- 補完を有効にするか

3. 動作確認
gcloud コマンドを実行して、エラーがないことを確認します。

$ source ~/.bash_profile
$ gcloud --version
$ gcloud components list

Google Cloud SDK の認証と初期設定

1. gcloud コマンドを実行し、Cloud SDK を認証します
2. 自動でブラウザが起動するので、Cloud SDK のリクエストを承認します

$ gcloud auth login
.....
You are logged in as hogehoge@gmail.com

3. プロジェクト ID*1 を設定します

$ gcloud config set project xxxxx-xxxxxxx-xxx

*1:プロジェクト作成時に自動付与された ID