kvm学习笔记

1、通过virt管理工具创建虚拟机

qemu-img create -f qcow2 -o size=50G,preallocation="metadata" /kvm/images/centos6.qcow2  创建磁盘文件
virt-install --name=centos01  --ram 512 --vcpus=2 --disk path=/home/kvm/images/centos6-d01.qcow2,format=qcow2,size=15,bus=virtio --accelerate --cdrom /opt/CentOS-6.5-x86_64-bin-DVD1.iso  --vnc --vncport=5901 --vnclisten=0.0.0.0 --network bridge=br0,model=virtio --noautoconsole      创建虚拟机
2、日常管理:

查看KVM列表:virsh  list --all

启动KVM:virsh start centos01

关闭KVM:virsh shutdown centos01

强制关闭KVM:virsh destroy centos01

暂停KVM:virsh suspend centos01

恢复KVM:virsh resume centos01

克隆KVM:virt-clone -o centos01 -n centos02 -f /data1/centos02.img

编辑KVM配置:virsh edit centos01

删除VNC端口:

virsh edit centos01,打开xml后,删除下面的配置:

1
2
3
    <graphics type='vnc' port='5910' autoport='no' listen='0.0.0.0'>
      <listen type='address' address='0.0.0.0'/>
    </graphics>

设置KVM开机自动启动:vrish autostart centos01

3、KVM配置文件(http://libvirt.org/formatdomain.html)

/etc/libvirt            当一个KVM虚拟机配置好后,就会在/etc/libvirt/qemu目录中生成xml格式的文件

                              关闭虚拟机后修改相关配置文件,service libvirtd restart重新启动libvirtd服务器后配置文件生效

/var/lib/libvirt      默认镜像等存储目录

/var/log/libvirt     日志存储位置  

The following files are required to manage and debug KVM problems:

  1. /etc/libvirt/ - Main configuration directory.
  2. /etc/libvirt/qemu/ - Virtual machine configuration directory. All xml files regarding VMs are stored here. You can edit them manually or via virt-manager.
  3. /etc/libvirt/qemu/networks/ - Networking for your KVM including default NAT. NAT is only recommended for small setup or desktops. I strongly suggest you use bridged based networking for performance.
  4. /etc/libvirt/qemu/networks/default.xml - The default NAT configuration used by NAT device virbr0.
  5. /var/log/libvirt/ - The default log file directory. All VM specific logs files are stored here.
  6. /etc/libvirt/libvirtd.conf - Master libvirtd configuration file.
  7. /etc/libvirt/qemu.conf - Master configuration file for the QEMU driver.
http://www.cyberciti.biz/faq/centos-rhel-linux-kvm-virtulization-tutorial/
原文地址:https://www.cnblogs.com/guoqp/p/5378544.html