Linux/RHEL6/KVM

Top / Linux / RHEL6 / KVM

KVMĶ


  • Ĥ뤳
    • ޤˤ⤹ΤǼȤƤȤʤ


ٶˤȤơʤäƤߤƤǤδۡ

  • KVMĶνƤʤΤˤʤCUIǿϤΤϤäȸ롣ɤ˽񤤤Ƥ륳ޥɤ̣Τ狼ʤޤ޼¹ԤˤʤΤϤʤCUIȤʤ꤬ʵ
  • GUIOSΥ󥹥ȡޤǤäƤߤȤ褤ΤǤϤʤȥסξⲾۥܥ塼ξ⥲Ȥξⲿ⤫XMLȤ롣С줿XML顢ʬCUIǤĤȤɬפˤʤϤ

KVMäƲʤ

  • ۴ĶΥϥѥХ
  • ե뤬XMLʤΤǤ狼䤹äݤäȤĤ狼äƤ

KVMĶΥͥåȥ

  • ͤˤĤȡkvmۥޥ󷲤ǤҤȤĤΥͥåȥǤ192.168.122.0/24ˡۥOSʪ󥿥եγΥͥåȥȤ̤ΤΡۥOSiptablesNATȤƻȤäƳˤǤ
  • ۥޥľܸ褦ˤʥۥȤʪ󥿥եƱͥåȥ˲ۥޥĤʤˤˤϡۥOSǡزۥ֥å١ʥåߤʤ͡ˤѰդۥȤʪNIC䲾ۥޥNIC򤹤٤Ƥβۥ֥åˤ֤鲼ɬפ롣
    • ⤦äΤ˽񤯤ȡۥȤ˲ۥ֥åvirbrXˤˤ֤餵TAPǥХvnetXˤäƤΤΤǤơ˲ۥޥNICethXˤ֤餵뤫󤸤餷䤳ʡ

ҤȤޤۥ֥åĶĤ

  • ۥ֥å br0 ե ifcfg-br0 ĤäơʪNIC ifcfg-eth0 br0 ˤ֤餵褦˽
    • /etc/sysconfig/network-scripts/ifcfg-br0
      DEVICE=br0
      TYPE=Bridge
      ONBOOT=yes
      BOOTPROTO=static
      IPADDR=192.168.1.100
      NETMASK=255.255.255.0
    • /etc/sysconfig/network-scripts/ifcfg-eth0
      DEVICE=eth0
      ONBOOT=yes
      NM_CONTROLLED=no
      BRIDGE=br0
    • ͥåȥƵư
      service network restart
    • ǧƤ
      • ifconfig
        br0       Link encap:Ethernet  HWaddr 00:19:99:A4:F3:3E
                 inet addr:192.168.1.100  Bcast:192.168.1.255  Mask:255.255.255.0
                 inet6 addr: fe80::219:99ff:fea4:f33e/64 Scope:Link
                 UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
                 RX packets:39 errors:0 dropped:0 overruns:0 frame:0
                 TX packets:73 errors:0 dropped:0 overruns:0 carrier:0
                 collisions:0 txqueuelen:0
                 RX bytes:3530 (3.4 KiB)  TX bytes:9239 (9.0 KiB)
        
        eth0      Link encap:Ethernet  HWaddr 00:19:99:A4:F3:3E
                 inet6 addr: fe80::219:99ff:fea4:f33e/64 Scope:Link
                 UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
                 RX packets:101 errors:0 dropped:0 overruns:0 frame:0
                 TX packets:31 errors:0 dropped:0 overruns:0 carrier:0
                 collisions:0 txqueuelen:1000
                 RX bytes:23406 (22.8 KiB)  TX bytes:3878 (3.7 KiB)
                 Interrupt:18
      • brctl show ȤʤĤäġʤvirbr0ϥ󥹥ȡ˾ˤǤƤ롣192.168.122.0/24ΥͥåȥˤĤʤäƤ벾ۥ֥å
        bridge name     bridge id               STP enabled     interfaces
        br0             8000.001999a4f33e       no              eth0
        virbr0          8000.000000000000       yes
      • virvr0פä餿֤brctl delbrä󤸤ʤ
    • br0virsh net-listˤϽФƤʤߤ

ǡɤ

  • ϲۥޥΥͥåȥǥХbr0ꤹФ褤櫓Ǥ
    • ɥᥤXMLʤʴ¸Τɲäʤ餳
      <interface type='bridge'>
        <source bridge='br0'/>

GUIˤ

  • Virtual Machine Managerʰʲvirt-manager ˤäƴǽ
  • ץǥȥå״Ķ
  • virt-managerˤäƤĤäۥޥϡΤޤޤǤvirshˤϤʤϿȤɬסȤäƤפäݤʡRHEL6ǻͤäΤ

virt-manager Υ󥹥ȡ

  • äݤѥåyumǤ

ۥޥ

  • ޥ͡[βۥޥ]÷ǥǤ롣ä˲ʤפʤ٥

OSΥ󥹥ȡ

  • Ϥ⤦OS˰¸ޥ͡¦ϥ󥹥ȡ륤᡼ɤäƤ뤫ꤹ뤯餤
    • ϤҤȤޤ Ubuntu 11.04 Server 줿Хɤ̣ʤȤˤʤäΤsshĶĤäƤȤssh˰ܹ

CUIˤ

  • virshʲάVirtual Machine Shell ȤʡˤǹԤϥϥѥХKVMɡvirshǤXenĶǤ餷פ˲۴ĶѤΥǤ͡

ŪʻȤ

  • virshĶ
    virsh
    • virshΤǤľܥޥɤ¹Ԥ
      <command>
  • virshޥɤľܼ¹Ԥ
    virsh <command>

褯Ȥʥޥ

  • ۥޥΰɽ
    list
    list --all
    list --inactive
  • ۥޥεư
    start <domain-name> [--console]
    • [--console]Ĥȵư˥󥽡³
  • ۥޥ
    shutdown <domain-name>
    • <domain-name>ϥɥᥤ̾iduuid

virsh Υ󥹥ȡ

  • ää yum groupinstall Virtualization 龡ä

ۥޥ(1)

  • 狼䤹ʤΤrhel5.4뤳Ȥˤ롣ʤߤ˥ۥȤrhel6Ǥ
  • ۥޥĤΤ virt-install ޥ
  • Ǥ⤽ˤޤϲۥϡɥɥ饤֤Ĥ
    • Ǥ˲ۥϡɥɥ饤֤ʤ顢vol-dumpxmlǥפxmlȤԽvol-createȤvol-cloneȤvol-create-from ȤǤ⤤Τ
    • ϥĤ롣ǥȤϤĤΥסϥǥեȤѰդƤġѰդƤΤGUIǤĤä餫ʡǽ餫餢Τ̤Ĵʤäpool-createФȤ⤦
      vol-create-as --pool default --name rhel54 --capacity 8G
      • formatǤ뤱ɡǥեȤrawˤʤΤǺϤΤޤޡʤrawäơguiǤĤärawˤʤä衪
      • Ǥ
        vol-list default
        vol-info --pool default rhel54
      • ĤǤʤΤxml⸫Ƥߤ褦
        vol-dumpxml --pool default rhel54

ۥޥ(2)

  • virt-install
    virt-install --name rhel54 --ram 512 --disk path=/var/lib/libvirt/images/rhel54.img --os-variant=rhel5.4 --network=bridge:br0 --location http://192.168.1.100/iso --nographics --extra-args='console=tty0 console=ttyS0,115200n8'
    • ǽ --cdrom iso᡼ľܻꤷɡ餦ޤʤäʸ
    • httpdδiso᡼ޥȤȤ˽ˤǤɤˤʤäʤ줬Υޥɡ
      mkdir /var/www/htdocs/iso
      mount -t iso9660 -o loop /root/isos/RHEL-5.4_i386_DVD.ISO /var/www/htdocs/iso/
      • /mnt/iso ˥ޥȤơ/etc/httpd/conf.d/ ۲ iso.conf ǤĤä Alias /iso "/mnt/iso" ۤȤ⤦
    • ͿƤ
      ץ̣
      --nameɥᥤʲۥޥˤ̾
      --ram
      --disk path=<path>Ȥۥܥ塼Υѥ
      --os-variant=<os>ۥޥOSμࡣȻꤹȤOS˹碌ƺ٤ŬƤȤʤȤǤOSϷޤäƤ롣ܺ٤virt-install˵ܤ
      --network=<type>:<name>ۥޥ³ͥåȥϤ餫ĤäƤۥ֥å³ƥۥȤƱͥåȥΤǾΤ褦ʻ
      --location󥹥ȡ륽λꡣ--cdromiso᡼ؤΥѥꤷƤɤ餷ɤޤʤäΤǥۥȤisoȤhttpǸƤĥ餻
      --nographicsƥȥ⡼ɤǥ󥹥ȡ뤵륪ץ󡣤ʤvncΩ夬äƤʤ餷
      --extra-args='console=tty0 console=ttyS0,115200n8'󥹥ȡ˥ȤΥꥢ륳󥽡ˤĤʤ褦ˤĥץ󡣥Ȥ /boot/grub/grub.conf ˥ꥢ륳󥽡³ط꤬ޤ롣줬ʤȰʸ virsh console hoge ǤʤơvncsshǤǤʤʤʤȻפäƤ餽⤽⥤󥹥ȡ̤ˤ⤽ԤʤäΤɬܤäݤʡsshĶȼ
      • Ȥgrub.confˤϤʤΤɲäƤ
        serial --unit=0 --speed=115200
        terminal --timeout=5 serial console
        title Red Hat Enterprise Linux Server (2.6.18-164.el5)
                root (hd0,0)
                kernel /vmlinuz-2.6.18-164.el5 ro root=/dev/VolGroup00/LogVol00 console==ttyS0,115200n8 rhgb quiet
                initrd /initrd-2.6.18-164.el5.img
      • serialȤconsoleȤؤʸۤ
      • ꤷʤä
      • serialԤˤϥѥƥӥåȤ̵ͭȤȥåץӥåȤɤΤΤȤ񤱤餷ȤꤢʤƤ⺤ʤ
    • Ȥʥץ
      ץ
      --file=<diskfile>Ȥۥܥ塼եλꡣdiskץȲ㤦ΤϤä
      --file-size=<filesize>ۥܥ塼Υե륵fileץȤ߹碌¸ߤʤȤ˼ưǤΥǤĤäƤ
      --vcpus=<number>Ȥ˳Ƥ벾ۥ
  • ÷virt-installġǤ륪ץϰŪ˾ʤ
    virt-install --prompt
    • ɬפʥץ򤢤餫Ϳ֤Ǥ÷Ǥμ¹ԤǤ롣ޤǤʤǽ餫ͿƤФäƴ
      virt-install --prompt --nographics --extra-args='console=tty0 console=ttyS0,115200n8'

ۥޥưߤ᤿

  • virsh start <domain>
  • Ȥ
    virsh shutdown <domain>
  • λŸĹߤʤΡ
    virsh destroy <domain>
  • 󥽡ˤĤʤ
    virsh console <domain>
  • ۥޥե뤴Ⱦä
    virsh undefine <domain>

todo

  • ۥȤεư˥Ȥư¹ԤˤϤɤ
  • isohttpǸˤIndexesɬܤ餽Τؤ⡣AllowOverRideȤ

virt-manager Ǻۥޥδ

¾

סäƤʤˡ

  • libvirt벾ۥȥ졼ΤޤȤޤñ̡
    • pool-listpool-infoʤɥޥɤ
    • ȥ졼ξvol-listȤvol-infoȤǸ
  • ޥ͡ǤĤä᡼פ餳ʤä
    virsh # vol-dumpxml --pool default Ubuntu_11.04_Server.img
    <volume>
      <name>Ubuntu_11.04_Server.img</name> 
      <key>/var/lib/libvirt/images/Ubuntu_11.04_Server.img</key>
      <source>
      </source>
      <capacity>8589934592</capacity>
      <allocation>8590544896</allocation>
      <target>
        <path>/var/lib/libvirt/images/Ubuntu_11.04_Server.img</path>
        <format type='raw'/>
        <permissions>
          <mode>0600</mode>
          <owner>0</owner>
          <group>0</group>
          <label>system_u:object_r:virt_image_t:s0</label>
        </permissions>
      </target>
    </volume>

virt-install --extra-args='console=tty0 console=ttyS0,115200n8' äƤʤˡ

  • consoleĻꤷƤΤϤʤǡ
    • ܤϤޤȤ˥ꥢݡȤĤäƤɡ㤢ܤϤʤˡ
      • ܤϥȤΥ󥹥ȡˤ̤ˤǤƤ뤷󥹥ȡgrub.conf˱ƶ͡ꥢ륳󥽡ط꤬ޤƤ
    • ܤϥۥ¦ Ȥͤɤʤ
  • ξꤷƥ󥹥ȡ뤷եˤϤФƤ
      <serial type='pty'>
        <target port='0'/>
      </serial>
      <console type='pty'>
        <target port='0'/>
      </console>
  • ҤȤξˤȡܤΤvncȤvirt-viewerǤĤʤȤѤ³λ꤫ȤΤ
  • ɤäꤷƥ󥹥ȡ뤷üsshĶvirt-viewerǤĤʤƤߤ
    • ǥץ쥤ʤäơsshʸδĶ̵
  • ۥOSΥǥȥå״ĶVNCǡȤФvirt-viewerǤĤʤƤߤ
    • ʤ󤫤顼
    • ­
      <graphics type='vnc' port='-1' autoport='yes'/> # ɲ
       <address type=........> # ι
      • autoportˤlibvirtʤǤΤʡˤݡȤưŪˤդͻҡư餷
      • virt-viewerϤΥݡȤФ³vnc饤ȤΩ夲Ƥäݤ
      • ݡȤ狼аʲΥޥɤǤvirt-viewerʤ³Ǥ
        vncviewer localhost:<port>
    • ѹȿ
      virsh define <domain>
    • qemu.conf񤭤ʤ
      vnc_listen = "0.0.0.0" #ȤϤ
    • ѹȿ
      service libvirtd restart
    • Ҥäɲ̤ʤ㤦󤸤ˡgettyΩ夬äƤʤġġ
    • Ȥ櫓/etc/inittab򸫤롣Ĵ٤nographicsǥ󥹥ȡ뤹Ȥʤ餷ȥȤȤҤɤġġ
      co:2345:respawn:/sbin/agetty ttyS0 115200 vt100-nav
      #1:2345:respawn:/sbin/mingetty tty1
      #2:2345:respawn:/sbin/mingetty tty2
      #3:2345:respawn:/sbin/mingetty tty3
      #4:2345:respawn:/sbin/mingetty tty4
      #5:2345:respawn:/sbin/mingetty tty5
      #6:2345:respawn:/sbin/mingetty tty6
    • ޤ͡ꥢ륳󥽡뤵ҤФ͡VNCǤĤʤˤgettyʤȥʤΤǥȤϤƤʤ
      init q
  • ޤǤvirt-viewer̵vncΩ夬ĶǤ
  • 㤢ܤconsoleǥ󥹥ȡ뤷ɤʤ롩
    • 󥹥ȡϤդĤ˽λ
    • ˤѲʤʤƤdiffȤФ褫äġġ
        <serial type='pty'>
          <target port='0'/>
        </serial>
        <console type='pty'>
          <target port='0'/>
        </console>
    • graphicsԤdefineդĤvncĤʤää衩 뤧
  • ʤδ֤ˤɤȤä2ѥ٤ͷꤷƤ
  • ǡɤΤʤ
    • ĿŪʷϡ--extra-args='console=ttyS0,115200n8' ǤȤΡ
    • ttyS0ɬסʤȥ󥹥ȡ̤˿ʤޡʤˤʤ
    • tty0פʤʤġ
      • ⤽ console=tty0 äƤʸ󥹥ȡΥƥǤȤ˸ʤ
      • 󥽡طǥƥΤˤꤽʤΤgrub.conf椫ʤäƤäɡtty0εҤϥȤgrub.confˤϻĤʤ
      • 󥹥ȡgrub̤˽ФƤΤttyS0http://gyazo.com/fe61adb51c46bee487b833b87379f5c7ˤ
      • tty0äƲۥ󥽡͡ǡttyS0ꥢ륳󥽡롣ñˡءʥ󥹥ȡβ̤tty0ttyS0Ρξ˽Ф٤äưŪ˻ꤷƤʤ󤸤ʤΡ
      • grub.confkernelԤtty0ttyS0դĤʻȡ˥tty0ˤȥꥢݡȡttyS0ˤξ˲̤Ϥ褦ˤʤ餷
      • extra-argsͤϥ󥹥ȡΥͥϤƤΤ http://gyazo.com/66eec1419140b7ad9688161531f19db4
      • 㡢virt-install饤󥹥ȡ뤹äƤδĶǡ̤󤫽˽Ϥ̣äƤʤ
      • virt-installΤȤˤĤʤǤΤϥꥢ륳󥽡ttyS0ˡȡȤ tty0 νϤäơۥȤΤɤǸΡʤʤ̵̣ǤϤʤΡ
      • 󥹥ȡʤ tty0 äƤ֤qemuvnc͡Ǥ⤽⤽vncʤǥ󥹥ȡǤ褦nographicsˤ櫓
      • tty0ϥ󥹥ȡˡʾʤȤʹ֤˸뤳ȤϤǤʤʤȻפˤΤǡ虜虜ꤹɬפϤʤ褦ʵ
      • Ǥ⥤󥹥ȡץtty0ϤܤΤʤ̤ʰ̣Τ⤷ʤ
      • sshĶȤۥȤXۤʤľܤtty*ĶȤΤǤѤΤʤ

virt-installΥǥե

  • man virt-install
  • ǥեȤxenkvm
  • locationcdrom
    • locationϥ󥹥ȡɤޤkernelinitrdΤ꤫򼨤locationisoꤹiso鵯ưϤ뤱ɡ󥹥ȡǥȤƤisoϻȤʤʤ
    • cdromϥ󥹥ȡǥλʤǡ֡Ȥ櫓ǤϤʤ
    • locationcdromƱ˻Ǥʤפisoľܤϥ󥹥ȡǤʤ󤸤ʤ
  • diskfile
    • fileϸŤץǡdiskȤfileѻߤ
    • Ǥˤ벾ۥܥ塼ȤϾʡϲʡʿϥ꤬ɬܡ
      --disk path=/path/to/vol.img
      --disk path=/path/to/vol.img,size=8 #ϥХñ

Last-modified: 2011-10-06 () 16:02:58 (2481d)