LoginSignup
0
0

More than 1 year has passed since last update.

AzureでグローバルIPを持った仮想マシンを作る

Posted at

今後Azureを主に利用していくことになるのでまず動かしてみたい。すでにアカウントを作り、無料期間が終わり、でMFAの認証を設定している状態です。

azのCLIの表示を整形する部分で以下の記事を参考にさせていただきました
https://qiita.com/dz_/items/dda1a8f6198667406aeb
VisualStudioCodeでSSH接続する部分は以下の記事を参考にさせていただきました
https://qiita.com/nlog2n2/items/1d1358f6913249f3e186

Azureの画面から仮想マシンを作成する

バーチャルマシンを作る
image.png

設定入力

image.png

バーチャルマシンの確認

画面上
image.png

az

$ az login
[
  {
    "cloudName": "AzureCloud",
    "name": "step",
    "state": "Enabled",
    "user": {
      "name": "kai.kusakari@gmail.com",
      "type": "user"
    }
  }
]

$ az vm list-ip-addresses --query "[].virtualMachine[].{Name:name, PublicIp:network.publicIpAddresses[0].ipAddress, PrivateIp:network.privateIpAddresses[0]}" -o table -g test
Name    PublicIp        PrivateIp
------  --------------  -----------
testvm  XXX.XXX.XXX.XXX  10.1.0.4

 以下の記事を参考にさせていただきました
Check! Azure CLI 2.0 のフィルタクエリ (--query) サンプル集
https://qiita.com/dz_/items/dda1a8f6198667406aeb

SSHで接続する

せっかくなのでVisualStudioCodeでSSHする
image.png

Ubuntsuのバージョンを確認する

root@testvm:~# cat /etc/issue
Ubuntu 20.04.5 LTS \n \l

root@testvm:~# cat /etc/os-release 
NAME="Ubuntu"
VERSION="20.04.5 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.5 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
root@testvm:~# 
root@testvm:~# uname -a
Linux testvm 5.15.0-1020-azure #25~20.04.1-Ubuntu SMP Thu Sep 1 19:20:56 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
root@testvm:~# 

インターネット経由で静的なテキストを表示する

Nginxを導入する
https://www.nginx.com/resources/wiki/start/topics/tutorials/install/

# インストール
$ sudo apt update
$ sudo apt install nginx

# 確認
$ nginx -v
nginx version: nginx/1.18.0 (Ubuntu)
$ systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-10-09 04:15:53 UTC; 14min ago
       Docs: man:nginx(8)
   Main PID: 4170 (nginx)
      Tasks: 2 (limit: 472)
     Memory: 2.4M
     CGroup: /system.slice/nginx.service
             ├─4170 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             └─4171 nginx: worker process

Oct 09 04:15:53 testvm systemd[1]: Starting A high performance web server and a reverse proxy server...
Oct 09 04:15:53 testvm systemd[1]: Started A high performance web server and a reverse proxy server.
azureuser@testvm:~$ 

ブラウザ経由でアクセスするも接続できない。制御が入っていると思われる。

image.png

受信ポートに80を許可していなかったので追加する。
image.png

接続できました
image.png

今後もAzureを使っていくため、まず基本中の基本としてVMを作成してCLIやVisualStudioCodeを使ってみました。横断的に勉強するには書籍や学習動画が手取り早いので、評価が高いものを選んで使っていきます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0