[GCE] Google Cloud SDKのセットアップ

Google Cloud SDKのセットアップ。といってもQuick Startの通りにやればいいので特に難しくはない。

google cloud sdkを拾ってきてインストールスクリプトを実行。
wget https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.zip
unzip google-cloud-sdk.zip
sh google-cloud-sdk/install.sh

↓こんな感じで出力されるんで、いくつか質問に答えていくと必要なものをダウンロードしてきてくれる。
Welcome to the Google Cloud SDK!

The Google Cloud SDK is currently in developer preview. To help improve the
quality of this product, we collect anonymized data on how the SDK is used.
You may choose to opt out of this collection now (by choosing 'N' at the below
prompt), or at any time in the future by running the following command:
    gcloud config --global-only set disable_usage_reporting true

Do you want to help improve the Google Cloud SDK (Y/n)?  


This will install all the core command line tools necessary for working with
the Google Cloud Platform.

If you are developing an App Engine application, please select the 
language your application is written in.  This will install the 
required tools and runtimes for working in that language.  If 
necessary, you can add and remove languages later through the gcloud 
component manager.
  [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):  


The following components will be installed:
    ----------------------------------------------------------------------
    | Cloud SDK Core Libraries (Platform Specific) | 2014.03.24 | < 1 MB |
    ----------------------------------------------------------------------

Creating update staging area...


Installing: Cloud SDK Core Libraries (Platform Specific) ... Done

Creating backup and activating new installation...

Done!

The Google Cloud SDK installer will now prompt you to update an rc 
file to bring
the Google Cloud CLIs into your environment.

Enter path to an rc file to update, or leave blank to use 
[/home/user/.bashrc]:             

Modify profile to update your $PATH? (Y/n)?  


Modify profile to enable bash completion? (Y/n)?  

Backing up [/home/user/.bashrc] to [/home/user/.bashrc.backup].
[/home/user/.bashrc] has been updated. Start a new shell for the changes to take effect.

For more information on how to get started, please visit:
  https://developers.google.com/cloud/sdk/gettingstarted


セットアップが完了すると ~/.bashrc に設定が追記される。
# The next line updates PATH for the Google Cloud SDK.
source /home/user/google-cloud-sdk/path.bash.inc

# The next line enables bash completion for gcloud.
source /home/user/google-cloud-sdk/completion.bash.inc


zshを使っている場合は、セットアップ途中の rc file の質問に /home/[username]/.zshrc と答えると zshrc に書き込んでくれる。

path.bash.inc の中身が何やってるのかよくわからないが、とりあえず export PATH=$PATH:(自分の環境)/google-cloud-sdk/bin などとして google-cloud-sdk/bin を $PATH に突っ込むとよさげ。

あとはzsh用のcompletion設定を読むように zshrc に追記された行を変更。(パスは自分の環境にあわせる)
source /home/user/google-cloud-sdk/completion.bash.inc

source /home/user/google-cloud-sdk/completion.zsh.inc


最後に以下のコマンドを実行するとブラウザが開いて認証される。
gcloud auth login


「承認する」をクリックしてターミナルに戻ると project ID を聞かれるので、入力して認証完了。


認証がちゃんとできているかはこれらのコマンドで確認可能。
gcloud auth list
gcloud config list
認証情報は ~/.config/gcloud/credentials に保存されている。


インスタンスを操作するには gcutil というものをインストールする必要があるみたいだがこの時点ではまだ使えない。


【まとめ】
Google Cloud PlatformのCompute Engine使ってみた

このブログの人気の投稿

zsh 設定 - プロンプト -

テンションを上げたいときにおすすめの曲(StarrySky YEAH! Remix)

OpenLDAP のログ周りの設定をする