环境:
vmware
[root@kvm ~]# yum -y install lsb[root@kvm ~]# lsb_release -aLSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarchDistributor ID: CentOSDescription: CentOS release 6.6 (Final)Release: 6.6Codename: Final[root@kvm ~]#
检查是否支持虚拟化
检查是否支持虚拟化KVM[root@localhost ~]# egrep '(vmx|svm)' --color=auto /proc/cpuinfoSVM:AMD VMX:intel[root@localhost ~]# grep -E '(vmx|svn)' /proc/cpuinfo flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx rdtscp lm constant_tsc up arch_perfmon pebs bts xtopology tsc_reliable nonstop_tsc aperfmperf unfair_spinlock pni pclmulqdq vmx ssse3 cx16 pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx hypervisor lahf_lm ida arat epb pln pts dts tpr_shadow vnmi ept vpid[root@kvm ~]# grep -i "kvm" /boot/config-2.6.32-504.el6.x86_64 CONFIG_KVM_CLOCK=yCONFIG_KVM_GUEST=yCONFIG_HAVE_KVM=yCONFIG_HAVE_KVM_IRQCHIP=yCONFIG_HAVE_KVM_EVENTFD=yCONFIG_KVM_APIC_ARCHITECTURE=yCONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT=yCONFIG_KVM=mCONFIG_KVM_INTEL=mCONFIG_KVM_AMD=m[root@kvm ~]# modprobe kvm[root@kvm ~]# modprobe kvm_intel[root@kvm ~]#
xend libvirt 和kvm的libvirt是有所不用,kvm的源中libvirt是不支持xen,而xen的源中libvirt是支持kvmkvm只能虚拟cpu和内存,kvm无法虚拟io,要使用则需要安装qemu-kvm
1,虚拟网桥
[root@kvm ~]# cat /etc/sysconfig/network-scripts/ifcfg-br0 DEVICE=br0 BOOTPROTO=noneNM_CONTROLLED=no ONBOOT=yesTYPE=Bridge IPADDR=10.0.0.10NETMASK=255.255.0.0 GATEWAYY=10.0.0.1 DNS1=8.8.8.8 IPV6INIT=no USERCTL=no[root@kvm ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1 DEVICE=eth1 BOOTPROTO=noneNM_CONTROLLED=no ONBOOT=yes TYPE=EthernetBRIDGE=br0IPV6INIT=noUSERCTL=no
2,安装epel源
[root@kvm ~]# rpm -ivh http://mirrors.ustc.edu.cn/fedora/epel//6/x86_64/epel-release-6-8.noarch.rpm
3,安装包
[root@kvm ~]# yum install qemu-kvm qemu-kvm-tools virt-manager libvirt管理工具: qemu-kvm qemu-kvm-tools 管理工具虚拟机工具:virt-manager其他工具:libvirt
查看网桥
[root@kvm ~]# brctl showbridge name bridge id STP enabled interfacesvirbr0 8000.525400d00a9c yes virbr0-nic[root@kvm1 ~]# ================[root@kvm ~]# ln -sv /usr/libexec/qemu-kvm /usr/sbin/
5,创建一个5G磁盘文件
[root@kvm ~]# qemu-img create -f raw /opt/CentOS-6.6-x86_64.raw 5GFormatting '/opt/CentOS-6.6-x86_64.raw', fmt=raw size=5368709120 查看[root@kvm ~]# file /opt/CentOS-6.6-x86_64.raw /opt/CentOS-6.6-x86_64.raw: data查看详细信息[root@kvm ~]# qemu-img info /opt/CentOS-6.6-x86_64.rawimage: /opt/CentOS-6.6-x86_64.rawfile format: rawvirtual size: 5.0G (5368709120 bytes)disk size: 0[root@kvm ~]#
克隆系统(从主机cdrom克隆都服务器)
[root@kvm /]# dd if=/dev/cdrom1 of=/opt/CentOS-6.6-x86_64.iso9048064+0 records in9048064+0 records out4632608768 bytes (4.6 GB) copied, 1087.13 s, 4.3 MB/s================virsh list -all 查看当前虚拟机virsh undefine NAME
安装一个虚拟机
[root@kvm /]# virt-install --virt-type kvm --name CentOS-6.6-x86_64-Test --ram 512 --cdrom=/opt/CentOS-6.6-x86_64.iso --disk path=/opt/CentOS-6.6-x86_64.raw --network network=default --graphics vnc,listen=0.0.0.0 --noautoconsole --os-type=linux --os-variant=rhel6/Starting install...Creating domain... | 0 B 00:02 Domain installation still in progress. You can reconnect to the console to complete the installation process.[root@kvm1 /]# =========================virt-install --virt-type kvm 类型--name Centos6.6-x86_64名字--ram 512 分配内粗--cdrom=/opt/CentOS-6.6-x86_64.iso--disk path=/opt/CentOS-6.6-x86_64.raw--network network=default 网卡默认的default--graphics vnc,listen=0.0.0.0 监听地址 --noautoconsole 不打开console --os-type=linux --os-variant=rhel6 系统名称而后通过VNC连接,下一步安装即可!
修改下桥接即可远程连接!
[root@kvm ~]# virt-manager Xlib: extension "RANDR" missing on display "localhost:11.0".