Chinaunix首页 | 论坛 | 博客
  • 博客访问: 111391
  • 博文数量: 29
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 240
  • 用 户 组: 普通用户
  • 注册时间: 2014-07-11 15:42
个人简介

多少人爱你青春欢畅的时辰, 爱你的美丽假意和真心, 只有一个人爱你那朝圣者的灵魂, 爱你衰老了的连上痛苦的皱纹.

文章分类

全部博文(29)

文章存档

2018年(1)

2015年(2)

2014年(26)

我的朋友

分类: 虚拟化

2014-07-16 11:26:01


1. Setup Network:


# vi /etc/resolv.conf

nameserver 202.96.209.133


root@centos]# vi /etc/sysconfig/network

GATEWAY=10.16.244.1

HOSTNAME=centosKVM0X #(设置本机的主机名,这里设置的主机名要和/etc/hosts中设置的主机名对应)


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

DEVICE=emX

BOOTPROTO=static

BROADCAST=10.16.244.127

IPADDR=10.16.244.81

IPV6_AUTOCONF=no

NETMASK=255.255.255.128

NETWORK=10.16.244.127

ONBOOT=yes

HWADDR=00:07:E9:05:E8:B4 #对应的网卡物理地址

[root@CentOSKVM01 ~]#  service network restart

2. 编译内核


Downloda tool:

Keep Cache自动保存yum install命令下载的包:

#vim /etc/yum.conf

更改参数: keepcache=1

更改保存路径: cachedir=/etc/updates


[root@CentosKVM02 ~]# mkdir kvm_demo

[root@CentosKVM02 ~]# cd kvm_demo/

git clone git://git.kernel.org/pub/scm/virt/kvm/kvm.git

wget

wget


Reference webpage:

()



cd kvm

[root@CentOSKVM01 kvm_demo]# make menuconfig 


 



—> save 

—> .config

[root@CentOSKVM01 kvm]# make localmodconfig 

错误:

可以忽略内核power_meter错误

参考文献:


[root@CentosKVM02 kvm]# vim .config #查看编译后的内核

HOSTLD  scripts/kconfig/conf

using config: ‘.config'


CONFIG_HAVE_KVM=y

CONFIG_HAVE_KVM_IRQCHIP=y

CONFIG_HAVE_KVM_EVENTFD=y

CONFIG_KVM_APIC_ARCHITECTURE=y

CONFIG_KVM_MMIO=y

CONFIG_KVM_ASYNC_PF=y

CONFIG_HAVE_KVM_MSI=y

CONFIG_VIRTUALIZATION=y

CONFIG_KVM=m

CONFIG_KVM_INTEL=m

# CONFIG_KVM_AMD is not set

CONFIG_KVM_MMU_AUDIT=y


[root@CentOSKVM01 kvm_demo]# make vmlinux -j 20

[root@CentOSKVM01 kvm_demo]# make bzImage

[root@CentOSKVM01 kvm_demo]# make modules 编译内核模块

[root@CentOSKVM01 kvm_demo]# make modules_install 

安装成功以后在末尾会显示 DEPMOD 3.15.0-rc4+ 

检查模块是否安装成功:ls -l /lib/modules/3.15.0-rc4_/kernel/

[root@CentOSKVM01 kvm_demo]# make install


错误:

虚拟机安装make install时遇到can’t find vmware_bollon错误

解决:切换至实体机测试


查看/启动KVM_Intel内核模块

[root@CentOSKVM01 ~]# modprobe kvm

[root@CentOSKVM01 ~]# modprobe kvm_intel

[root@CentOSKVM01 ~]# modprobe kvm_amd

[root@CentOSKVM01 ~]# lsmod | grep kvm

kvm_intel             140119  0 

kvm                   447823  1 kvm_intel

kvm_amd 132320  1 kvm_amd


检查/dev/kvm 此权限表示正常

[root@CentOSKVM01 ~]# ls -l /dev/kvm

crw-rw----+ 1 root root 10, 232 May 14 21:21 /dev/kvm



3. 安装 qemu-kvm


[root@CentOSKVM01 kvm_demo]# git clone git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git qemu-kvm.git

yum install qemu-kvm

[root@CentOSKVM01 kvm_demo]# cd qemu-kvm.git

[root@CentOSKVM01 kvm_demo]# pwd

[root@CentOSKVM01 qemu-kvm.git]# ./configure —help

[root@CentOSKVM01 qemu-kvm.git]# ./configure


错误:

-bash: ./configure: Permission denied

解决:在当前目录下输入:chmod +x ./configure


KVM device assig.  yes, 此选项未找到

未处理



[root@CentOSKVM01 qemu-kvm.git]# make -j 20

[root@CentOSKVM01 qemu-kvm.git]# make install | tee make-install.log


查看被安装的情况

[root@CentOSKVM01 qemu-kvm.git]# which qemu-system-x86_64

/usr/local/bin/qemu-system-x86_64


[root@CentOSKVM01 qemu-kvm.git]# which qemu-img

/usr/local/bin/qemu-img

[root@CentOSKVM01 ~]# ls /usr/local/share/qemu

bamboo.dtb  kvmvapic.bin   openbios-ppc      palcode-clipper           ppc_rom.bin       pxe-ne2k_pci.rom  pxe-virtio.rom  sgabios.bin     vgabios.bin         vgabios-stdvga.bin

bios.bin    linuxboot.bin  openbios-sparc32  petalogix-ml605.dtb       pxe-e1000.rom     pxe-pcnet.rom     qemu-icon.bmp   slof.bin        vgabios-cirrus.bin  vgabios-vmware.bin

keymaps     multiboot.bin  openbios-sparc64  petalogix-s3adsp1800.dtb  pxe-eepro100.rom  pxe-rtl8139.rom   s390-zipl.rom   spapr-rtas.bin  vgabios-qxl.bin


4. 创建客户机


[root@CentOSKVM01 ~]#  cd ./kvm_demo


生成一个镜像文件

[root@CentOSKVM01 kvm_demo]# dd if=/dev/zero of=Centos.img bs=1M count=8192

8192+0 records in

8192+0 records out


8589934592 bytes (8.6 GB) copied, 6.97503 s, 1.2 GB/s

[root@CentOSKVM01 kvm_demo]# qemu-img create -f qcow2 win2003.img 16G


[root@CentOSKVM01 ~]# qemu-system-x86_64 -m 4096 -smp 4 -boot order=cd -hda /root/kvm_demo/Centos.img -cdrom /root/kvm_demo/DFSAST-OS6-Entry-V4.iso


VNC server running on `::1:5900’


[root@CentOSKVM01 ~]#  yum install tigervnc-server vnc


[root@CentOSKVM01 ~]# vncviewer :5900 主服务器需要安装Desktop界面,输入后


5. 配置网卡


查看:

[root@CentOSKVM01 kvm_demo]# qemu-system-x86_64 -net nic,model=?

qemu: Supported NIC models: ne2k_pci,i82551,i82557b,i82559er,rtl8139,e1000,pcnet,virtio


[root@CentOSKVM01 kvm_demo]# lspci | grep Eth

01:00.0 Ethernet controller: Broadcom Corporation NetXtreme BCM5720 Gigabit Ethernet PCIe

01:00.1 Ethernet controller: Broadcom Corporation NetXtreme BCM5720 Gigabit Ethernet PCIe

02:00.0 Ethernet controller: Broadcom Corporation NetXtreme BCM5720 Gigabit Ethernet PCIe

02:00.1 Ethernet controller: Broadcom Corporation NetXtreme BCM5720 Gigabit Ethernet PCIe


5.1 在KVM Server上先装Bridge

[root@CentOSKVM01 ~]#  yum install bridge-utils tunctl

[root@CentOSKVM01 ~]#  lsmod |grep tun

如果没有加载模块 modprobe tun

查看权限读写

[root@CentOSKVM01 kvm_demo]# ll /dev/net/tun

crw-rw-rw-. 1 root root 10, 200 May 15 00:38 /dev/net/tun


[root@CentOSKVM01 kvm_demo]# brctl addbr br0 #添加BR0这个bridge

[root@CentOSKVM01 kvm_demo]# brctl addif br0 eth0 #讲br0与em1绑定起来

interface eth0 does not exist!


[root@CentOSKVM01 kvm_demo]# brctl addif br0 em1 #将br0与em1绑定起来

[root@CentOSKVM01 kvm_demo]# brctl stp br0 on #br0设置为启动stp协议

[root@CentOSKVM01 kvm_demo]# ifconfig em1 0   #将em1的IP设置为0

[root@CentOSKVM01 kvm_demo]# dhclient br0 #将br0的网络配置好

[root@CentOSKVM01 ~]# route #查看路由表配置

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

10.16.244.0     *               255.255.255.128 U     0      0        0 br0


default         10.16.244.1     0.0.0.0         UG    0      0        0 br0


5.1.1 Brctl工具命令介绍

删除创建的br0需要先停止br0

1. ifconfig br0 down

2. brctl delif br0 em1   把 em1从br0的捆绑中删除

3. brctl delbr br0 把br0删掉

参考网站:


5.2 创建脚本

两个脚本 qemu-ifup/Down 穿件后放至/etc/qemu-ifup, /etc/qemu-ifdown

注意复制脚本的时候系统会自动删除#!/bin/bash

http://blog.csdn.net/cybertan/article/details/8160102

#!/bin/bash

#This is a qemu-ifup script for bridging.

#You can use it when starting a KVM guest with bridge mode network.

 

#set your bridge name

switch=br0

 

if [ -n "$1" ]; then

#create a TAP interface; qemu will handle it automatically.

#tunctl -u $(whoami) -t $1

 

#start up the TAP interface

ip link set $1 up

sleep 1

#add TAP interface to the bridge

brctl addif ${switch} $1

exit 0

else

echo “Error: no interface specified”

exit 1

fi





#!/bin/bash

#This is a qemu-ifdown script for bridging.

#You can use it when starting a KVM guest with bridge mode network.

#Don’t use this script in most cases; QEMU will handle it automatically.

 

#set your bridge name

switch=br0

 

if [ -n "$1" ]; then

# Delete the specified interfacename

tunctl -d $1

#release TAP interface from bridge

brctl delif ${switch} $1

#shutdown the TAP interface

ip link set $1 down

exit 0

else

echo “Error: no interface specified”

exit 1

fi


5.3 运行虚机并查看


用qemu-kvm命令启动bridge模式的网络。

在宿主机中,用命令行 启动客户机和检查bridge的状态,如下:

[root@jay-linux kvm_demo]# qemu-system-x86_64 rhel6u3.img -smp 2 -m 1024 -net nic -net tap,ifname=tap1,script=/etc/qemu-ifup,downscript=no -vnc :0 -daemonize  //经过命令没问题

[root@jay-linux kvm_demo]# vncviewer :0 连接到服务器进行查看


[root@CentOSKVM01 ~]#  brctl show

bridge name bridge id STP enabled interfaces

br0 8000.c81f66b959ea yes em1


tap1

[root@CentOSKVM01 ~]# ls /sys/devices/virtual/net/

br0  lo  tap1


由上面信息可知,创建客户机后,添加了一个名为tap1的TAP虚拟网络设备,它被绑定在br0这个bridge上。查看到的三个虚拟网络设备依次为:网络回路设备lo(就是一般IP为127.0.0.1的设备)、前面建立好的bridge设备br0、给客户机提供网络的TAP设备tap1。


记得需要关闭 KVM服务器的防火墙,否则虚拟机无法获取IP 地址

service iptables stop

 



阅读(1004) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:KVM virtualize multiNIC bridge sloved

给主人留下些什么吧!~~