我是在vmware虚拟机上安装的
一、检查cpu是否支持虚拟表
grep ‘vmx|svm‘ /proc/cpuinfo --color //有则支持
二、安装kvm及所需软件包并验证
yum -y install kvm virt-* libvirt //
检查安装是否成功
lsmod|grep kvm
ls /dev/kvm
三、网络配置
cat /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
#HWADDR=00:0C:29:F2:0D:DA
TYPE=Ethernet
#UUID=e4728a54-13a5-48a2-8fcc-030eb15e789f
ONBOOT=yes
#NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=192.168.10.20
NETMASK=255.255.255.0
GATEWAY=192.168.10.2
cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
#HWADDR=00:0C:29:F2:0D:DA
TYPE=Ethernet
#UUID=e4728a54-13a5-48a2-8fcc-030eb15e789f
ONBOOT=yes
#NM_CONTROLLED=yes
BOOTPROTO=none
#IPADDR=192.168.10.20
#NETMASK=255.255.255.0
#GATEWAY=192.168.10.2
BRIDGE=br0
四、加载网卡模块,并重启网络服务
modprobe -rv e1000
modprobe -v e1000
/etc/init.d/network restart
chkconfig libvirtd on
五、安装虚机
virt-install \
--connect qemu:///system \
--name=rhel-server-10.20 \
--ram=1024 --vcpus=1 \
--os-type=linux \
--hvm \
--cdrom=/store/rhel-server-6.4-x86_64-dvd.iso \
--disk path=/store/KVM/rhel-server-10.20.img,size=20 \
--graphics vnc \
--network bridge=br0 \
--noautoconsole \
--debug
六、一些简单的使用
通过vnc进行安装配置
virsh vncdisplay rhel-server-10.20
克隆虚机
virt-clone --connect=qemu:///system -o rhel-server-10.20 -n rhel-server-10.21 -f /store/KVM/rhel-server-10.20.img -f /storage/DISK/rhel-server-10.20
添加硬盘
virsh attach-disk 虚拟机名 source target
eg:qemu-img create -f raw /storage/DISK/VM_CentOS.img 50G
virsh attach-disk VM_CentOS_6.5_x64 /storage/DISK/rhel-server-10.20.img vda --config
删除硬盘
virsh detach-disk VM_CentOS_6.5_x64 /storage/DISK/rhel-server-10.20.img --config
KVM增加块设备:
qemu-img create -f raw /storage/DISK/rhel-server-10.20.img 200G
virsh edit VMname
<disk type=‘file‘ device=‘disk‘>
<driver name=‘qemu‘ type=‘raw‘/>
<source file=‘/storage/DISK/rhel-server-10.20.img‘/>
<target dev=‘vda‘ bus=‘virtio‘/>
<address type=‘pci‘ domain=‘0x0000‘ bus=‘0x00‘ slot=‘0x05‘ function=‘0x0‘/>
</disk>
动态增加内存
virsh setmem rhel-server-10.20 8388608