虚拟化技术基础原理
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了虚拟化技术基础原理相关的知识,希望对你有一定的参考价值。
程序局限性原因:
空间局限性
时间局限性
IO设备的部分:
设备控制器和设备本身
控制器:集成在主板上的一块芯片或一组芯片
驱动程序:通常应该由设备生产商:位于内核中
每个控制器都有少量的用于通信的寄存器,每个寄存器表现为一个I/O端口;
所有的寄存器组合成为设备的IO地址空间;
实现输入、输出:
三种方式:
1、轮询:忙等待
2、中断:
内核处理中断分为两步:
中断上半部、中断的下半部
3、DMA:
OS:
cpu:时间片,time slice
memory:虚拟地址空间
I/O:文件
进程
资源集
cpu事件
memory:抽象,虚拟地址空间(32bits:4G)
I/O:打开的多个文件,fd(file descriptor)
正常文件
设备文件
管道文件
进程:task
cpu虚拟化:
模拟:emulation
虚拟:virtulization
完全虚拟化(full-virtulization)
BT:二进制翻译(软件)
HVM:硬件辅助的虚拟化(硬件)
半虚拟化:
Memory:
进程:现行地址空间
内核:物理地址空间
MMU Virtulization
Inter:EPT,Extended Page Table
AMD:NTP,Nested Page Table
TLB virtulization
tagged TLB
I/O:
外存:
硬盘、光盘、U盘
网络设备:
网卡
显示设备:
VGA:frame buffer机制
键盘鼠标:
ps/2,usb
I/O虚拟化的方式:
模拟:完全使用软件来模拟真实硬件
半虚拟化:
IO-through:IO透传
Inter:VT-d
基于北桥的硬件辅助的虚拟化技术:
两种实现方式:
Type-I:
xen,vmware ESX/ESXi
Type-II:
kvm,vmware,workstation,virtualbox
Inter硬件辅助的虚拟化:
CPU:vt-x,EPT,tagged-TLB
IO/CPU:vt-d,IOV,VMDq
第一类:跟处理器相关:vt-x
第二类:跟芯片相关:vt-d
第三类:跟IO相关:VMDq和SR-IOV
QEMU,virtio
虚拟化技术的分类
模拟:著名的模拟器,PearPC,Bochs,QEMU
完全虚拟化:也称为native virtulization
两种加速方式:
BT
HVM
VMware Workstation,VMware Server,Parallels Desktop,KVM,Xen(HVM)
半虚拟化:para-virtualization
xen,uml(user-mod linux)
OS级别的虚拟化:
OpenVZ,lxc
Solaris Contaniners
FreeBSD jails
库虚拟化:
wine,
应用程序虚拟化:
jvm
虚拟化网络:
nat mode
bridge mode
routed mode
isolation mode
使用brctl的配置过程:
# brctl add br0
# brctl stp br0 on
# ifconfig eth0 0 up
# brctl addif br0 eth0
# ifconfig br0 IP/NETMASK up
# route add default gw GW
TUN与TAP
在计算机网络中,TUN与TAP是操作系统内核中的虚拟网络设备,不同于普通靠硬件网络办卡实现的设备,这些虚拟的网络设备全部用软件实现,并向运行于操作系统上的软件提供与硬件的网络设备完全相同的功能;
TAP等同于一个以太网设备,它操作第二层数据包如以太网数据帧,TUN模拟了网络层设备,操作第三层数据包如IP数据包。
操作系统通过TUN/TAP设备向绑定该设备的用户空间的程序发送数据,反之,用户空间的程序也可以像操作硬件的网络设备那样,通过TUN/TAP设备发送数据,在后种情况下,TUN/TAP设备向操作系统的网络栈投递(或"注入")数据包,从而模拟从外部接受数据的过程。
[[email protected] ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:11:21:56
inet addr:192.168.10.6 Bcast:192.168.10.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe11:2156/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:141 errors:0 dropped:0 overruns:0 frame:0
TX packets:74 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:14934 (14.5 KiB) TX bytes:9717 (9.4 KiB)
eth1 Link encap:Ethernet HWaddr 00:0C:29:11:21:60
inet addr:192.168.190.128 Bcast:192.168.190.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe11:2160/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:193 errors:0 dropped:0 overruns:0 frame:0
TX packets:30 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:16345 (15.9 KiB) TX bytes:3153 (3.0 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:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
桥不支持NetworkManger管理,需要关闭NetworkManger启动[[email protected] ~]# chkconfig --list NetworkManager
桥使用network管理
[[email protected] ~]# chkconfig --list network
network 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
[[email protected] ~]# yum -y install bridge-utils
[[email protected] ~]# rpm -ql bridge-utils
/usr/sbin/brctl
/usr/share/doc/bridge-utils-1.2
/usr/share/doc/bridge-utils-1.2/AUTHORS
/usr/share/doc/bridge-utils-1.2/COPYING
/usr/share/doc/bridge-utils-1.2/FAQ
/usr/share/doc/bridge-utils-1.2/HOWTO
/usr/share/man/man8/brctl.8.gz
[[email protected] ~]# cd /etc/sysconfig/network-scripts/
[[email protected] network-scripts]# cp ifcfg-eth0 ifcfg-br0
关闭NetworkManger服务进行管理:NM_CONTROLLED=no
[[email protected] network-scripts]# vim ifcfg-br0
DEVICE=br0
TYPE=Bridge
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=none
IPADDR=192.168.10.6
NETMASK=255.255.255.0
[[email protected] network-scripts]# vim ifcfg-eth0
DEVICE=eth0
HWADDR=00:0C:29:11:21:56
TYPE=Ethernet
UUID=f343369c-4aa9-4975-81b3-3f38f4c56ef0
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=none
BRIDGE=br0
[[email protected] network-scripts]# service network restart
正在关闭接口 eth0: bridge br0 does not exist!
[确定]
正在关闭接口 eth1: [确定]
关闭环回接口: [确定]
弹出环回接口: [确定]
弹出界面 eth0: [确定]
弹出界面 eth1:
正在决定 eth1 的 IP 信息...完成。
[确定]
弹出界面 br0: Determining if ip address 192.168.10.6 is already in use for device br0...
[确定]
[[email protected] network-scripts]# ifconfig
br0 Link encap:Ethernet HWaddr 00:0C:29:11:21:56
inet addr:192.168.10.6 Bcast:192.168.10.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe11:2156/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:21 errors:0 dropped:0 overruns:0 frame:0
TX packets:20 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2174 (2.1 KiB) TX bytes:2264 (2.2 KiB)
eth0 Link encap:Ethernet HWaddr 00:0C:29:11:21:56
inet6 addr: fe80::20c:29ff:fe11:2156/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1353 errors:0 dropped:0 overruns:0 frame:0
TX packets:1217 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:105072 (102.6 KiB) TX bytes:120035 (117.2 KiB)
eth1 Link encap:Ethernet HWaddr 00:0C:29:11:21:60
inet addr:192.168.190.128 Bcast:192.168.190.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe11:2160/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:19201 errors:0 dropped:0 overruns:0 frame:0
TX packets:8181 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:27802761 (26.5 MiB) TX bytes:449250 (438.7 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:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
[[email protected] network-scripts]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000c29112156 no eth0
[[email protected] network-scripts]# brctl --help
Usage: brctl [commands]
commands:
addbr <bridge> add bridge
delbr <bridge> delete bridge
addif <bridge> <device> add interface to bridge
delif <bridge> <device> delete interface from bridge
setageing <bridge> <time> set ageing time
setbridgeprio <bridge> <prio> set bridge priority
setfd <bridge> <time> set bridge forward delay
sethello <bridge> <time> set hello time
setmaxage <bridge> <time> set max message age
sethashel <bridge> <int> set hash elasticity
sethashmax <bridge> <int> set hash max
setmclmc <bridge> <int> set multicast last member count
setmcrouter <bridge> <int> set multicast router
setmcsnoop <bridge> <int> set multicast snooping
setmcsqc <bridge> <int> set multicast startup query count
setmclmi <bridge> <time> set multicast last member interval
setmcmi <bridge> <time> set multicast membership interval
setmcqpi <bridge> <time> set multicast querier interval
setmcqi <bridge> <time> set multicast query interval
setmcqri <bridge> <time> set multicast query response interval
setmcqri <bridge> <time> set multicast startup query interval
setpathcost <bridge> <port> <cost> set path cost
setportprio <bridge> <port> <prio> set port priority
setportmcrouter <bridge> <port> <int> set port multicast router
show [ <bridge> ] show a list of bridges
showmacs <bridge> show a list of mac addrs
showstp <bridge> show bridge stp info
stp <bridge> {on|off} turn stp on/off
[[email protected] network-scripts]# brctl stp br0 on
[[email protected] network-scripts]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000c29112156 yes eth0
命令创建桥:
[[email protected] ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:E8:20:12
inet addr:192.168.10.7 Bcast:192.168.10.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fee8:2012/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:27 errors:0 dropped:0 overruns:0 frame:0
TX packets:40 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4781 (4.6 KiB) TX bytes:5365 (5.2 KiB)
eth1 Link encap:Ethernet HWaddr 00:0C:29:E8:20:1C
inet addr:192.168.190.129 Bcast:192.168.190.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fee8:201c/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:40 errors:0 dropped:0 overruns:0 frame:0
TX packets:15 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3072 (3.0 KiB) TX bytes:1511 (1.4 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:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
[[email protected] ~]# chkconfig --list NetworkManager
[[email protected] ~]# chkconfig --list network
network 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
[[email protected] ~]# yum -y install bridge-utils
[[email protected] ~]# brctl --help
Usage: brctl [commands]
commands:
addbr <bridge> add bridge
delbr <bridge> delete bridge
addif <bridge> <device> add interface to bridge
delif <bridge> <device> delete interface from bridge
setageing <bridge> <time> set ageing time
setbridgeprio <bridge> <prio> set bridge priority
setfd <bridge> <time> set bridge forward delay
sethello <bridge> <time> set hello time
setmaxage <bridge> <time> set max message age
sethashel <bridge> <int> set hash elasticity
sethashmax <bridge> <int> set hash max
setmclmc <bridge> <int> set multicast last member count
setmcrouter <bridge> <int> set multicast router
setmcsnoop <bridge> <int> set multicast snooping
setmcsqc <bridge> <int> set multicast startup query count
setmclmi <bridge> <time> set multicast last member interval
setmcmi <bridge> <time> set multicast membership interval
setmcqpi <bridge> <time> set multicast querier interval
setmcqi <bridge> <time> set multicast query interval
setmcqri <bridge> <time> set multicast query response interval
setmcqri <bridge> <time> set multicast startup query interval
setpathcost <bridge> <port> <cost> set path cost
setportprio <bridge> <port> <prio> set port priority
setportmcrouter <bridge> <port> <int> set port multicast router
show [ <bridge> ] show a list of bridges
showmacs <bridge> show a list of mac addrs
showstp <bridge> show bridge stp info
stp <bridge> {on|off} turn stp on/off
[[email protected] ~]# brctl show
bridge name bridge id STP enabled interfaces
[[email protected] ~]# brctl addbr br0
[[email protected] ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:E8:20:12
inet addr:192.168.10.7 Bcast:192.168.10.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fee8:2012/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:557 errors:0 dropped:0 overruns:0 frame:0
TX packets:385 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:48970 (47.8 KiB) TX bytes:39748 (38.8 KiB)
eth1 Link encap:Ethernet HWaddr 00:0C:29:E8:20:1C
inet addr:192.168.190.129 Bcast:192.168.190.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fee8:201c/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:5053 errors:0 dropped:0 overruns:0 frame:0
TX packets:2694 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:7236029 (6.9 MiB) TX bytes:148485 (145.0 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:65536 Metric:1
RX packets:2 errors:0 dropped:0 overruns:0 frame:0
TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:200 (200.0 b) TX bytes:200 (200.0 b)
[[email protected] ~]# ifconfig eth0 0 up
[[email protected] ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:E8:20:12
inet6 addr: fe80::20c:29ff:fee8:2012/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:600 errors:0 dropped:0 overruns:0 frame:0
TX packets:404 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:52372 (51.1 KiB) TX bytes:41802 (40.8 KiB)
eth1 Link encap:Ethernet HWaddr 00:0C:29:E8:20:1C
inet addr:192.168.190.129 Bcast:192.168.190.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fee8:201c/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:5118 errors:0 dropped:0 overruns:0 frame:0
TX packets:2749 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:7247051 (6.9 MiB) TX bytes:156881 (153.2 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:65536 Metric:1
RX packets:2 errors:0 dropped:0 overruns:0 frame:0
TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:200 (200.0 b) TX bytes:200 (200.0 b)
[[email protected] ~]# brctl addif br0 eth0
[[email protected] ~]# ifconfig br0 192.168.10.7/24 up
[[email protected] ~]# route add default gw 192.168.10.254
[[email protected] ~]# ifconfig
br0 Link encap:Ethernet HWaddr 00:0C:29:E8:20:12
inet addr:192.168.10.7 Bcast:192.168.10.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fee8:2012/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:24 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1104 (1.0 KiB) TX bytes:468 (468.0 b)
eth0 Link encap:Ethernet HWaddr 00:0C:29:E8:20:12
inet6 addr: fe80::20c:29ff:fee8:2012/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:632 errors:0 dropped:0 overruns:0 frame:0
TX packets:410 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:54292 (53.0 KiB) TX bytes:42270 (41.2 KiB)
eth1 Link encap:Ethernet HWaddr 00:0C:29:E8:20:1C
inet addr:192.168.190.129 Bcast:192.168.190.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fee8:201c/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:5331 errors:0 dropped:0 overruns:0 frame:0
TX packets:2881 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:7263087 (6.9 MiB) TX bytes:168737 (164.7 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:65536 Metric:1
RX packets:2 errors:0 dropped:0 overruns:0 frame:0
TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:200 (200.0 b) TX bytes:200 (200.0 b)
以上是关于虚拟化技术基础原理的主要内容,如果未能解决你的问题,请参考以下文章