DRYな備忘録

Don't Repeat Yourself.

Azureことはじめ

アカウント登録

が終わった図↓

f:id:otiai10:20171217105454p:plain

Computeリソースの作成

f:id:otiai10:20171217134811p:plain

必要な前提作業があった

  • AWSなどと違い、インスタンスsshするためのIdentityファイルを自分で作成する必要がある
    • ssh-keygen -f ~/.ssh/azure/id_rsa みたいにしてつくった
  • Azureでは、Accountに紐付いたクレジットカードと、さらにそれに紐付いたSubscriptionというモデルをつくる必要がある(画像赤枠部分に警告が出ている場合)

f:id:otiai10:20171217135223p:plain

次に、インスタンスタイプを選ぶ。ここでスペックを選べる。ここで提示されてるestimated price、完全に購買障壁になってる気がするんだけど。

f:id:otiai10:20171217133326p:plain

Public IPなんかはここでNoneに指定できるようだ。今回はローカルから直でsshしたいので、とりあえずpublic ipつけとく。

f:id:otiai10:20171217135517p:plain

インスタンス立った

2,3分ぐるぐるがあったのち、インスタンスが立つ。

f:id:otiai10:20171217140538p:plain

Public IP Addressをモザイクかけるか迷ったけど、まあどうせすぐ殺すしええやろ。

sshを試みる

% ssh -i ~/.ssh/azure/id_rsa 13.78.120.58
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.11.0-1016-azure x86_64)

otiai10@testtest:~$ uname -a
Linux testtest 4.11.0-1016-azure #16-Ubuntu SMP Tue Dec 5 22:52:08 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
otiai10@testtest:~$

いいですね!

Webサーバでも立ててみるか

せっかくPublic IP Addressがあるので、ウェブサーバでも立ててみるか、というはこびになった。まぁGoでいっか。

otiai10@testtest:~$ sudo apt-get update -qq
otiai10@testtest:~$ sudo apt-get install -qq -y golang vim
otiai10@testtest:~$ vi server.go
package main

import (
    "fmt"
    "net/http"
)

func main() {
    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        fmt.Println("Request has come!")
        fmt.Fprintf(w, "Hello! This is a server running on Azure!!")
    })
    fmt.Println("The server is up on port 9980")
    http.ListenAndServe(":9980", nil)
}
otiai10@testtest:~$ go run server.go
The server is up on port 9980

してから、ローカルのターミナル(あるいはふつうにウェブブラウザで)

% curl http://13.78.120.58:9980/
curl: (7) Failed to connect to 13.78.120.58 port 9980: Operation timed out

oh... 到達していないような気がする。22番ポートは開いてるってことだから、9980(自分でserver.goで勝手に決めたポート)を開ける必要があるな。

SecurityGroupというものがある

f:id:otiai10:20171217142851p:plain

9980開けた。

うごいた

再度、ローカルから

% curl http://13.78.120.58:9980/
Hello! This is a server running on Azure!!%                                                                                                                                       %

同様に、ブラウザ

f:id:otiai10:20171217143310p:plain

あとかたづけ

まず単純にインスタンスを削除(delete)してみる。

f:id:otiai10:20171217143627p:plain

で、削除されたら、All resources見てみるじゃないですか?

f:id:otiai10:20171217144927p:plain

_人人人人人人人人人人_ > けっこうのこってる <  ̄YYYYYYYYYY^ ̄

  • Storage account: ストレージの管理用アカウントなんだろうな
  • Virtual network: AWSにおけるVPCみたいなものだろうな
  • Network interface: その名の通りだろうな
  • Public IP address: その名の通り。インスタンス消したら消えてもいいんだけどな
  • Network security group: はい

インスタンスを殺しても残るもの」的な意味ではわりと納得できるリソース群ですね。殺そ。

全部消して、終了。とりあえず最初なのでこんなものかというかんじ。

f:id:otiai10:20171217145604p:plain

雑感

  • 5000兆円ほしい

DRYな備忘録として