linux 下的KVM 虛擬機

linux 下的kvm的使用html

  1.  cpu開啓VTlinux

  2.  安裝kvm套件ubuntu

    1. Ubuntu: $ sudo apt-get install qemu-kvm qemu-system libvirt-bin  bridge-utilsvim

      1. 驗證: $ kvm-okcentos

      b. CentOS:# yum -y install qemu-kvm libvirt virt-install bridge-utilsapi

           i. 驗證:#lsmod | grep kvm
      bash

      # systemctl start libvirtddom

      # systemctl enable libvirtdide

  3.  添加br0橋接網口oop

    1. Ubuntu: 

    2. $ sudo vim /etc/network/interfaces


    3. auto lo 
      iface lo inet loopback 
      
      auto eth0 
      iface eth0 inet static 
      #address 192.168.102.18 #netmask 255.255.255.0 #gateway 192.168.102.254 auto br0 
      iface br0 inet static 
      address 192.168.102.18 
      netmask 255.255.255.0 
      gateway 192.168.102.254 
      bridge_ports eth0 
      bridge_stp off 
      bridge_fd 0
    4. CentOS: 

    5. # vim ifcfg-eth0

    6. BOOTPROTO=none
      DEVICE=eth0
      NM_CONTROLLED=no
      ONBOOT=yes
      BRIDGE=br0
    7. # vim ifcfg-br0

    8. BOOTPROTO=static
      DEVICE=br0
      TYPE=Bridge
      NM_CONTROLLED=no
      IPADDR=192.168.8.150
      NETMASK=255.255.255.0
      GATEWAY=192.168.8.1
      DNS1=122.200.121.230
      DNS2=8.8.8.8


  4.  建立虛擬機磁盤,或者在安裝虛擬機的時候建立該磁盤。

  5.  安裝虛擬機 ubuntu和centos系統一致,都是使用的virt-install命令

    1. 橋接模式:
      virt-install --name=gatewat-4 --ram 4096 --vcpus=4 -f /home/kvm/gateway-4.qcow2 --cdrom /home/iso/CentOS-6.5-x86_64-bin-DVD1.iso --graphics vnc,listen=0.0.0.0,port=5920, --network bridge=br0 --force --autostart
    2. NAT模式:
      virt-install --name=test --ram 512 --vcpus=1 -f /home/kvm/test.qcow2 --cdrom /opt/CentOS-6.5-x86_64-bin-DVD1.iso --graphics vnc,listen=0.0.0.0,port=5988, --network network=default, --force --autostart
  6.  

  7.  使用虛擬機

  8.  使用安裝的虛擬機磁盤作原始鏡像來啓動新的虛擬機

    1. 給模版的磁盤擴容: qemu-img resize centos.qcow2 +10G #增長磁盤大小

    2. 關閉安裝的虛擬機

    3. 複製安裝的虛擬機磁盤

    4. 從新define 一個虛擬機的xml文件,具體內容以下:


    5. <domain type='kvm'>
          <name>vm01</name>
          <memory>4096000</memory>
          <currentMemory>4096000</currentMemory>
          <vcpu>2</vcpu>
      
         <os>
            <type arch='x86_64' machine='pc'>hvm</type>
            <boot dev='hd'/> 
         </os>
      
         <features>
           <acpi/>
           <apic/>
           <pae/>
         </features>
      
         <clock offset='localtime'/>
         <on_poweroff>destroy</on_poweroff>
         <on_reboot>restart</on_reboot>
         <on_crash>destroy</on_crash>
         <devices>
           <emulator>/usr/libexec/qemu-kvm</emulator>
      
           <disk type='file' device='disk'>
            <driver name='qemu' type='qcow2'/>
             <source file='/storage/instance/vm01/centos6.6.qcow2'/>
             <target dev='hda' bus='ide'/>
           </disk>
      
           <disk type='file' device='disk'>
            <driver name='qemu' type='qcow2'/>
             <source file='/storage/instance/vm01/disk.qcow2'/>
             <target dev='hdb' bus='ide'/>
           </disk>
      
           <disk type='file' device='cdrom'>
             <source file='/iso/CentOS-6.6-x86_64-bin-DVD1.iso'/>
             <target dev='hdc' bus='ide'/>
             </disk>
      
           <interface type='bridge'>
            <source bridge='br0'/>
           </interface>
      
          <input type='mouse' bus='ps2'/>
           <graphics type='vnc' port='-1' autoport='yes' listen = '0.0.0.0' keymap='en-us'/>
         </devices>
       </domain>
    6. 啓動剛建立的虛擬機

    7. 大功告成

相關文章
相關標籤/搜索