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. 大功告成

相关文章
相关标签/搜索