SlideShare a Scribd company logo
1 of 22
Download to read offline
Linux Bonding
hubugui@gmail.com
2016-05
目录
• 介绍
• 工作模式
– mode=5 balance-tlb
– balance-tlb's transmit policy
– mode=6 balance-alb
• 测试balance-alb-输出流量
– 准备
– 例:笔记本-含WiFi网卡
– 例:服务器-多以太网卡
– 结论
– 局限
• Bonding不足 2
介绍
• 背景
– 利用多网卡提升传输速度和容错
– Sun和Cisco早已存在,Linux 2.4.x内核引入
• 原理
– 使网卡工作于混杂模式
– 虚拟多网卡到1个IP地址,利用"ARP欺骗"实现单IP地址多、MAC地址
– 提供链路监测,即主机到交换机是否接通。如果仅交换机对外链路down
掉了,bonding会认为没有故障
• 常用模式
– 多网卡负载均衡、容错(故障切换)
• 对于同一连接从不同的接口发出的包,中途传输过程中再经过不同的链接,
在客户端很有可能会出现数据包无序到达的问题,而无序到达的数据包需要
重新要求被发送,这样网络的吞吐量就会下降。
• 1次TCP send调用,对应2个IP包及2个以太网包,1个网卡送出还是2个?
• 同一个TCP连接的流量是否经过不同网卡,待验证(iftop或tcpdump)
– 主备模式,仅1块网卡工作
3
工作模式
• mode=0 (balance-rr)
– 负载均衡+容错
– 需交換機支持
• mode=1 (active-backup)
• mode=2 (balance-xor)
– 需交換機支持
• mode=3 (broadcast)
• mode=4 (balance-802.3ad)
– 需交換機支持
• mode=5 (balance-tlb)
– 容错+负载均衡
– 输入流量固定在某slave,输出流量负载均衡
– 要求驱动支持ethtool命令来获取网卡速率等信息
• mode=6 (balance-alb)
– 容错+负载均衡(3张或以上网卡才能激活)
– tlb的增强版,支持输入流量负载均衡
– 除ethtool外,还要求驱动支持修改MAC地址
4
• Adaptive transmit load balancing: channel bonding that does not
require any special switch support. The outgoing traffic is
distributed according to the current load (computed relative to the
speed) on each slave. Incoming traffic is received by the current
slave. If the receiving slave fails, another slave takes over the MAC
address of the failed receiving slave.
mode=5 (balance-tlb)
• Bonding响应对方ARP寻址广播时始终返回MAC A地址,使得输入流量一直在MAC A
• 輸出流量分配到2块网卡,可能有的交換機(EMC)不支持同一源IP地址,不同源MAC地址 5
balance-tlb's transmit policy
• 最优网卡=MIN(网卡每秒速度 - 每秒发送bit数量(最近10秒平均))
Linux Source
6
• Adaptive load balancing: includes balance-tlb plus receive load
balancing (rlb) for IPV4 traffic, and does not require any special switch
support. The receive load balancing is achieved by ARP negotiation.
The bonding driver intercepts the ARP Replies sent by the local system
on their way out and overwrites the source hardware address with the
unique hardware address of one of the slaves in the bond such that
different peers use different hardware addresses for the server.
mode=6 (balance-alb)
1. Linux kernel module used for bonding replies with the first MAC address for
some ARP requests, and the second MAC address for other ARP requests.
2. One additional item to note – if most or all of the inbound traffic to a server is
coming from a single device on the subnet (the default gateway for
instance).the receive load balancing won’t be overly effective. All traffic from
that device will be sent over the same link to the server.
3. "3层交换机或路由器的ARP缓存可能会直接发包,从而Bonding没有"欺骗ARP回复"的机会
,导致ARP缓存过期时间内,输入流量始终在一张网卡上" 7
测试balance-alb-
输出流量
8
• Ubuntu Bonding配置, 12.04/14.04
• UbuntuBonding
• Linux Bonding
• 提供Web视频服务
• 网卡流量监视工具
• sudo apt-get install bmon
• sudo apt-get install iftop
• HTTP下载工具
• sudo apt-get install wget axel
准备
9
• 服务器/Ubuntu14.04
• 服务器192.168.10.109上提供HTTP访问MP4
• 服务器上安装bmon查看网卡带宽占用
• 各个设备接入路由器
• 服务器Bonding工作模式是mode=6(balance-alb)
• Lenovo Y430P/Ubuntu 14.04/1张有线网卡,1张WIFI网卡,失败鸟...
• 没启动Bonding时无线网卡可以连接无线路由器,启动Bonding后不行,sudo ifup wlan0或
dhclient wlan0始终无法获取IP地址,同时/var/log/syslog有一些wl_错误.和驱动有关
• sudo ethtool wlan0,仅返回"No data available"
• sudo ethtool eth0,返回网卡速率等信息
• Lenovo X201i/Ubuntu 14.04/1张有线网卡,1张WIFI网卡,失败鸟...
• 无线网卡(6Mbps)可连接到无线路由器,配置bond-mode=6无效,改为balance-alb后
/proc/net/bonding/bond0中显示工作模式在balance-rr
• 虚拟网卡Bond0的IP地址192.168.10.109,eth0地址192.168.10.103,wlan0地址
192.168.10.102
• 路由器管理中可看到有2台设备进入,1个客户端地址,2个服务器地址的MAC一样
• 启动一台客户端播放HTTP流MP4同时再执行wget,实际连接到eth0(1000Mbps),带宽约
11MBps,ifdown掉有线后自动切换到wlan0(6Mbps),带宽约580KBps.客户端无不良反应
• 再次ifup eth0瞬间发现2张网卡均有输出流量,一旦ifup结束,又只有1张网卡有流量
• sudo ethtool wlan0,仅返回"Link detected: yes"
• sudo ethtool eth0,返回网卡速率等信息
• 失败原因
• 官方解释启用balance-tlb和balance-alb时网卡驱动须支持ethtool,而这2个笔记本无线网卡驱动
均不支持
例:笔记本-含WiFi网卡(1/2)
10
auto lo
iface lo inet loopback
#eth0
iface eth0 inet dhcp
bond-master bond0
#bond-primary eth0
#auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-ssid "NETGEAR38-5G-1"
wpa-psk "avccdc123"
bond-master bond0
bond-primary wlan0
# bond0
auto bond0
iface bond0 inet static
address 192.168.10.109
gateway 192.168.10.1
netmask 255.255.255.0
dns-nameservers 192.168.10.1
bond-mode balance-alb
bond-miimon 100
bond-slaves none
例:笔记本-含WiFi网卡(2/2)
/etc/network/interfaces
11
• 服务器/Ubuntu12.04
• 服务器192.168.1.50上启动3张千兆以太网卡,提供HTTP访问
• 虚拟网卡Bond0的IP地址是192.168.1.128
• 服务器上安装bmon/iftop查看网卡带宽占用
• 服务器Bonding工作模式是mode=6(balance-alb)
• 客户端
• PC1,Ubuntu14.04/192.168.1.159,千兆网卡
• PC2,Ubuntu14.04/192.168.1.149,百兆网卡
• PC3,Windows/192.168.1.100,千兆网卡
• 网络
• 接入千兆交换机
例:服务器-多以太网卡(1/7)
12
auto eth0
iface eth0 inet static
address 192.168.1.163
netmask 255.255.255.0
gateway 192.168.1.254
boot-master bond0
boot-primary eth0
auto eth1
iface eth1 inet static
address 192.168.1.50
netmask 255.255.255.0
gateway 192.168.1.254
bond-master bond0
例:服务器-多以太网卡(2/7)
13
/etc/network/interfaces
auth eth2
iface eth2 inet manual
bond-master bond0
auto bond0
iface bond0 inet static
address 192.168.1.128
netmask 255.255.255.0
gateway 192.168.1.254
#dns-nameservers 192.168.1.254
bond-mode balance-alb
bond-miimon 100
bond-slaves eth0 eth1 eth2
Ethernet Channel Bonding Driver:
v3.7.1 (April 27, 2011)
Bonding Mode: adaptive load balancing
Primary Slave: None
Currently Active Slave: eth0
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 2
Permanent HW addr: 00:25:90:68:3f:b4
Slave queue ID: 0
例:服务器-多以太网卡(3/7)
14cat /proc/net/bonding/bond0
Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:25:90:91:71:ac
Slave queue ID: 0
Slave Interface: eth2
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:25:90:91:71:ad
Slave queue ID: 0
• Bonding服务器流量-空闲
• # Interface RX Rate RX # TX Rate TX #
• 0 bond0 882.00B 12 684.00B 9
• 1 eth0 322.00B 4 191.00B 2
• 2 eth1 271.00B 3 300.00B 3
• 3 eth2 287.00B 3 191.00B 2
• 4 eth3 0.00B 0 0.00B 0
• Bonding服务器流量-PC1(千兆网卡)多线程请求MKV文件
• while true; do axel -n 10 http://192.168.1.128/hoc.mkv ; done
• # Interface RX Rate RX # TX Rate TX #
• 0 bond0 2.03MiB 30387 117.19MiB 81174
• 1 eth0 2.03MiB 30380 287.00B 3
• 2 eth1 229.00B 1 117.19MiB 81167
• 3 eth2 345.00B 2 191.00B 2
• 4 eth3 0.00B 0 0.00B 0
• PC1输入带宽和服务器网卡eth1的输出带宽已接近网卡和交换机端口上限
例:服务器-多以太网卡(4/7)
15
• Bonding服务器流量-PC2(百兆网卡)多线程请求MKV文件
• axel -n 10 http://192.168.1.128/hoc.mkv
• # Interface RX Rate RX # TX Rate TX #
• 0 bond0 269.22KiB 4136 11.68MiB 8098
• 1 eth0 336.00B 3 410.00B 4
• 2 eth1 268.63KiB 4129 11.67MiB 8088
• 3 eth2 269.00B 2 191.00B 2
• 4 eth3 0.00B 0 0.00B 0
• PC2输入带宽已接近网卡上限,服务器eth1负载不高
• Bonding服务器流量-PC3(千兆网卡)单线程请求MKV文件
• wget http://192.168.1.128/hoc.mkv
• # Interface RX Rate RX # TX Rate TX #
• 0 bond0 112.43KiB 1798 17.80MiB 12339
• 1 eth0 112.12KiB 1793 346.00B 3
• 2 eth1 119.00B 1 17.80MiB 12331
• 3 eth2 162.00B 2 191.00B 2
• 4 eth3 0.00B 0 0.00B 0
• PC3输入带宽已接近网卡上限,服务器eth1负载不高
例:服务器-多以太网卡(5/7)
16
• Bonding服务器流量-PC1/PC2/PC3并发
• PC1(千兆网卡) axel -n 2 http://192.168.1.128/hoc.mkv,2个线程不会占满带宽
• PC2(百兆网卡) axel -n 10 http://192.168.1.128/hoc.mkv
• PC3(千兆网卡) wget http://192.168.1.128/hoc.mkv
• # Interface RX Rate RX # TX Rate TX #
• 0 bond0 669.34KiB 10130 105.78MiB 73107
• 1 eth0 397.54KiB 5958 72.06MiB 49781
• 2 eth1 271.55KiB 4171 15.28MiB 10587
• 3 eth2 344.00B 2 18.47MiB 12763
• 4 eth3 0.00B 0 0.00B 0
• 该测试情况没有占满服务器的每个网卡。
例:服务器-多以太网卡(6/7)
17
• 常用命令
1. ifconfig eth0 down
2. ifconfig eth0 up
3. ifenslave bond0 eth0 eth1 eth2
4. iwconfig wlan0
5. sudo dhclient eth0
6. sudo /etc/init.d/networking restart
• QA
• Q1. 某个slave设备MII Status: down或者没有出现在cat
/proce/net/bonding/bon0的slave中
• A1. 试试上述1,2,3命令.多关闭/启动网卡几次,甚至重启系统
.如果配置非静态IP地址,可能会需要点DHCP时间
• Q2. 配置顺利吗?
• A2. Ubuntu官方例子不能一步到位.参考A1,保持耐心
例:服务器-多以太网卡(7/7)
18
• Bonding可用作负载均衡的生产环境,客户端只需访
问虚拟网卡bond0的IP地址,Bonding分流到多张网卡
• 系统实际输出带宽约等于3张网卡之和,107.78MiB
结论
19
• 笔记本环境下验证了拔掉网线后的容错,服务器上没有测试
• 3个客户端正好对应3张网卡,没验证再多些客户端是否会均
衡网卡流量?
• 1个TCP连接会在多张网卡上分担流量吗?
• 没抓包,不清楚各个情况下的"ARP欺骗"细节
• TCP重传时走的网卡会不会和首次传输时不同?
• 没有测试Bonding输入流量
局限
20
• 只检测和交换机之间链路,也就是整个网络链条
中的最后一跳,可能会出现外网已断开,
Bonding毫不知请,使得没有容错更谈不上均衡
• 网卡支持有所限制
• balance-alb发送均衡只考虑网卡发送数据量,
不考量数据包路由后的拥塞,丢失,虽然TCP数
据重传事件一定程度上会反映到发送数据量,但
仍是粗粒度均衡
Bonding不足
21
• Linux Bonding
• UbuntuBonding
• Ubuntu 14.04 Restore Networking
• Data Center Server Access Topologies: Part 1, Logical Interface Config on
Servers
• Interface/Bonding
• linux bonding 详解
• http://www.linux-magazin.de/Ausgaben/2014/07/Bonding
• http://www.lemmster.de/network-bonding-wlan-eth-on-linux-ubuntu.html
• https://github.com/zphj1987/myalldoc/blob/master/linux/%E7%BD%91%E7
%BB%9C%E7%9B%B8%E5%85%B3/ubuntu%E9%85%8D%E7%BD%AEbon
ding.md
参考
22

More Related Content

What's hot

第16讲 Vlan和Vtp
第16讲 Vlan和Vtp第16讲 Vlan和Vtp
第16讲 Vlan和VtpF.l. Yu
 
20170415- 智慧空調通訊系統實務_柯大
20170415- 智慧空調通訊系統實務_柯大20170415- 智慧空調通訊系統實務_柯大
20170415- 智慧空調通訊系統實務_柯大MAKERPRO.cc
 
第20讲 帧中继
第20讲 帧中继第20讲 帧中继
第20讲 帧中继F.l. Yu
 
Improvements Made in KoP 2.9.0 - Pulsar Summit Asia 2021
Improvements Made in KoP 2.9.0  - Pulsar Summit Asia 2021Improvements Made in KoP 2.9.0  - Pulsar Summit Asia 2021
Improvements Made in KoP 2.9.0 - Pulsar Summit Asia 2021StreamNative
 
Colonel转码集群
Colonel转码集群Colonel转码集群
Colonel转码集群pluschen
 
SACC2015 ”互联网+“任重而道远-白金&高春辉
SACC2015 ”互联网+“任重而道远-白金&高春辉SACC2015 ”互联网+“任重而道远-白金&高春辉
SACC2015 ”互联网+“任重而道远-白金&高春辉ptcracker
 
The Evolution History of RoP(RocketMQ-on-Pulsar) - Pulsar Summit Asia 2021
The Evolution History of RoP(RocketMQ-on-Pulsar) - Pulsar Summit Asia 2021The Evolution History of RoP(RocketMQ-on-Pulsar) - Pulsar Summit Asia 2021
The Evolution History of RoP(RocketMQ-on-Pulsar) - Pulsar Summit Asia 2021StreamNative
 
Computer Network 1 TCP/IP
Computer Network 1 TCP/IPComputer Network 1 TCP/IP
Computer Network 1 TCP/IPFelix Lin
 
第19讲 Isdn
第19讲 Isdn第19讲 Isdn
第19讲 IsdnF.l. Yu
 
实验2 数据链路层和网络层协议分析(研究生)2013春
实验2 数据链路层和网络层协议分析(研究生)2013春实验2 数据链路层和网络层协议分析(研究生)2013春
实验2 数据链路层和网络层协议分析(研究生)2013春凯 罗
 
第7讲 路由协议原理
第7讲 路由协议原理第7讲 路由协议原理
第7讲 路由协议原理F.l. Yu
 
第13讲 Nat网络地址转换
第13讲 Nat网络地址转换第13讲 Nat网络地址转换
第13讲 Nat网络地址转换F.l. Yu
 
第9讲 Eigrp
第9讲 Eigrp第9讲 Eigrp
第9讲 EigrpF.l. Yu
 
初學者都該了解的 HTTP 通訊協定基礎
初學者都該了解的 HTTP 通訊協定基礎初學者都該了解的 HTTP 通訊協定基礎
初學者都該了解的 HTTP 通訊協定基礎Will Huang
 
第11讲 管理Cisco互联网络
第11讲 管理Cisco互联网络第11讲 管理Cisco互联网络
第11讲 管理Cisco互联网络F.l. Yu
 
第18讲 Hdlc和Ppp
第18讲 Hdlc和Ppp第18讲 Hdlc和Ppp
第18讲 Hdlc和PppF.l. Yu
 
Computer Network 6 CAN
Computer Network 6 CANComputer Network 6 CAN
Computer Network 6 CANFelix Lin
 
0416 Windows Server 2008 Native IPv6 新功能介紹
0416 Windows Server 2008 Native IPv6 新功能介紹0416 Windows Server 2008 Native IPv6 新功能介紹
0416 Windows Server 2008 Native IPv6 新功能介紹Timothy Chen
 

What's hot (20)

第16讲 Vlan和Vtp
第16讲 Vlan和Vtp第16讲 Vlan和Vtp
第16讲 Vlan和Vtp
 
20170415- 智慧空調通訊系統實務_柯大
20170415- 智慧空調通訊系統實務_柯大20170415- 智慧空調通訊系統實務_柯大
20170415- 智慧空調通訊系統實務_柯大
 
第20讲 帧中继
第20讲 帧中继第20讲 帧中继
第20讲 帧中继
 
Improvements Made in KoP 2.9.0 - Pulsar Summit Asia 2021
Improvements Made in KoP 2.9.0  - Pulsar Summit Asia 2021Improvements Made in KoP 2.9.0  - Pulsar Summit Asia 2021
Improvements Made in KoP 2.9.0 - Pulsar Summit Asia 2021
 
Colonel转码集群
Colonel转码集群Colonel转码集群
Colonel转码集群
 
SACC2015 ”互联网+“任重而道远-白金&高春辉
SACC2015 ”互联网+“任重而道远-白金&高春辉SACC2015 ”互联网+“任重而道远-白金&高春辉
SACC2015 ”互联网+“任重而道远-白金&高春辉
 
The Evolution History of RoP(RocketMQ-on-Pulsar) - Pulsar Summit Asia 2021
The Evolution History of RoP(RocketMQ-on-Pulsar) - Pulsar Summit Asia 2021The Evolution History of RoP(RocketMQ-on-Pulsar) - Pulsar Summit Asia 2021
The Evolution History of RoP(RocketMQ-on-Pulsar) - Pulsar Summit Asia 2021
 
Computer Network 1 TCP/IP
Computer Network 1 TCP/IPComputer Network 1 TCP/IP
Computer Network 1 TCP/IP
 
第19讲 Isdn
第19讲 Isdn第19讲 Isdn
第19讲 Isdn
 
实验2 数据链路层和网络层协议分析(研究生)2013春
实验2 数据链路层和网络层协议分析(研究生)2013春实验2 数据链路层和网络层协议分析(研究生)2013春
实验2 数据链路层和网络层协议分析(研究生)2013春
 
第7讲 路由协议原理
第7讲 路由协议原理第7讲 路由协议原理
第7讲 路由协议原理
 
第13讲 Nat网络地址转换
第13讲 Nat网络地址转换第13讲 Nat网络地址转换
第13讲 Nat网络地址转换
 
p2p通信之nat
p2p通信之natp2p通信之nat
p2p通信之nat
 
第9讲 Eigrp
第9讲 Eigrp第9讲 Eigrp
第9讲 Eigrp
 
初學者都該了解的 HTTP 通訊協定基礎
初學者都該了解的 HTTP 通訊協定基礎初學者都該了解的 HTTP 通訊協定基礎
初學者都該了解的 HTTP 通訊協定基礎
 
FCN lan2lan
FCN lan2lanFCN lan2lan
FCN lan2lan
 
第11讲 管理Cisco互联网络
第11讲 管理Cisco互联网络第11讲 管理Cisco互联网络
第11讲 管理Cisco互联网络
 
第18讲 Hdlc和Ppp
第18讲 Hdlc和Ppp第18讲 Hdlc和Ppp
第18讲 Hdlc和Ppp
 
Computer Network 6 CAN
Computer Network 6 CANComputer Network 6 CAN
Computer Network 6 CAN
 
0416 Windows Server 2008 Native IPv6 新功能介紹
0416 Windows Server 2008 Native IPv6 新功能介紹0416 Windows Server 2008 Native IPv6 新功能介紹
0416 Windows Server 2008 Native IPv6 新功能介紹
 

Similar to Linux bonding

实时消息推送系统
实时消息推送系统实时消息推送系统
实时消息推送系统Yi Feng Yang
 
网络基础知识(经典)
网络基础知识(经典)网络基础知识(经典)
网络基础知识(经典)littlesujin
 
第3讲 Tcpip协议栈
第3讲 Tcpip协议栈第3讲 Tcpip协议栈
第3讲 Tcpip协议栈F.l. Yu
 
Java线上应用问题排查方法和工具(空望)
Java线上应用问题排查方法和工具(空望)Java线上应用问题排查方法和工具(空望)
Java线上应用问题排查方法和工具(空望)ykdsg
 
Io t security-ameba-ppt
Io t security-ameba-pptIo t security-ameba-ppt
Io t security-ameba-pptJou Neo
 
C1000K高性能服务器构建技术
C1000K高性能服务器构建技术C1000K高性能服务器构建技术
C1000K高性能服务器构建技术Feng Yu
 
第2讲 Osi分层模型
第2讲 Osi分层模型第2讲 Osi分层模型
第2讲 Osi分层模型F.l. Yu
 
Openstack neutron 原理详解
Openstack neutron 原理详解Openstack neutron 原理详解
Openstack neutron 原理详解Yong Luo
 
Juniper ScreenOS 基于Policy的
Juniper ScreenOS 基于Policy的Juniper ScreenOS 基于Policy的
Juniper ScreenOS 基于Policy的mickchen
 
计算机组成原理 6
计算机组成原理 6计算机组成原理 6
计算机组成原理 6lqarenas
 
Net重點及作業解答
Net重點及作業解答Net重點及作業解答
Net重點及作業解答longfire2007
 
Module 08 防火牆
Module 08 防火牆Module 08 防火牆
Module 08 防火牆rbk19871124
 
构建ActionScript游戏服务器,支持超过15000并发连接
构建ActionScript游戏服务器,支持超过15000并发连接 构建ActionScript游戏服务器,支持超过15000并发连接
构建ActionScript游戏服务器,支持超过15000并发连接 Renaun Erickson
 
Track2 -刘继伟--openstack in gamewave
Track2 -刘继伟--openstack in gamewaveTrack2 -刘继伟--openstack in gamewave
Track2 -刘继伟--openstack in gamewaveOpenCity Community
 
Linux Network Monitoring
Linux Network MonitoringLinux Network Monitoring
Linux Network MonitoringKenny (netman)
 

Similar to Linux bonding (20)

实时消息推送系统
实时消息推送系统实时消息推送系统
实时消息推送系统
 
Tcpip
TcpipTcpip
Tcpip
 
网络基础知识(经典)
网络基础知识(经典)网络基础知识(经典)
网络基础知识(经典)
 
第3讲 Tcpip协议栈
第3讲 Tcpip协议栈第3讲 Tcpip协议栈
第3讲 Tcpip协议栈
 
network1
network1network1
network1
 
Java线上应用问题排查方法和工具(空望)
Java线上应用问题排查方法和工具(空望)Java线上应用问题排查方法和工具(空望)
Java线上应用问题排查方法和工具(空望)
 
Os讀書會20170415
Os讀書會20170415Os讀書會20170415
Os讀書會20170415
 
Io t security-ameba-ppt
Io t security-ameba-pptIo t security-ameba-ppt
Io t security-ameba-ppt
 
C1000K高性能服务器构建技术
C1000K高性能服务器构建技术C1000K高性能服务器构建技术
C1000K高性能服务器构建技术
 
第2讲 Osi分层模型
第2讲 Osi分层模型第2讲 Osi分层模型
第2讲 Osi分层模型
 
Openstack neutron 原理详解
Openstack neutron 原理详解Openstack neutron 原理详解
Openstack neutron 原理详解
 
Juniper ScreenOS 基于Policy的
Juniper ScreenOS 基于Policy的Juniper ScreenOS 基于Policy的
Juniper ScreenOS 基于Policy的
 
计算机组成原理 6
计算机组成原理 6计算机组成原理 6
计算机组成原理 6
 
Net重點及作業解答
Net重點及作業解答Net重點及作業解答
Net重點及作業解答
 
Module 08 防火牆
Module 08 防火牆Module 08 防火牆
Module 08 防火牆
 
构建ActionScript游戏服务器,支持超过15000并发连接
构建ActionScript游戏服务器,支持超过15000并发连接 构建ActionScript游戏服务器,支持超过15000并发连接
构建ActionScript游戏服务器,支持超过15000并发连接
 
網路概論
網路概論網路概論
網路概論
 
Snort分析评估
Snort分析评估Snort分析评估
Snort分析评估
 
Track2 -刘继伟--openstack in gamewave
Track2 -刘继伟--openstack in gamewaveTrack2 -刘继伟--openstack in gamewave
Track2 -刘继伟--openstack in gamewave
 
Linux Network Monitoring
Linux Network MonitoringLinux Network Monitoring
Linux Network Monitoring
 

Linux bonding

  • 2. 目录 • 介绍 • 工作模式 – mode=5 balance-tlb – balance-tlb's transmit policy – mode=6 balance-alb • 测试balance-alb-输出流量 – 准备 – 例:笔记本-含WiFi网卡 – 例:服务器-多以太网卡 – 结论 – 局限 • Bonding不足 2
  • 3. 介绍 • 背景 – 利用多网卡提升传输速度和容错 – Sun和Cisco早已存在,Linux 2.4.x内核引入 • 原理 – 使网卡工作于混杂模式 – 虚拟多网卡到1个IP地址,利用"ARP欺骗"实现单IP地址多、MAC地址 – 提供链路监测,即主机到交换机是否接通。如果仅交换机对外链路down 掉了,bonding会认为没有故障 • 常用模式 – 多网卡负载均衡、容错(故障切换) • 对于同一连接从不同的接口发出的包,中途传输过程中再经过不同的链接, 在客户端很有可能会出现数据包无序到达的问题,而无序到达的数据包需要 重新要求被发送,这样网络的吞吐量就会下降。 • 1次TCP send调用,对应2个IP包及2个以太网包,1个网卡送出还是2个? • 同一个TCP连接的流量是否经过不同网卡,待验证(iftop或tcpdump) – 主备模式,仅1块网卡工作 3
  • 4. 工作模式 • mode=0 (balance-rr) – 负载均衡+容错 – 需交換機支持 • mode=1 (active-backup) • mode=2 (balance-xor) – 需交換機支持 • mode=3 (broadcast) • mode=4 (balance-802.3ad) – 需交換機支持 • mode=5 (balance-tlb) – 容错+负载均衡 – 输入流量固定在某slave,输出流量负载均衡 – 要求驱动支持ethtool命令来获取网卡速率等信息 • mode=6 (balance-alb) – 容错+负载均衡(3张或以上网卡才能激活) – tlb的增强版,支持输入流量负载均衡 – 除ethtool外,还要求驱动支持修改MAC地址 4
  • 5. • Adaptive transmit load balancing: channel bonding that does not require any special switch support. The outgoing traffic is distributed according to the current load (computed relative to the speed) on each slave. Incoming traffic is received by the current slave. If the receiving slave fails, another slave takes over the MAC address of the failed receiving slave. mode=5 (balance-tlb) • Bonding响应对方ARP寻址广播时始终返回MAC A地址,使得输入流量一直在MAC A • 輸出流量分配到2块网卡,可能有的交換機(EMC)不支持同一源IP地址,不同源MAC地址 5
  • 6. balance-tlb's transmit policy • 最优网卡=MIN(网卡每秒速度 - 每秒发送bit数量(最近10秒平均)) Linux Source 6
  • 7. • Adaptive load balancing: includes balance-tlb plus receive load balancing (rlb) for IPV4 traffic, and does not require any special switch support. The receive load balancing is achieved by ARP negotiation. The bonding driver intercepts the ARP Replies sent by the local system on their way out and overwrites the source hardware address with the unique hardware address of one of the slaves in the bond such that different peers use different hardware addresses for the server. mode=6 (balance-alb) 1. Linux kernel module used for bonding replies with the first MAC address for some ARP requests, and the second MAC address for other ARP requests. 2. One additional item to note – if most or all of the inbound traffic to a server is coming from a single device on the subnet (the default gateway for instance).the receive load balancing won’t be overly effective. All traffic from that device will be sent over the same link to the server. 3. "3层交换机或路由器的ARP缓存可能会直接发包,从而Bonding没有"欺骗ARP回复"的机会 ,导致ARP缓存过期时间内,输入流量始终在一张网卡上" 7
  • 9. • Ubuntu Bonding配置, 12.04/14.04 • UbuntuBonding • Linux Bonding • 提供Web视频服务 • 网卡流量监视工具 • sudo apt-get install bmon • sudo apt-get install iftop • HTTP下载工具 • sudo apt-get install wget axel 准备 9
  • 10. • 服务器/Ubuntu14.04 • 服务器192.168.10.109上提供HTTP访问MP4 • 服务器上安装bmon查看网卡带宽占用 • 各个设备接入路由器 • 服务器Bonding工作模式是mode=6(balance-alb) • Lenovo Y430P/Ubuntu 14.04/1张有线网卡,1张WIFI网卡,失败鸟... • 没启动Bonding时无线网卡可以连接无线路由器,启动Bonding后不行,sudo ifup wlan0或 dhclient wlan0始终无法获取IP地址,同时/var/log/syslog有一些wl_错误.和驱动有关 • sudo ethtool wlan0,仅返回"No data available" • sudo ethtool eth0,返回网卡速率等信息 • Lenovo X201i/Ubuntu 14.04/1张有线网卡,1张WIFI网卡,失败鸟... • 无线网卡(6Mbps)可连接到无线路由器,配置bond-mode=6无效,改为balance-alb后 /proc/net/bonding/bond0中显示工作模式在balance-rr • 虚拟网卡Bond0的IP地址192.168.10.109,eth0地址192.168.10.103,wlan0地址 192.168.10.102 • 路由器管理中可看到有2台设备进入,1个客户端地址,2个服务器地址的MAC一样 • 启动一台客户端播放HTTP流MP4同时再执行wget,实际连接到eth0(1000Mbps),带宽约 11MBps,ifdown掉有线后自动切换到wlan0(6Mbps),带宽约580KBps.客户端无不良反应 • 再次ifup eth0瞬间发现2张网卡均有输出流量,一旦ifup结束,又只有1张网卡有流量 • sudo ethtool wlan0,仅返回"Link detected: yes" • sudo ethtool eth0,返回网卡速率等信息 • 失败原因 • 官方解释启用balance-tlb和balance-alb时网卡驱动须支持ethtool,而这2个笔记本无线网卡驱动 均不支持 例:笔记本-含WiFi网卡(1/2) 10
  • 11. auto lo iface lo inet loopback #eth0 iface eth0 inet dhcp bond-master bond0 #bond-primary eth0 #auto wlan0 allow-hotplug wlan0 iface wlan0 inet dhcp wpa-ssid "NETGEAR38-5G-1" wpa-psk "avccdc123" bond-master bond0 bond-primary wlan0 # bond0 auto bond0 iface bond0 inet static address 192.168.10.109 gateway 192.168.10.1 netmask 255.255.255.0 dns-nameservers 192.168.10.1 bond-mode balance-alb bond-miimon 100 bond-slaves none 例:笔记本-含WiFi网卡(2/2) /etc/network/interfaces 11
  • 12. • 服务器/Ubuntu12.04 • 服务器192.168.1.50上启动3张千兆以太网卡,提供HTTP访问 • 虚拟网卡Bond0的IP地址是192.168.1.128 • 服务器上安装bmon/iftop查看网卡带宽占用 • 服务器Bonding工作模式是mode=6(balance-alb) • 客户端 • PC1,Ubuntu14.04/192.168.1.159,千兆网卡 • PC2,Ubuntu14.04/192.168.1.149,百兆网卡 • PC3,Windows/192.168.1.100,千兆网卡 • 网络 • 接入千兆交换机 例:服务器-多以太网卡(1/7) 12
  • 13. auto eth0 iface eth0 inet static address 192.168.1.163 netmask 255.255.255.0 gateway 192.168.1.254 boot-master bond0 boot-primary eth0 auto eth1 iface eth1 inet static address 192.168.1.50 netmask 255.255.255.0 gateway 192.168.1.254 bond-master bond0 例:服务器-多以太网卡(2/7) 13 /etc/network/interfaces auth eth2 iface eth2 inet manual bond-master bond0 auto bond0 iface bond0 inet static address 192.168.1.128 netmask 255.255.255.0 gateway 192.168.1.254 #dns-nameservers 192.168.1.254 bond-mode balance-alb bond-miimon 100 bond-slaves eth0 eth1 eth2
  • 14. Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: adaptive load balancing Primary Slave: None Currently Active Slave: eth0 MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 Slave Interface: eth1 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 2 Permanent HW addr: 00:25:90:68:3f:b4 Slave queue ID: 0 例:服务器-多以太网卡(3/7) 14cat /proc/net/bonding/bond0 Slave Interface: eth0 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:25:90:91:71:ac Slave queue ID: 0 Slave Interface: eth2 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:25:90:91:71:ad Slave queue ID: 0
  • 15. • Bonding服务器流量-空闲 • # Interface RX Rate RX # TX Rate TX # • 0 bond0 882.00B 12 684.00B 9 • 1 eth0 322.00B 4 191.00B 2 • 2 eth1 271.00B 3 300.00B 3 • 3 eth2 287.00B 3 191.00B 2 • 4 eth3 0.00B 0 0.00B 0 • Bonding服务器流量-PC1(千兆网卡)多线程请求MKV文件 • while true; do axel -n 10 http://192.168.1.128/hoc.mkv ; done • # Interface RX Rate RX # TX Rate TX # • 0 bond0 2.03MiB 30387 117.19MiB 81174 • 1 eth0 2.03MiB 30380 287.00B 3 • 2 eth1 229.00B 1 117.19MiB 81167 • 3 eth2 345.00B 2 191.00B 2 • 4 eth3 0.00B 0 0.00B 0 • PC1输入带宽和服务器网卡eth1的输出带宽已接近网卡和交换机端口上限 例:服务器-多以太网卡(4/7) 15
  • 16. • Bonding服务器流量-PC2(百兆网卡)多线程请求MKV文件 • axel -n 10 http://192.168.1.128/hoc.mkv • # Interface RX Rate RX # TX Rate TX # • 0 bond0 269.22KiB 4136 11.68MiB 8098 • 1 eth0 336.00B 3 410.00B 4 • 2 eth1 268.63KiB 4129 11.67MiB 8088 • 3 eth2 269.00B 2 191.00B 2 • 4 eth3 0.00B 0 0.00B 0 • PC2输入带宽已接近网卡上限,服务器eth1负载不高 • Bonding服务器流量-PC3(千兆网卡)单线程请求MKV文件 • wget http://192.168.1.128/hoc.mkv • # Interface RX Rate RX # TX Rate TX # • 0 bond0 112.43KiB 1798 17.80MiB 12339 • 1 eth0 112.12KiB 1793 346.00B 3 • 2 eth1 119.00B 1 17.80MiB 12331 • 3 eth2 162.00B 2 191.00B 2 • 4 eth3 0.00B 0 0.00B 0 • PC3输入带宽已接近网卡上限,服务器eth1负载不高 例:服务器-多以太网卡(5/7) 16
  • 17. • Bonding服务器流量-PC1/PC2/PC3并发 • PC1(千兆网卡) axel -n 2 http://192.168.1.128/hoc.mkv,2个线程不会占满带宽 • PC2(百兆网卡) axel -n 10 http://192.168.1.128/hoc.mkv • PC3(千兆网卡) wget http://192.168.1.128/hoc.mkv • # Interface RX Rate RX # TX Rate TX # • 0 bond0 669.34KiB 10130 105.78MiB 73107 • 1 eth0 397.54KiB 5958 72.06MiB 49781 • 2 eth1 271.55KiB 4171 15.28MiB 10587 • 3 eth2 344.00B 2 18.47MiB 12763 • 4 eth3 0.00B 0 0.00B 0 • 该测试情况没有占满服务器的每个网卡。 例:服务器-多以太网卡(6/7) 17
  • 18. • 常用命令 1. ifconfig eth0 down 2. ifconfig eth0 up 3. ifenslave bond0 eth0 eth1 eth2 4. iwconfig wlan0 5. sudo dhclient eth0 6. sudo /etc/init.d/networking restart • QA • Q1. 某个slave设备MII Status: down或者没有出现在cat /proce/net/bonding/bon0的slave中 • A1. 试试上述1,2,3命令.多关闭/启动网卡几次,甚至重启系统 .如果配置非静态IP地址,可能会需要点DHCP时间 • Q2. 配置顺利吗? • A2. Ubuntu官方例子不能一步到位.参考A1,保持耐心 例:服务器-多以太网卡(7/7) 18
  • 20. • 笔记本环境下验证了拔掉网线后的容错,服务器上没有测试 • 3个客户端正好对应3张网卡,没验证再多些客户端是否会均 衡网卡流量? • 1个TCP连接会在多张网卡上分担流量吗? • 没抓包,不清楚各个情况下的"ARP欺骗"细节 • TCP重传时走的网卡会不会和首次传输时不同? • 没有测试Bonding输入流量 局限 20
  • 21. • 只检测和交换机之间链路,也就是整个网络链条 中的最后一跳,可能会出现外网已断开, Bonding毫不知请,使得没有容错更谈不上均衡 • 网卡支持有所限制 • balance-alb发送均衡只考虑网卡发送数据量, 不考量数据包路由后的拥塞,丢失,虽然TCP数 据重传事件一定程度上会反映到发送数据量,但 仍是粗粒度均衡 Bonding不足 21
  • 22. • Linux Bonding • UbuntuBonding • Ubuntu 14.04 Restore Networking • Data Center Server Access Topologies: Part 1, Logical Interface Config on Servers • Interface/Bonding • linux bonding 详解 • http://www.linux-magazin.de/Ausgaben/2014/07/Bonding • http://www.lemmster.de/network-bonding-wlan-eth-on-linux-ubuntu.html • https://github.com/zphj1987/myalldoc/blob/master/linux/%E7%BD%91%E7 %BB%9C%E7%9B%B8%E5%85%B3/ubuntu%E9%85%8D%E7%BD%AEbon ding.md 参考 22