Google Cloud Platformを初めて触る

google cloud platformの無料枠が増えたというニュースをみてちょっと触ってみることにしました(https://japan.zdnet.com/article/35097973/)。

アカウント登録からインスタンス作成まで

まずはサービスのページここの無料トライアルから作成
利用するための情報を登録していく。
開始までちょっと時間かかる。
管理コンソールが表示される。ちゃんと日本語化されてる
まずはサーバを。AWSで言うEC2
初めて作るときはここも時間がかかる。
画面が表示されたらサーバの設定をしていく。OSイメージの種類
こんなのもある。
設定していく。
設定が完了したら「作成」を押す
無事にインスタンスが立ち上がりました。

ざっと触ってみた感じ。AWSを触ったことがある人であればなんとなく使えそうって言う感じ。日本語ちゃんとなっているし。

gcloudコマンドのインストール

gcloudというコマンドが必要なようで、まずそちらをインストール。コマンドは下記の通りで。このコマンドを打つと何回か質問がされますので、全部答えていきます。私は最初なのでとりあえず全部デフォルトっぽいのでセットしました。

$ curl https://sdk.cloud.google.com | bash

次に認証のためのコマンドを実行します。

$ gcloud init

認証しますか?という問いにYで応えるとブラウザが立ち上がり認証を求められます。

Googleアカウントでログイン後に


と出てくるので許可をすると認証が終わります。


compute engine にログイン

ここまで準備が終わったのでcompute engineにログインしてみます。管理コンソールに戻ってcompute engineのインスタンスのところで赤枠部分を選択するとメニューがでてきて「gcloudコマンドを表示」とでます。



ここを選択するとコマンドが表示されます。


これを実行してみる。

$ gcloud compute --project "service-account-manager" ssh --zone "asia-northeast1-c" "instance-1"
WARNING: The public SSH key file for gcloud does not exist.
WARNING: The private SSH key file for gcloud does not exist.
WARNING: You do not have an SSH key for gcloud.
WARNING: [/usr/bin/ssh-keygen] will be executed to generate a key.
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/xxx/.ssh/google_compute_engine.
Your public key has been saved in /Users/xxx/.ssh/google_compute_engine.pub.
The key fingerprint is:
The key's randomart image is:

Updating project ssh metadata.../Updated [https://www.googleapis.com/compute/v1/projects/service-account-manager].
Updating project ssh metadata...done.
Warning: Permanently added 'compute.00000000000000' (ECDSA) to the list of known hosts.
[xxx@instance-1 ~]$

秘密鍵の指定を特にしていなかったせいか、鍵が自動で作られてログインされた様子。

ちなみに、事前に公開鍵を登録していれば

$ ssh -i <秘密鍵のパス> <user>@<ip or hostname>

でログイン可能です。

色々と確認

ログインできたので軽く確認してみる。

$ cat .ssh/authorized_keys

ここにはさっき追加された公開鍵とインスタンス作成時に追加した公開鍵が追加されていた

$ ls /home

ユーザーはインスタンス作成時に追加したユーザが2人。

$ cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)

CentOs 7を選択したのでこれが(2017/03/18時点)

$ sudo cat /etc/ssh/sshd_config ※抜粋
PermitRootLogin no
PasswordAuthentication no

sudoパスワードなしで行けてた。怖い。

$ yum list installed

これといってすごい面白いものはなかった。

$ systemctl list-units --type=service |cat
UNIT LOAD ACTIVE SUB DESCRIPTION
acpid.service loaded active running ACPI Event Daemon
auditd.service loaded active running Security Auditing Service
avahi-daemon.service loaded active running Avahi mDNS/DNS-SD Stack
crond.service loaded active running Command Scheduler
dbus.service loaded active running D-Bus System Message Bus
firewalld.service loaded active running firewalld - dynamic firewall daemon
getty@tty1.service loaded active running Getty on tty1
google-accounts-daemon.service loaded active running Google Compute Engine Accounts Daemon
google-clock-skew-daemon.service loaded active running Google Compute Engine Clock Skew Daemon
google-ip-forwarding-daemon.service loaded active running Google Compute Engine IP Forwarding Daemon
google-shutdown-scripts.service loaded active exited Google Compute Engine Shutdown Scripts
kmod-static-nodes.service loaded active exited Create list of required static device nodes for the current kernel
network.service loaded active exited LSB: Bring up/down networking
NetworkManager-wait-online.service loaded active exited Network Manager Wait Online
NetworkManager.service loaded active running Network Manager
ntpd.service loaded active running Network Time Service
polkit.service loaded active running Authorization Manager
postfix.service loaded active running Postfix Mail Transport Agent
rhel-dmesg.service loaded active exited Dump dmesg to /var/log/dmesg
rhel-readonly.service loaded active exited Configure read-only root support
rsyslog.service loaded active running System Logging Service
serial-getty@ttyS0.service loaded active running Serial Getty on ttyS0
sshd-keygen.service loaded active exited OpenSSH Server Key Generation
sshd.service loaded active running OpenSSH server daemon
systemd-fsck-root.service loaded active exited File System Check on Root Device
systemd-hwdb-update.service loaded active exited Rebuild Hardware Database
systemd-journal-catalog-update.service loaded active exited Rebuild Journal Catalog
systemd-journal-flush.service loaded active exited Flush Journal to Persistent Storage
systemd-journald.service loaded active running Journal Service
systemd-logind.service loaded active running Login Service
systemd-random-seed.service loaded active exited Load/Save Random Seed
systemd-remount-fs.service loaded active exited Remount Root and Kernel File Systems
systemd-sysctl.service loaded active exited Apply Kernel Variables
systemd-tmpfiles-setup-dev.service loaded active exited Create Static Device Nodes in /dev
systemd-tmpfiles-setup.service loaded active exited Create Volatile Files and Directories
systemd-udev-trigger.service loaded active exited udev Coldplug all Devices
systemd-udevd.service loaded active running udev Kernel Device Manager
systemd-update-done.service loaded active exited Update is Completed
systemd-update-utmp.service loaded active exited Update UTMP about System Boot/Shutdown
systemd-user-sessions.service loaded active exited Permit User Sessions
systemd-vconsole-setup.service loaded active exited Setup Virtual Console
tuned.service loaded active running Dynamic System Tuning Daemon
yum-cron.service loaded active exited Run automatic yum updates as a cron job
LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.
43 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.

こんな感じかな。

次回はここにItamaeでサーバ構成を流していこうと思います。