Skip to Content
문서서버가상화

가상화 및 컨테이너

Ubuntu 26.04은 완전한 가상화 및 컨테이너 기술 스택을 제공합니다. 이 기사에서는 KVM/QEMU 하드웨어 가상화, libvirt 관리 도구, LXD 시스템 컨테이너 및 MicroCloud 클러스터 솔루션을 다룹니다.

KVM / QEMU

KVM(커널 기반 가상 머신)은 Linux 커널에 내장된 가상화 모듈입니다. QEMU와 결합되어 완전한 하드웨어 가상화 기능을 제공합니다.

하드웨어 지원 확인

# Check CPU virtualization support grep -Ec '(vmx|svm)' /proc/cpuinfo # Output greater than 0 means supported # Or use the kvm-ok tool sudo apt install cpu-checker -y kvm-ok

KVM 설치

sudo apt update sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virtinst virt-manager -y # Add current user to the libvirt group sudo usermod -aG libvirt $USER sudo usermod -aG kvm $USER newgrp libvirt # Verify service is running sudo systemctl status libvirtd # Verify installation virsh list --all

virt-install을 사용하여 VM 만들기

# Download ISO wget https://releases.ubuntu.com/26.04/ubuntu-26.04-live-server-amd64.iso -O /var/lib/libvirt/images/ubuntu-26.04.iso # Create a virtual machine # Note: --os-variant should match the ISO. If your local osinfo-db does not # list it yet, confirm with osinfo-query os | grep ubuntu. If it is not listed, # you can temporarily fall back to ubuntu24.04, or use # --os-variant detect=on,name=ubuntu26.04 virt-install \ --name ubuntu-vm \ --ram 2048 \ --vcpus 2 \ --disk path=/var/lib/libvirt/images/ubuntu-vm.qcow2,size=20,format=qcow2 \ --cdrom /var/lib/libvirt/images/ubuntu-26.04.iso \ --os-variant ubuntu26.04 \ --network bridge=virbr0 \ --graphics vnc,listen=0.0.0.0,port=5901 \ --console pty,target_type=serial \ --noautoconsole # Use a cloud image for quick creation (no installation process needed) wget https://cloud-images.ubuntu.com/releases/26.04/release/ubuntu-26.04-server-cloudimg-amd64.img # Create a disk copy and resize cp ubuntu-26.04-server-cloudimg-amd64.img /var/lib/libvirt/images/vm-disk.qcow2 qemu-img resize /var/lib/libvirt/images/vm-disk.qcow2 20G # Use with cloud-init # If osinfo-db does not list ubuntu26.04, you can temporarily fall back to ubuntu24.04 virt-install \ --name cloud-vm \ --ram 2048 \ --vcpus 2 \ --disk /var/lib/libvirt/images/vm-disk.qcow2 \ --import \ --os-variant ubuntu26.04 \ --network bridge=virbr0 \ --cloud-init user-data=cloud-config.yaml \ --noautoconsole

일반적인 virsh 명령

# VM management virsh list --all # List all VMs virsh start ubuntu-vm # Start virsh shutdown ubuntu-vm # Graceful shutdown virsh destroy ubuntu-vm # Force shutdown virsh reboot ubuntu-vm # Reboot virsh suspend ubuntu-vm # Suspend virsh resume ubuntu-vm # Resume virsh undefine ubuntu-vm --remove-all-storage # Delete VM and its disks virsh autostart ubuntu-vm # Enable autostart at boot # Resource adjustment virsh setvcpus ubuntu-vm 4 --config # Change CPU count (requires shutdown) virsh setmaxmem ubuntu-vm 4G --config # Change max memory virsh setmem ubuntu-vm 4G --config # Change current memory # Snapshot management virsh snapshot-create-as ubuntu-vm snap1 "Post-install snapshot" virsh snapshot-list ubuntu-vm virsh snapshot-revert ubuntu-vm snap1 virsh snapshot-delete ubuntu-vm snap1 # Console access virsh console ubuntu-vm # Serial console virsh vncdisplay ubuntu-vm # Show VNC port # Disk management qemu-img info /var/lib/libvirt/images/ubuntu-vm.qcow2 qemu-img resize /var/lib/libvirt/images/ubuntu-vm.qcow2 +10G

네트워크 브리지 구성

# Create a bridge (Netplan configuration) sudo tee /etc/netplan/01-bridge.yaml << 'EOF' network: version: 2 renderer: networkd ethernets: ens33: dhcp4: false bridges: br0: interfaces: - ens33 dhcp4: true parameters: stp: false forward-delay: 0 EOF sudo netplan apply # Use the bridge network in libvirt virsh net-define bridge-net.xml virsh net-start bridge-net virsh net-autostart bridge-net

libvirt 관리

XML을 사용하여 VM 정의

<!-- /etc/libvirt/qemu/example-vm.xml --> <domain type='kvm'> <name>example-vm</name> <memory unit='GiB'>4</memory> <vcpu placement='static'>2</vcpu> <os> <type arch='x86_64' machine='q35'>hvm</type> <boot dev='hd'/> </os> <features> <acpi/> <apic/> </features> <cpu mode='host-passthrough'/> <devices> <disk type='file' device='disk'> <driver name='qemu' type='qcow2'/> <source file='/var/lib/libvirt/images/example-vm.qcow2'/> <target dev='vda' bus='virtio'/> </disk> <interface type='bridge'> <source bridge='br0'/> <model type='virtio'/> </interface> <console type='pty'> <target type='serial' port='0'/> </console> <graphics type='vnc' port='-1' autoport='yes'/> </devices> </domain>
# Create a VM from XML virsh define example-vm.xml virsh start example-vm

스토리지 풀 관리

# List storage pools virsh pool-list --all # Create a directory storage pool virsh pool-define-as mypool dir --target /data/libvirt/images virsh pool-build mypool virsh pool-start mypool virsh pool-autostart mypool # Create a volume virsh vol-create-as mypool vm-disk.qcow2 20G --format qcow2 # List volumes virsh vol-list mypool

LXD 시스템 컨테이너

LXD은 전체 Linux 시스템 환경, 빠른 시작 시간 및 낮은 리소스 오버헤드를 갖춘 경량 시스템 컨테이너를 제공합니다.

LXD 설치

# Install via Snap sudo snap install lxd # Initialize LXD sudo lxd init # Interactive configuration: # - Clustering: no (standalone) # - Storage pool: dir or zfs # - Network: create a new bridge network # - Auto-update images: yes # Minimal initialization sudo lxd init --minimal # Add user to the lxd group sudo usermod -aG lxd $USER newgrp lxd

LXD 컨테이너 관리

# View available images lxc image list ubuntu: # Ubuntu official images lxc image list images: # Community images # Launch a container lxc launch ubuntu:26.04 my-container lxc launch ubuntu:26.04 web-server # Launch a virtual machine (LXD also supports VMs) lxc launch ubuntu:26.04 my-vm --vm # Container operations lxc list # List all lxc start my-container # Start lxc stop my-container # Stop lxc restart my-container # Restart lxc delete my-container --force # Delete lxc info my-container # Detailed info # Enter a container lxc exec my-container -- bash lxc exec my-container -- cat /etc/os-release # File transfer lxc file push local-file.txt my-container/root/ lxc file pull my-container/etc/hostname . # Snapshots lxc snapshot my-container snap0 lxc restore my-container snap0 lxc info my-container # View snapshot list

LXD 리소스 제한

# CPU limit lxc config set my-container limits.cpu 2 # Memory limit lxc config set my-container limits.memory 1GB # Disk limit lxc config device set my-container root size=10GB # Network bandwidth limit lxc config device set my-container eth0 limits.ingress=100Mbit lxc config device set my-container eth0 limits.egress=100Mbit

LXD 프로필

# Create a custom profile lxc profile create web-server lxc profile set web-server limits.cpu 2 lxc profile set web-server limits.memory 2GB # Launch a container using a profile lxc launch ubuntu:26.04 web1 --profile default --profile web-server # View the profile lxc profile show web-server # cloud-init integration lxc profile set web-server user.user-data - << 'EOF' #cloud-config packages: - nginx runcmd: - systemctl enable --now nginx EOF

마이크로클라우드

MicroCloud는 LXD, MicroCeph(분산 스토리지) 및 MicroOVN(SDN 네트워킹)을 통합하는 Canonical의 경량 클러스터 솔루션입니다.

마이크로클라우드 설치

# Install on all nodes sudo snap install lxd sudo snap install microceph sudo snap install microovn sudo snap install microcloud # Initialize the cluster on the first node sudo microcloud init

클러스터 초기화

# microcloud init will guide you through: # 1. Discovering other nodes on the LAN # 2. Selecting nodes to join the cluster # 3. Configuring MicroCeph distributed storage # 4. Configuring MicroOVN networking # 5. Configuring the LXD cluster # Verify after initialization lxc cluster list sudo microceph status sudo microovn status

MicroCloud 클러스터 사용

# Launch containers (automatically distributed across cluster nodes) lxc launch ubuntu:26.04 app1 lxc launch ubuntu:26.04 app2 lxc launch ubuntu:26.04 app3 # Launch on a specific node lxc launch ubuntu:26.04 db1 --target node2 # View container distribution lxc list -c nNtSl # Live-migrate a container lxc move app1 --target node3

기술 비교

특징KVM/QEMULXD 컨테이너Docker
가상화 유형하드웨어 가상화시스템 컨테이너애플리케이션 컨테이너
격리 수준완전 격리공유 커널공유 커널
시작 시간수십초1~2초1초 미만
리소스 오버헤드더 높은낮은매우 낮음
핵심독립 커널공유 호스트 커널공유 호스트 커널
사용 사례이기종 OS전체 Linux 환경마이크로서비스
밀도낮은높은매우 높음
실시간 마이그레이션지원됨지원됨오케스트레이션 도구 필요

권장사항

  • KVM/QEMU: 다양한 운영 체제 실행, 가장 강력한 격리 필요, 기존 가상화 시나리오
  • LXD: 전체 Linux 시스템 환경, 개발 및 테스트, 경량 서비스 격리
  • Docker: 마이크로서비스 배포, CI/CD, 애플리케이션 패키징 및 배포
  • MicroCloud: 소규모 클러스터, 에지 컴퓨팅, 간단한 분산 솔루션

관리 도구

조종석 웹 콘솔

# Install Cockpit sudo apt install cockpit cockpit-machines -y # Start the service sudo systemctl enable --now cockpit.socket # Access at https://server-ip:9090 # Manage virtual machines through the web interface # Firewall sudo ufw allow 9090/tcp

virt-manager(그래픽 관리)

# Install (requires a desktop environment or X11 forwarding) sudo apt install virt-manager -y # Remote connection (via SSH X11 forwarding) ssh -X user@server virt-manager