본문

libvirt에 대하여 #1. 소개

libvirt는 Linux의 가상화를 '지원'하기 위하여 구성된 API, 데몬, 그리고 관리 툴들의 집합이다. Linux 가상화를 구현하는데에는 LXC, KVM/QEMU, Xen, VMware ESX등의 Hypervisor기술들이 사용되는데, 이러한 다양한 Hypervisor기반의 가상환경을 더욱 편하고 안정적으로 사용하기 위하여 libvirt가 소개되었다. 엄밀히 따지자면 libvirt 자체는 가상환경 관리를 위한 C 라이브러리이고(물론 Java, Python등 다양한 언어도 지원한다), 여기에 통신을 위한 데몬, 그리고 virsh등의 가상화 툴이 추가된것이라고 할 수 있다.


libvirt의 목적을 설명하기에 앞서, 세가지 짚고 넘어가야할 용어들이 있다. Node는 일반 컴퓨터와같은 물리머신을 지칭한다. Hypervisor는 Node를 가상화하여 다양한 가상머신을 만들 수 있도록 하는 소프트웨어 계층을 말하며, 여기에는 VMware나 VirtualBox와 같은 프로그램들을 예로 들 수 있다. Domain은 가상머신위에서 동작하는 운영체제의 인스턴스를 말하는데, 이건 인스턴스와 가상머신을 엄격히 구분해놔서 그렇지, 흔히말하는 VirtualBox위에서 돌아가는 (Ubuntu등의) 가상머신이라 보면 된다.



이때 libvirt의 목적은 '(로컬/원격)노드상에 생성된 Domain들을 안전하게 관리하는 보편적이고 안정적인 레이어(계층)를 제공' 하는것이다. 이를 위하여 libvirt는 Domain을 프로비저닝, 생성, 수정, 모니터링, 제어, 마이그레이션, 그리고 삭제하는등의 Hypervisor를 위한 다양한 API를 제공한다. 또한 인터페이스, 방화벽, 저장공간 설치 및 관리등과같은 Node 관리 API들을 제공하며, 상태 모니터링 API가 제공되어 정책 관리, Domain상태관리, Node 자원 상태정보등이 제공된다. 즉 가상화 환경을 전반적으로 두루 관리하는것이 목표이다. 더욱 구체적으로는 다음을 포함한다.

  • VM management: Various domain lifecycle operations such as start, stop, pause, save, restore, and migrate. Hotplug operations for many device types including disk and network interfaces, memory, and cpus.
  • Remote machine support: All libvirt functionality is accessible on any machine running the libvirt daemon, including remote machines. A variety of network transports are supported for connecting remotely, with the simplest being SSH, which requires no extra explicit configuration.
  • Storage management: Any host running the libvirt daemon can be used to manage various types of storage: create file images of various formats (qcow2, vmdk, raw, ...), mount NFS shares, enumerate existing LVM volume groups, create new LVM volume groups and logical volumes, partition raw disk devices, mount iSCSI shares, and much more.
  • Network interface management: Any host running the libvirt daemon can be used to manage physical and logical network interfaces. Enumerate existing interfaces, as well as configure (and create) interfaces, bridges, vlans, and bond devices.
  • Virtual NAT and Route based networking: Any host running the libvirt daemon can manage and create virtual networks. Libvirt virtual networks use firewall rules to act as a router, providing VMs transparent access to the host machines network.



libvirt는 보편적인 인터페이스를 통하여 Hypervisor(파란색)에 대한 의존성을 감소시킨다. 이 글 에서 적은 표현을 쓰자면 다양한 Hypervisor들을 추상화시켜 놓은 것. 이를 통해 어플리케이션(분홍색) 개발자는 개별적인 Hypervisor에 대한 걱정없이 일관적인 개발이 가능하다. 아래의 코드는 libvirt를 사용하여 system의 QEMU Hypervisor에 연결하는것을 보여준다. 이와같이 libvirt는 url주소를 통하여 로컬/원격지의 다양한 Hypervisor에 접속이 가능하다. (xen:///, lxc:///등으로 변경하여 각각의 Hypervisor에 접근할 수 있다)

#include <stdio.h>
#include <stdlib.h>
#include <libvirt/libvirt.h>

int main(int argc, char *argv[])
{
    virConnectPtr conn;

    conn = virConnectOpen("qemu:///system");
    if (conn == NULL) {
        fprintf(stderr, "Failed to open connection to qemu:///system\n");
        return 1;
    }
    virConnectClose(conn);
    return 0;
}

libvirt에는 관리 툴들이 포함된다고 서두에 밝힌 바 있다. 코딩을 하지 않더라도 각각의 Node(기상머신)을 관리해야 할 필요가 있는데, 이를위해 virsh라는 명령줄 tool이 제공된다. 아래와 같은 명령을 실행할 수 있다.

virsh -c qemu:///system list

virsh -c qemu:///system start web_devel



참고주소

http://libvirt.org/guide/html/Application_Development_Guide-Connections.html

https://help.ubuntu.com/lts/serverguide/libvirt.html

https://wiki.archlinux.org/index.php/libvirt

http://www.iamroot.org/xe/Hypervisor_3_KVM/48717

댓글

Holic Spirit :: Tistory Edition

design by tokiidesu. powerd by kakao.