🐧
Multipass + Nginx 環境構築メモ
はじめに
MacOS上で完全なLinux環境の作成・管理が容易にできるツールを探していて、
Multipassが使いやすそうだったので、実際に触ってみました。
Multipassを詳しく知りたい方は、以下の公式資料を参照してみてください。
実行環境
- MacOS Sequoia 15.3.2
- Multipass 1.15.0+mac
- Homebrew 4.4.27
構築の流れ
- Install Multipass.
% brew install --cask multipass
- Check the installation is complete.
% multipass version
multipass 1.15.0+mac
multipassd 1.15.0+mac
- Creating SSH public and private keys.
% ssh-keygen
- 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>
- 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
- 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>
- 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:~$
- 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コンテンツを表示することができました。
- 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しか選択できないため、柔軟な使い分けが必要。
- まだまだ使っていない機能があるため、もう少し触ってみたい。
参考
Discussion