程序局限性原因:
空间局限性
时间局限性
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设备向操作系统的网络栈投递(或"注入")数据包,从而模拟从外部接受数据的过程。
[root@node1 ~]# 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启动[root@node1 ~]# chkconfig --list NetworkManager
桥使用network管理
[root@node1 ~]# chkconfig --list network
network 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
[root@node1 ~]# yum -y install bridge-utils
[root@node1 ~]# 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
[root@node1 ~]# cd /etc/sysconfig/network-scripts/
[root@node1 network-scripts]# cp ifcfg-eth0 ifcfg-br0
关闭NetworkManger服务进行管理:NM_CONTROLLED=no
[root@node1 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
[root@node1 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
[root@node1 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...
[确定]
[root@node1 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)
[root@node1 network-scripts]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000c29112156 no eth0
[root@node1 network-scripts]# brctl --help
Usage: brctl [commands]
commands:
addbr add bridge
delbr delete bridge
addif add interface to bridge
delif delete interface from bridge
setageing
[root@node1 network-scripts]# brctl stp br0 on
[root@node1 network-scripts]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000c29112156 yes eth0
命令创建桥:
[root@node2 ~]# 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)
[root@node2 ~]# chkconfig --list NetworkManager
[root@node2 ~]# chkconfig --list network
network 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
[root@node2 ~]# yum -y install bridge-utils
[root@node2 ~]# brctl --help
Usage: brctl [commands]
commands:
addbr add bridge
delbr delete bridge
addif add interface to bridge
delif delete interface from bridge
setageing set ageing time
setbridgeprio set bridge priority
setfd set bridge forward delay
sethello set hello time
setmaxage set max message age
sethashel set hash elasticity
sethashmax set hash max
setmclmc set multicast last member count
setmcrouter set multicast router
setmcsnoop set multicast snooping
setmcsqc set multicast startup query count
setmclmi set multicast last member interval
setmcmi set multicast membership interval
setmcqpi set multicast querier interval
setmcqi set multicast query interval
setmcqri set multicast query response interval
setmcqri set multicast startup query interval
setpathcost set path cost
setportprio set port priority
setportmcrouter set port multicast router
show [ ] show a list of bridges
showmacs show a list of mac addrs
showstp show bridge stp info
stp {on|off} turn stp on/off
[root@node2 ~]# brctl show
bridge name bridge id STP enabled interfaces
[root@node2 ~]# brctl addbr br0
[root@node2 ~]# 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)
[root@node2 ~]# ifconfig eth0 0 up
[root@node2 ~]# 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)
[root@node2 ~]# brctl addif br0 eth0
[root@node2 ~]# ifconfig br0 192.168.10.7/24 up
[root@node2 ~]# route add default gw 192.168.10.254
[root@node2 ~]# 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)