How to install KVM virtual machines on CentOS6.4 system

KVM virtual machine installed on the system CentOS6.4

 

NOTE: The following instructions are summed up after experimental verification of transcripts, a friend in need can be a reference, the following is based on the experimental environment installed on VMware12.5.2 virtual machine version.

First, install the KVM

1. kvm needs the support of the CPU (Intel VT or AMD SVM). Enter the command: egrep '. ^ Flags * (vmx | svm)' / proc / cupinfo, shown below: svm, I can see the computer's CPU is AMD's model.

2.  Installation KVM libvirted , enter the command: yum the install kmod-KVM KVM QEMU KVM-QEMU the virt-IMG-Viewer Manager the libvirt the libvirt the virt-Python-Python-virtinst

 

 

3.  Start libvirted

input the command:

service messagebus start

service haldaemon start

service libvirtd start

chkconfig messagebus on

chkconfig haldaemon on

chkconfig libvirtd on

 

4. 检查kvm是否安装成功,输入命令:virsh -c qemu:///system list。检查kvm模块是否安装成功,输入命令:/sbin/lsmod | grep kvm

 

二、配置网桥

1. 输入命令:

vi /etc/sysconfig/network-scripts/ifcfg-br0

a、

DEVICE=br0

TYPE=Bridge

BOOTPROTO=static

BROADCAST=192.168.xxx.255

IPADDR=192.168.xxx.1

NETMASK=255.255.255.0

NETWORK=192.168.xxx.0

ONBOOT=yes

 

 

b、

vi /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

BOOTPROTO=dhcp

ONBOOT=yes

BRIDGE=br0

 

 

2. 重起网络服务生效
service network restart

 

3. 输入命令:echo 1 > /proc/sys/net/ipv4/ip_forward  #虚拟机上网

 

4. 检查桥接网络
[root@localhost ~]# brctl show
bridge name     bridge id               STP enabled     interfaces
br0             8000.842b2b74e1b6       no              eth0
virbr0          8000.000000000000       yes
br0是我们配置的桥接网卡,virbr0是系统脚本自动配置的NAT网卡

 

三、安装VNC
(1). 输入命令:
yum install tiggervnc-server

 

 

 

查看vnc安装输入命令:

rpm -q vnc tigervnc-server

安装成功显示

package vnc is not installed

tigervnc-server-1.1.0-8.el6_5.x86_64

 

 

(2). 输入命令:
vi /etc/sysconfig/vncservers
#加一行
VNCSERVERS="1:root"

 

 

(3). 输入命令:
vncpasswd
创建密码:123456

 

 

(4). 输入命令:
/etc/init.d/vncserver start

 

(5). 输入命令:
# netstat -nulpt | grep vnc
tcp        0      0 0.0.0.0:5901                0.0.0.0:*                   LISTEN      29167/Xvnc
tcp        0      0 0.0.0.0:6001                0.0.0.0:*                   LISTEN      29167/Xvnc
tcp        0      0 :::6001                     :::*                        LISTEN      29167/Xvnc
表示vnc可以使用了

 

四、创建KVM虚拟机
#virsh-install
    1、输入虚拟机名称
    2、分配多少内存
    3、处理器的个数
    4、此步可以直接输入iso的位置或是url
    5、虚拟机类型KVM
    6、定义虚拟机磁盘映像的位置
    7、磁盘的大小
    6、指定哪个桥或者可以指定多个桥
    7、额外的控制台和KS文件
    8、连接到系统参数
    参数说明注意每行都要空格
    -n 虚拟机名称
    -r 分配虚拟机内存大小
    --vcpus 分配虚拟cpu个数
    -c 镜像文件位置
    --vnc --vncport=5901 --vnclisten=0.0.0.0 启动图形安装界面
    --virt-type 虚拟机模式
    -f 虚拟机系统文件存储目录
    -s 分配磁盘大小(GB
    -w 联网方式(birdge bridge:br0/nat bridge:virbr0
    --os-type='windows' --os-variant=win2k3 安装windows最好加上这个否则会报错
    virt-install工具安装虚拟机后,在目录/etc/libvirt/qemu/下生成xml配置文件
    -s 用来指定虚拟磁盘的大小单位为GB
    -m 指定虚拟网卡的硬件地址默认virt-install自动产生
    -p 以半虚拟化方式建立虚拟机
    -l 指定安装来源
    -x EXTRA, --extra-args=EXTRA当执行从"--location"选项指定位置的客户机安装时,附加内核命令行参数到安装程序。
    -v, --hvm 设置全虚拟化
virt-install --name=centos6.3  --ram 1024 --vcpus=2 --disk path=/data0/centos-6.3.x86_64.img.img,size=20  --accelerate --cdrom /data0/CentOS-6.3-x86_64-bin-DVD1.iso  --graphics vnc,listen=0.0.0.0,port=5920,  --network bridge=br0  --force  --autostart
执行后,netstat -nulpt | grep 5920 看端口启用否

 

五、KVM虚拟机配置

1. 用默认向导创建的KVM虚拟机,磁盘文件位置不能修改。可以用下面的命令先创建一个磁盘文件

qemu-img create -f qcow2 win7.img 700G

home/vps目录下,建立一个虚拟机的磁盘文件

 

2. Virtual Machine Manager创建一个虚拟机系统

 

 

从硬盘里找到要安装的系统盘镜像,例如win7.iso

 

 

这里,一定要选 Customeize configuration before install ,在安装前做最后的定制

 

注意:需要修改2个地方

a.添加一个Input设备(EvTouch USB Graphics Tablet)(网上很多文章都是介绍用 vi 去修改配置文件,我不建议你那么做,很麻烦,而且我实验了效果还不怎么好!),如果不加这个设备,你在VNC环境下,你会发现 鼠标很不灵光,还会乱跑!

 

 

b.添加一个Graphics 设备,并且把默认的Display VNC 删除掉(因为默认的VNC只监听127.0.0.1

  

 

至此,关键部分都配置完毕。启动虚拟机,并查看 VNC 端口号

默认端口是 5900

好了,到此为止!我们的KVM虚拟机已经成功安装并且在KVM上成功加载WIN7 GHOST。接下来如何安装WIN7系统我想大家应该都非常熟悉了,(如果不会,可以自行参考某度上安装WIN7操作系统步骤)在此就不浪费时间了,顺祝大家周末愉快!

Guess you like

Origin www.cnblogs.com/lyiwei/p/11295179.html