Webエンジニア susumuis の技術ブログ

このブログの内容は個人の見解であり、所属する組織の公式見解ではありません

Google Cloud Platform に Google Compute Engine を構築して、Wordpressを動かすまで(その1 - instance に SSHで接続するまで)

先日、GCEを使って遊んでみました。 基本的なことですが、自分用のログとして残します。

なお、事前にGoogle Cloud Platformの登録は済んでいてプロジェクト作成済みで、インスタンスも作成済み、さらにgcutilもインストール済みとします。(そこまでの記録は別エントリを書くかもしれませんが、今回は扱いません)*1

gcutil経由でSSH接続をする

まずは gcutil が使えることを確認します。

ishigami-air:Commands susumuis$ gcutil
You do not currently have an active account selected.
Please run:

  $ gcloud auth login

to obtain new credentials, or if you have already logged in with a
different account:

  $ gcloud config set account <account name>

to select an already authenticated account to use.

バージョンも見てみましょう。

ishigami-air:Commands susumuis$ gcloud --version
Google Cloud SDK 0.9.21

bq 2.0.18
bq-nix 2.0.18
core 2014.04.08
core-nix 2014.04.08
gcutil 1.15.0
gcutil-nix 1.13.0
gsutil 3.42
gsutil-nix 3.42
sql 2014.04.15


There are available updates for some Cloud SDK components.  To
install them, please run:
 $ gcloud components update

updateできるというので、早速やってみよう。

ishigami-air:Commands susumuis$ gcloud components update

The following components will be updated:
    ------------------------------------------------------------------------------
    | BigQuery Command Line Tool                           |     2.0.18 | < 1 MB |
    | BigQuery Command Line Tool (Platform Specific)       |     2.0.18 | < 1 MB |
    | Cloud SDK Core Libraries                             | 2014.04.24 | < 1 MB |
    | Cloud SDK Core Libraries (Platform Specific)         | 2014.04.24 | < 1 MB |
    | Cloud SQL Admin Command Line Interface               | 2014.04.24 | < 1 MB |
    | Cloud Storage Command Line Tool (Platform Specific)  |       3.42 | < 1 MB |
    | Compute Engine Command Line Tool (Platform Specific) |     1.15.0 | < 1 MB |
    ------------------------------------------------------------------------------
The following components will be installed:
    ----------------------------------------------------------------
    | Cloud DNS Admin Command Line Interface | 2014.04.24 | < 1 MB |
    ----------------------------------------------------------------

Do you want to continue (Y/n)?  Y

Creating update staging area...

Uninstalling: BigQuery Command Line Tool ... Done
Uninstalling: BigQuery Command Line Tool (Platform Specific) ... Done
Uninstalling: Cloud SDK Core Libraries ... Done
Uninstalling: Cloud SDK Core Libraries (Platform Specific) ... Done
Uninstalling: Cloud SQL Admin Command Line Interface ... Done
Uninstalling: Cloud Storage Command Line Tool (Platform Specific) ... Done
Uninstalling: Compute Engine Command Line Tool (Platform Specific) ... Done

Installing: BigQuery Command Line Tool ... Done
Installing: BigQuery Command Line Tool (Platform Specific) ... Done
Installing: Cloud DNS Admin Command Line Interface ... Done
Installing: Cloud SDK Core Libraries ... Done
Installing: Cloud SDK Core Libraries (Platform Specific) ... Done
Installing: Cloud SQL Admin Command Line Interface ... Done
Installing: Cloud Storage Command Line Tool (Platform Specific) ... Done
Installing: Compute Engine Command Line Tool (Platform Specific) ... Done

Creating backup and activating new installation...

Done!

それでは、早速作ったアプリにログインします。

ishigami-air:Commands susumuis$ gcloud auth login
Your browser has been opened to visit:

    https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fbigquery+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdevstorage.full_control+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fndev.cloudman+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fsqlservice.admin+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fprediction+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fprojecthosting&redirect_uri=http%3A%2F%2Flocalhost%3A8085%2F&response_type=code&client_id=***********.apps.googleusercontent.com&access_type=offline



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

ここで表示されたURLをクリックするように書いてありますが、僕の環境では、そもそもブラウザが勝手に立ち上がって、認証画面が表示されました。

f:id:s-ishigami:20140504203245p:plain

承認すると

You are now authenticated with the Google Cloud SDK.

The authentication flow has completed. You may close this window, or check out the Getting Started Guide for more information.

と表示されます。よく見ると、URLがlocalhostですね。gcutilがWebサーバーを立てているようです。

一方端末側では

Enter your Google Cloud project ID (or leave blank to not set):

と聞かれています。blankでも良いというのですが、僕はとりあえずプロジェクト名である。

API Project

と入れてみます。(これで後でハマります) すると、

You are logged in as ************@gmail.com.

There are available updates for some Cloud SDK components.  To
install them, please run:
 $ gcloud components update

これでログイン状態になったようです。それでは、早速コマンドを実行してみましょう。

ishigami-air:Commands susumuis$ gcutil listregions
CommandError: Characters in project name must be lowercase: API Project.

おかしいですね。プロジェクト名は全部lowercaseにしろとか。それで色々調べた結果、"gcloud config set project "でproject IDを変更できるようです。

ishigami-air:~ susumuis$ gcloud config set project 26*********
ishigami-air:~ susumuis$ gcutil listregions
+--------------+--------+----------+----------------+------------------+
| name         | status | cpus     | disks-total-gb | static-addresses |
+--------------+--------+----------+----------------+------------------+
| asia-east1   | UP     | 1.0/24.0 | 10.0/5120.0    | 0.0/7.0          |
+--------------+--------+----------+----------------+------------------+
| europe-west1 | UP     | 0.0/24.0 | 0.0/5120.0     | 0.0/7.0          |
+--------------+--------+----------+----------------+------------------+
| us-central1  | UP     | 0.0/24.0 | 0.0/5120.0     | 0.0/7.0          |
+--------------+--------+----------+----------------+------------------+

やれやれ、やっとできました。早速instance-1にSSHで繋いでみましょう。

ishigami-air:~ susumuis$ gcutil ssh instance-1
INFO: Zone for instance-1 detected as asia-east1-b.
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:

初めての接続なので、SSHの鍵を作るからパスフレーズを入れてくれと言われます。鍵を持ってるクライアントでしかアクセス出来ないようです。 初期状態で鍵認証なのでセキュリティ的には安心ですね! Macだとここで、key chainのダイアログが出てきてパスワードを聞かれます。

Linux instance-1 3.13-0.bpo.1-amd64 #1 SMP Debian 3.13.7-1~bpo70+1 (2014-03-29) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

Debianにログインしていることがわかります。

一度鍵をつくれば、後は普通にssh接続することも可能です。

ssh ユーザー名@IPアドレス

上記同様のメッセージが表示され、Debianに接続されています。

それでは、色々試してみましょう。

susumuis@instance-1:~$ pwd
/home/susumuis
susumuis@instance-1:~$ whoami
susumuis
susumuis@instance-1:~$ df -h
Filesystem                                              Size  Used Avail Use% Mounted on
rootfs                                                  9.8G  652M  8.6G   7% /
udev                                                     10M     0   10M   0% /dev
tmpfs                                                    60M   80K   60M   1% /run
/dev/disk/by-uuid/3816747c-4543-4118-9797-d429d1554032  9.8G  652M  8.6G   7% /
tmpfs                                                   5.0M     0  5.0M   0% /run/lock
tmpfs                                                   119M     0  119M   0% /run/shm

ルート10GBしかないですね。追加の容量はGoogle Cloud Strageを購入してマウントすると良いでしょう。 引き続き、ここにLAMP環境を構築して、Wordpressを動かした手順を紹介したいと思います。 もっとも、ここから先は、どの環境でやってもDebianなら同じになりますから、サーバーに慣れた方は、不要な情報になるでしょう。

続きはこちら:  Google Cloud Platform に Google Compute Engine を構築して、Wordpressを動かすまで(その2 - LAMP環境の構築) - susumuis Info

*1:なぜかって言うと、自分で取った手順ログがそこからだから