xen和kvm虚拟化

                                    xen虚拟化

配置yum源

# cd/etc/yum.repos.d

# ls

centos.repo  kernel-xen.repo  xen4.repo

# vim kernel-xen.repo

[kernel-xen]

name=kernel-xen

baseurl=http://xenbits.xen.org/people/mayoung/testing/x86_64/

gpgcheck=0

# vim xen4.repo

[xen4]

name=xen4

baseurl=http://mirrors.sohu.com/centos/6/xen4/x86_64/

gpgcheck=0

yum源里的rpm包

# ls /kernel-xen/

kernel-2.6.32-131.21.1.el6.xendom0.x86_64.rpm

kernel-debug-2.6.32-131.21.1.el6.xendom0.x86_64.rpm

kernel-debug-debuginfo-2.6.32-131.21.1.el6.xendom0.x86_64.rpm

kernel-debug-devel-2.6.32-131.21.1.el6.xendom0.x86_64.rpm

kernel-debuginfo-2.6.32-131.21.1.el6.xendom0.x86_64.rpm

kernel-debuginfo-common-x86_64-2.6.32-131.21.1.el6.xendom0.x86_64.rpm

kernel-devel-2.6.32-131.21.1.el6.xendom0.x86_64.rpm

kernel-doc-2.6.32-131.21.1.el6.xendom0.noarch.rpm

kernel-firmware-2.6.32-131.21.1.el6.xendom0.noarch.rpm

kernel-headers-2.6.32-131.21.1.el6.xendom0.x86_64.rpm

perf-2.6.32-131.21.1.el6.xendom0.x86_64.rpm

perf-debuginfo-2.6.32-131.21.1.el6.xendom0.x86_64.rpm

repodata


# ls /xen4

e1000e-2.4.14-3.4.53.1.el6.centos.alt.x86_64.rpm

e1000e-2.4.14-3.4.54.1.el6.centos.alt.x86_64.rpm

e1000e-2.4.14-3.4.59.1.el6.centos.alt.x86_64.rpm

e1000e-2.4.14-3.4.61.2.el6.centos.alt.x86_64.rpm

ipxe-bootimgs-20120328-2.gitaac9718.el6.centos.alt.noarch.rpm

ipxe-roms-20120328-2.gitaac9718.el6.centos.alt.noarch.rpm

ipxe-roms-qemu-20120328-2.gitaac9718.el6.centos.alt.noarch.rpm

kernel-3.4.46-8.el6.centos.alt.x86_64.rpm

kernel-3.4.50-8.el6.centos.alt.x86_64.rpm

kernel-3.4.53-8.el6.centos.alt.x86_64.rpm

kernel-3.4.54-8.el6.centos.alt.x86_64.rpm

kernel-3.4.59-8.el6.centos.alt.x86_64.rpm

kernel-3.4.61-9.el6.centos.alt.x86_64.rpm

kernel-devel-3.4.46-8.el6.centos.alt.x86_64.rpm

kernel-devel-3.4.50-8.el6.centos.alt.x86_64.rpm

kernel-devel-3.4.53-8.el6.centos.alt.x86_64.rpm

kernel-devel-3.4.54-8.el6.centos.alt.x86_64.rpm

kernel-devel-3.4.59-8.el6.centos.alt.x86_64.rpm

kernel-devel-3.4.61-9.el6.centos.alt.x86_64.rpm

kernel-doc-3.4.46-8.el6.centos.alt.noarch.rpm

kernel-doc-3.4.50-8.el6.centos.alt.noarch.rpm

kernel-doc-3.4.53-8.el6.centos.alt.noarch.rpm

kernel-doc-3.4.54-8.el6.centos.alt.noarch.rpm

kernel-doc-3.4.59-8.el6.centos.alt.noarch.rpm

kernel-doc-3.4.61-9.el6.centos.alt.noarch.rpm

kernel-firmware-3.4.46-8.el6.centos.alt.noarch.rpm

kernel-firmware-3.4.50-8.el6.centos.alt.noarch.rpm

kernel-firmware-3.4.53-8.el6.centos.alt.noarch.rpm

kernel-firmware-3.4.54-8.el6.centos.alt.noarch.rpm

kernel-firmware-3.4.59-8.el6.centos.alt.noarch.rpm

kernel-firmware-3.4.59-9.el6.centos.alt.noarch.rpm

kernel-firmware-3.4.61-9.el6.centos.alt.noarch.rpm

kernel-headers-3.4.46-8.el6.centos.alt.x86_64.rpm

kernel-headers-3.4.50-8.el6.centos.alt.x86_64.rpm

kernel-headers-3.4.53-8.el6.centos.alt.x86_64.rpm

kernel-headers-3.4.54-8.el6.centos.alt.x86_64.rpm

kernel-headers-3.4.59-8.el6.centos.alt.x86_64.rpm

kernel-headers-3.4.61-9.el6.centos.alt.x86_64.rpm

libvirt-0.10.2.4-5.el6.centos.alt.x86_64.rpm

libvirt-0.10.2.6-5.el6.centos.alt.x86_64.rpm

libvirt-0.10.2.7-5.el6.centos.alt.x86_64.rpm

libvirt-client-0.10.2.4-5.el6.centos.alt.x86_64.rpm

libvirt-client-0.10.2.6-5.el6.centos.alt.x86_64.rpm

libvirt-client-0.10.2.7-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-0.10.2.4-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-0.10.2.6-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-0.10.2.7-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-config-network-0.10.2.4-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-config-network-0.10.2.6-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-config-network-0.10.2.7-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-config-nwfilter-0.10.2.4-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-config-nwfilter-0.10.2.6-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-config-nwfilter-0.10.2.7-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-interface-0.10.2.4-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-interface-0.10.2.6-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-interface-0.10.2.7-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-libxl-0.10.2.4-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-libxl-0.10.2.6-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-libxl-0.10.2.7-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-lxc-0.10.2.4-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-lxc-0.10.2.6-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-lxc-0.10.2.7-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-network-0.10.2.4-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-network-0.10.2.6-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-network-0.10.2.7-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-nodedev-0.10.2.4-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-nodedev-0.10.2.6-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-nodedev-0.10.2.7-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-nwfilter-0.10.2.4-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-nwfilter-0.10.2.6-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-nwfilter-0.10.2.7-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-qemu-0.10.2.4-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-qemu-0.10.2.6-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-qemu-0.10.2.7-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-secret-0.10.2.4-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-secret-0.10.2.6-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-secret-0.10.2.7-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-storage-0.10.2.4-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-storage-0.10.2.6-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-storage-0.10.2.7-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-xen-0.10.2.4-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-xen-0.10.2.6-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-driver-xen-0.10.2.7-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-kvm-0.10.2.4-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-kvm-0.10.2.6-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-kvm-0.10.2.7-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-lxc-0.10.2.4-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-lxc-0.10.2.6-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-lxc-0.10.2.7-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-xen-0.10.2.4-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-xen-0.10.2.6-5.el6.centos.alt.x86_64.rpm

libvirt-daemon-xen-0.10.2.7-5.el6.centos.alt.x86_64.rpm

libvirt-devel-0.10.2.4-5.el6.centos.alt.x86_64.rpm

libvirt-devel-0.10.2.6-5.el6.centos.alt.x86_64.rpm

libvirt-devel-0.10.2.7-5.el6.centos.alt.x86_64.rpm

libvirt-docs-0.10.2.4-5.el6.centos.alt.x86_64.rpm

libvirt-docs-0.10.2.6-5.el6.centos.alt.x86_64.rpm

libvirt-docs-0.10.2.7-5.el6.centos.alt.x86_64.rpm

libvirt-lock-sanlock-0.10.2.4-5.el6.centos.alt.x86_64.rpm

libvirt-lock-sanlock-0.10.2.6-5.el6.centos.alt.x86_64.rpm

libvirt-lock-sanlock-0.10.2.7-5.el6.centos.alt.x86_64.rpm

libvirt-python-0.10.2.4-5.el6.centos.alt.x86_64.rpm

libvirt-python-0.10.2.6-5.el6.centos.alt.x86_64.rpm

libvirt-python-0.10.2.7-5.el6.centos.alt.x86_64.rpm

perf-3.4.46-8.el6.centos.alt.x86_64.rpm

perf-3.4.50-8.el6.centos.alt.x86_64.rpm

perf-3.4.53-8.el6.centos.alt.x86_64.rpm

perf-3.4.54-8.el6.centos.alt.x86_64.rpm

perf-3.4.59-8.el6.centos.alt.x86_64.rpm

perf-3.4.61-9.el6.centos.alt.x86_64.rpm

python-virtinst-0.600.0-16.el6.centos.alt.noarch.rpm

repodata

seabios-1.7.1-1.el6.centos.alt.x86_64.rpm

seabios-bin-1.7.1-1.el6.centos.alt.noarch.rpm

xen-4.2.2-22.el6.centos.alt.x86_64.rpm

xen-4.2.2-23.el6.centos.alt.x86_64.rpm

xen-4.2.3-23.el6.centos.alt.x86_64.rpm

xen-devel-4.2.2-22.el6.centos.alt.x86_64.rpm

xen-devel-4.2.2-23.el6.centos.alt.x86_64.rpm

xen-devel-4.2.3-23.el6.centos.alt.x86_64.rpm

xen-doc-4.2.2-22.el6.centos.alt.x86_64.rpm

xen-doc-4.2.2-23.el6.centos.alt.x86_64.rpm

xen-doc-4.2.3-23.el6.centos.alt.x86_64.rpm

xen-hypervisor-4.2.2-22.el6.centos.alt.x86_64.rpm

xen-hypervisor-4.2.2-23.el6.centos.alt.x86_64.rpm

xen-hypervisor-4.2.3-23.el6.centos.alt.x86_64.rpm

xen-libs-4.2.2-22.el6.centos.alt.x86_64.rpm

xen-libs-4.2.2-23.el6.centos.alt.x86_64.rpm

xen-libs-4.2.3-23.el6.centos.alt.x86_64.rpm

xen-licenses-4.2.2-22.el6.centos.alt.x86_64.rpm

xen-licenses-4.2.2-23.el6.centos.alt.x86_64.rpm

xen-licenses-4.2.3-23.el6.centos.alt.x86_64.rpm

xen-ocaml-4.2.2-22.el6.centos.alt.x86_64.rpm

xen-ocaml-4.2.2-23.el6.centos.alt.x86_64.rpm

xen-ocaml-4.2.3-23.el6.centos.alt.x86_64.rpm

xen-ocaml-devel-4.2.2-22.el6.centos.alt.x86_64.rpm

xen-ocaml-devel-4.2.2-23.el6.centos.alt.x86_64.rpm

xen-ocaml-devel-4.2.3-23.el6.centos.alt.x86_64.rpm

xen-runtime-4.2.2-22.el6.centos.alt.x86_64.rpm

xen-runtime-4.2.2-23.el6.centos.alt.x86_64.rpm

xen-runtime-4.2.3-23.el6.centos.alt.x86_64.rpm


安装rpm

# yum install kernel-xenxen xen-runtime xen-libs

# ll /boot | grepxen

-rw-r--r--  1 root root  806912 Sep 12 01:46 xen-4.2.3-23.el6.gz

lrwxrwxrwx  1 root root       19 Nov 17 10:09 xen-4.2.gz ->xen-4.2.3-23.el6.gz

lrwxrwxrwx  1 root root       19 Nov 17 10:09 xen.gz ->xen-4.2.3-23.el6.gz

-rw-r--r--  1 root root 14608999 Sep 12 01:46xen-syms-4.2.3-23.el6


修改内核

先让cpu支持硬件虚拟化,可以启用更多功能。

212650363.jpg

# vim /etc/grub.conf

default=0

timeout=5

splashimage=(hd0,0)/grub/splash.xpm.gz

hiddenmenu

title Red Hat EnterpriseLinux Server (3.4.61-9.el6.centos.alt.x86_64)

root(hd0,0)

      kernel /xen.gz dom0_mem=500M cpufreq=xen dom0_max_vcpus=2 dom0_vcpus_pin

module /vmlinuz-3.4.61-9.el6.centos.alt.x86_64ro root=/dev/mapper/vg0-root rd_NO_LUKS rd_NO_DM LANG=en_US.UTF-8rd_LVM_LV=vg0/swap rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=autord_LVM_LV=vg0/root  KEYBOARDTYPE=pc KEYTABLE=usrhgb crashkernel=auto quiet rhgb quiet

module /initramfs-3.4.61-9.el6.centos.alt.x86_64.img

title Red Hat EnterpriseLinux (2.6.32-358.el6.x86_64)

       root (hd0,0)

       kernel /vmlinuz-2.6.32-358.el6.x86_64ro root=/dev/mapper/vg0-root rd_NO_LUKS rd_NO_DM LANG=en_US.UTF-8rd_LVM_LV=vg0/swap rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=autord_LVM_LV=vg0/root  KEYBOARDTYPE=pcKEYTABLE=us rhgb crashkernel=auto quiet rhgb quiet

       initrd/initramfs-2.6.32-358.el6.x86_64.img

蓝颜色的部分没有装xen包之前是不存在的。

# reboot

# ls /proc/xen

capabilities  privcmd xenbus

如果capabilities存在,说明xen运行正常。

# cat/proc/xen/capabilities

control_d

# yum -yinstall libvirt

# service libvirtdstart

# brctl show

管理桥

# virsh

也可以管理桥

# cd/etc/sysconfig/network-scripts/

# cp ifcfg-eth0ifcfg-br0

# vim ifcfg-br0

DEVICE=br0

TYPE=Ethernet

ONBOOT=yes

BOOTPROTO=static

TYPE=Bridge

IPADDR=192.168.137.251

GATEWAY=192.168.137.1

# vim ifcfg-eth0

DEVICE=eth0

TYPE=Ethernet

ONBOOT=yes

NM_CONTROLLED=yes

BRIDGE=br0

# ifconfig

br0       Link encap:Ethernet  HWaddr 00:0C:29:20:C7:A4  

         inet addr:192.168.137.251  Bcast:192.168.137.255  Mask:255.255.255.0

         inet6 addr:fe80::20c:29ff:fe20:c7a4/64 Scope:Link

         UP BROADCAST RUNNING MULTICAST  MTU:1500 Metric:1

         RX packets:240 errors:0 dropped:0overruns:0 frame:0

         TX packets:192 errors:0 dropped:0overruns:0 carrier:0

         collisions:0 txqueuelen:0

         RX bytes:30495 (29.7 KiB)  TX bytes:23112 (22.5 KiB)


eth0      Link encap:Ethernet  HWaddr 00:0C:29:20:C7:A4  

         inet6 addr:fe80::20c:29ff:fe20:c7a4/64 Scope:Link

         UP BROADCAST RUNNING MULTICAST  MTU:1500 Metric:1

         RX packets:10063 errors:0 dropped:0overruns:0 frame:0

         TX packets:5889 errors:0 dropped:0overruns:0 carrier:0

         collisions:0 txqueuelen:1000

         RX bytes:7984544 (7.6 MiB)  TX bytes:708451 (691.8 KiB)


lo        Link encap:Local Loopback  

         inet addr:127.0.0.1  Mask:255.0.0.0

         inet6 addr: ::1/128 Scope:Host

         UP LOOPBACK RUNNING  MTU:16436 Metric:1

         RX packets:0 errors:0 dropped:0overruns:0 frame:0

         TX packets:0 errors:0 dropped:0overruns:0 carrier:0

         collisions:0 txqueuelen:0

         RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)


virbr0    Link encap:Ethernet  HWaddr 6A:C7:DD:42:05:93  

         inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0

         UP BROADCAST MULTICAST  MTU:1500 Metric:1

         RX packets:0 errors:0 dropped:0overruns:0 frame:0

         TX packets:0 errors:0 dropped:0overruns:0 carrier:0

         collisions:0 txqueuelen:0

         RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

好了,桥建好了,我们就可以通过桥创建一个虚拟机,来让虚拟机链接到dom0上了。

# yum -y install virt-manager  

装xen的时候,virt-manager 需要单独装,装kvm时,一个virtualization 包组就包含了这个工具。

# virt-manager

Traceback (mostrecent call last):

 File"/usr/share/virt-manager/virt-manager.py", line 383, in<module>

   main()

 File"/usr/share/virt-manager/virt-manager.py", line 248, in main

   cli.setup_i18n(gettext_app, gettext_dir)

 File"/usr/share/virt-manager/virtManager/cli.py", line 90, in setup_i18n

   locale.setlocale(locale.LC_ALL, '')

 File"/usr/lib64/python2.6/locale.py", line 513, in setlocale

   return _setlocale(category, locale)

locale.Error:unsupported locale setting

解决办法

# export LC_ALL=C

LC_ALL=C是为了去除所有本地化的设置,让命令能正确执行。

# virt-manager  //只有在xend服务启动后,在能运行。

212553683.jpg


好了,下面就可以新建虚拟机了,只需要注意选择安装方式和内存分配合理就可以了。

装好一个,可以克隆另一个。


不使用图形界面启动虚拟机

方法一:

# cd/etc/xen

# vimtest

Kernel="/tmp/vmlinuz-2.6.18-308.el5xen"   //虚拟机启动后/boot目录下的文件,需要虚拟机安装完成后去复制

Ramdisk="/tmp/initrd-2.6.18-308.el5xen.img"  //虚拟机启动后/boot目录下的文件,需要虚拟机安装完成后去复制

Name="test"

Memory=512

Vcpus=2

Root="/dev/vol0/rootro"

Extra="rhgbquiet"

Vif=['bridge=xenbr0']

Disk=['file:/var/lib/libvirt/images/test.img,xvda,w']

# xmcreate test

# xm list

# xm console test   //启动过程,推出"ctrl+]"


方法二:

# vimtest2

Bootloader="/usr/bin/pygrub"  //不需要用到引导内核,直接使用虚拟机自己的内核

Name="test2"

Memory=512

Vcpus=2

Vif=['bridge=xenbr0']

Disk=['file:/var/lib/libvirt/images/test.img,xvda,w']

On_reboot='restart'

On_crash='destroy'

Vfb=['vnc=1,vnclisten=0.0.0.0,vncpasswd=vpass'] #定义帧缓冲

# xm create -c test2  //-c 立即链接到控制台


domu中按装运行Redhat 5要使用images/etc/xen目录下的专用内核,redhat5没有收录xen的模块

                        kvm虚拟化

Kvm只能在64位系统上运行

一、检验cpu是否支持硬件虚拟化

# grep -o -E 'svm|vmx'/proc/cpuinfo

Svm AMD的cpu

Vmx intel的cpu

二、加载两个模块

如果是intelcpu

# modprobe kvm

# modprobe kvm_intel

如果是amdcpu

# modprobe kvm

# modprobe kvm_amd

# lsmod | grep kvm

kvm_intel    53484 0

kvm     316506 1 kvm_intel

# ls /dev | grep kvm

kvm #虚拟的设备文件,kvmapi,对虚拟机的操作都要通过这个接口

此时,说明系统已经可以虚拟化了。


kvm跟qemu结合起来才能更好地完成虚拟化

# yum -y groupinstall“Virtualization”

# yum groupinfo"Virtualization"

Loaded plugins:fastestmirror

Setting up GroupProcess

Loading mirrorspeeds from cached hostfile


Group:Virtualization

Description:Provides an environment for hosting virtualized guests.

Mandatory Packages:

qemu-kvm

Default Packages:

hypervkvpd

Optional Packages:

qemu-guest-agent

qemu-kvm-tools

# yum -y groupinstall“Virtualization Platform” “Virtualization Client”

VirtualizationPlatform 相关库

# yum groupinfo"Virtualization Platform"

Loaded plugins:fastestmirror

Setting up GroupProcess

Loading mirrorspeeds from cached hostfile


Group:Virtualization Platform

Description:Provides an interface for accessing and controlling virtualized guests andcontainers.

Mandatory Packages:

libvirt

libvirt-client

virt-who

Optional Packages:

fence-virtd-libvirt

fence-virtd-multicast

fence-virtd-serial

libvirt-cim

libvirt-java

libvirt-snmp

perl-Sys-Virt

# yum groupinfo"Virtualization Client"

Loaded plugins:fastestmirror

Setting up GroupProcess

Loading mirrorspeeds from cached hostfile


Group:Virtualization Client

Description:Clients for installing and managing virtualization instances.

Mandatory Packages:

python-virtinst

virt-manager

virt-viewer

Default Packages:

virt-top

# ls/usr/libexec/qemu-kvm

/usr/libexec/qemu-kvm # 这是一个命令

# ln -sv/usr/libexec/qemu-kvm /usr/bin/qemu

# qemu-cpu ? 查看可以模拟哪种类型的cpu


# qemu -M ? 查看可以模拟的架构

Supported machines are:

pc   RHEL 6.4.0 PC (alias of rhel6.4.0)

rhel6.4.0 RHEL 6.4.0 PC (default)

rhel6.3.0 RHEL 6.3.0 PC

rhel6.2.0 RHEL 6.2.0 PC

rhel6.1.0 RHEL 6.1.0 PC

rhel6.0.0 RHEL 6.0.0 PC

rhel5.5.0 RHEL 5.5.0 PC

rhel5.4.4 RHEL 5.4.4 PC

rhel5.4.0 RHEL 5.4.0 PC


qemu命令可以创建,启动,安装虚拟机

# qemu -img 创建映像文件

# service libvirtd start

# ifconfig

Eth0

Lo

Virbr0

# yum -y installbridge-utils

# virsh iface-bridge eth0 br0

#ifconfig

Br0

Eth0

Lo

Virbr0


遇到报错,cant  find eth0 or  br0 already exsit只了到错误不要急,解决办法如下:

重新编写eth0网卡信息,将br0网卡备份,然后再执行命令virsh iface-bridge eth0 br0 

问题解决。

接下来装操作系统


错误问题解决:

利用Xshell安装虚拟机的时候,很多按键都会错乱,这时,我们可以选择使用puttyXming两个软件结合使用来完成安装。Putty+Xming=Xshell+Xmanager

Windows上安装puttyXming


# virt-manager

Traceback (most recentcall last):

File"/usr/share/virt-manager/virt-manager.py", line 383, in<module>

main()

File"/usr/share/virt-manager/virt-manager.py", line 286, in main

raise gtk_error

RuntimeError: could notopen display


223733182.jpg


点击Xming启动

配置putty

223821279.jpg



223900117.jpg


# virt-manager

process 3554: D-Buslibrary appears to be incorrectly set up; failed to read machine uuid: Failedto open "/var/lib/dbus/machine-id": No such file or directory

See the manual page fordbus-uuidgen to correct this issue.

D-Bus not built with -rdynamic so unable toprint a backtrace

Aborted

解决方案

# mkdir /var/lib/dbus

# dbus-uuidgen > /var/lib/dbus/machine-id

# virt-manager


当出现乱码

安装包组

# yum -y groupinstall “ X Window System”

# virt-manager


223918180.jpg


虚拟机装完后的镜像文件 /var/lib/libvirt/images/


------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

命令行下安装虚拟机

#mkdir -pv /VMs/images

#chown -R root:kvm /dev/kvm

#virt-install \

--connect qemu:///system\

--virt-type kvm \

--name centos6 \

--ram 512 \

--vcpus 2 \

--network bridge=br0 \

--diskpath=/VMs/images/centos6.img,size=120,sparse \

--locationhttp://192.168.137.111/cobbler/ks_mirror/centos-6.4-x86_64/ \

--extra-args"ks=http://192.168.137.111/centos6.x86_64.cfg" \

--os-variant rhel6 \

--force


你可能感兴趣的:(虚拟化技术)