🐧

Multipass + Nginx 環境構築メモ

に公開

はじめに

MacOS上で完全なLinux環境の作成・管理が容易にできるツールを探していて、
Multipassが使いやすそうだったので、実際に触ってみました。
Multipassを詳しく知りたい方は、以下の公式資料を参照してみてください。
https://canonical.com/multipass/docs/tutorial

実行環境

  • MacOS Sequoia 15.3.2
  • Multipass 1.15.0+mac
  • Homebrew 4.4.27

構築の流れ

  1. Install Multipass.
% brew install --cask multipass
  1. Check the installation is complete.
% multipass version
multipass   1.15.0+mac
multipassd  1.15.0+mac
  1. Creating SSH public and private keys.
% ssh-keygen
  1. Create the cloud-init file.
cloud-init.yml
#cloud-config
repo_update: true
repo_upgrade: all

packages:
  - nginx

runcmd:
  - systemctl start nginx.service
  - systemctl enable nginx.service

ssh_authorized_keys:
  - <ssh public key>
  1. Creating the Virtual Machine.
% multipass launch --name vm-nginx --cloud-init cloud-init.yml
% multipass ls
Name                    State             IPv4             Image
vm-nginx                Running           <ip address>     Ubuntu 24.04 LTS
  1. Addition the .ssh/config file in the Host OS.
~/.ssh/config
Host vm-nginx
 HostName <ip address>
 User ubuntu
 Port 22
 IdentityFile <ssh secret key>
  1. Make an SSH Connection to the virtual machine.
% ssh vm-nginx
Welcome to Ubuntu 24.04.2 LTS (GNU/Linux 6.8.0-57-generic aarch64)
ubuntu@vm-nginx:~$ 
  1. Check the initial page of Nginx.
% ssh -L 8080:localhost:80 ubuntu@<ip address>
Welcome to Ubuntu 24.04.2 LTS (GNU/Linux 6.8.0-57-generic aarch64)
ubuntu@vm-nginx:~$

SSHコネクションを確立した状態で、ブラウザからアクセスすると、
NginxのHTMLコンテンツを表示することができました。

  1. Cleanup the virtual machine.
% multipass ls
Name                    State             IPv4             Image
vm-nginx                Running           <ip address>     Ubuntu 24.04 LTS

% multipass delete vm-nginx
% multipass purge

% multipass ls
Name                    State             IPv4             Image

感想

  • 短時間で作成できて、すぐにLinux環境を触れる点がとても嬉しい。
  • 簡単なコマンド確認やツールの動作確認をしたいときに楽。
  • 一方でディストリビューションはUbuntuしか選択できないため、柔軟な使い分けが必要。
  • まだまだ使っていない機能があるため、もう少し触ってみたい。

参考

https://dev.classmethod.jp/articles/intro-to-multipass/

Discussion