KVM手动配置安装实践(一)

环境:

vmware

 

[root@kvm ~]# yum -y install lsb
[root@kvm ~]# lsb_release  -a
LSB 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-noarch
Distributor ID: CentOS
Description:    CentOS release 6.6 (Final)
Release:    6.6
Codename:   Final
[root@kvm ~]# 

 检查是否支持虚拟化

检查是否支持虚拟化
KVM
[root@localhost ~]# egrep '(vmx|svm)' --color=auto /proc/cpuinfo
SVM: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=y
CONFIG_KVM_GUEST=y
CONFIG_HAVE_KVM=y
CONFIG_HAVE_KVM_IRQCHIP=y
CONFIG_HAVE_KVM_EVENTFD=y
CONFIG_KVM_APIC_ARCHITECTURE=y
CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT=y
CONFIG_KVM=m
CONFIG_KVM_INTEL=m
CONFIG_KVM_AMD=m
[root@kvm ~]# modprobe kvm
[root@kvm ~]# modprobe kvm_intel
[root@kvm ~]# 

 xend libvirt 和kvm的libvirt是有所不用,kvm的源中libvirt是不支持xen,而xen的源中libvirt是支持kvm
kvm只能虚拟cpu和内存,kvm无法虚拟io,要使用则需要安装qemu-kvm

1,虚拟网桥

[root@kvm ~]# cat /etc/sysconfig/network-scripts/ifcfg-br0 
DEVICE=br0 
BOOTPROTO=none
NM_CONTROLLED=no 
ONBOOT=yes
TYPE=Bridge 
IPADDR=10.0.0.10
NETMASK=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=none
NM_CONTROLLED=no 
ONBOOT=yes 
TYPE=Ethernet
BRIDGE=br0
IPV6INIT=no
USERCTL=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 show
bridge name bridge id  STP enabled interfaces
virbr0  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 5G
Formatting '/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.raw
image: /opt/CentOS-6.6-x86_64.raw
file format: raw
virtual size: 5.0G (5368709120 bytes)
disk size: 0
[root@kvm ~]# 


克隆系统(从主机cdrom克隆都服务器)

[root@kvm /]# dd if=/dev/cdrom1 of=/opt/CentOS-6.6-x86_64.iso
9048064+0 records in
9048064+0 records out
4632608768 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".

0 分享

您可以选择一种方式赞助本站

支付宝扫码赞助

支付宝扫码赞助

日期: 2015-11-26分类: KVM

标签: KVM

发表评论