设为首页 收藏本站
查看: 1338|回复: 1

[经验分享] linux下用bonding实现双网卡绑定

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2013-8-27 09:03:53 | 显示全部楼层 |阅读模式

Bonding 可以把多张网卡汇聚成一张,可以提供负载平衡(load-balancing),容错(fault-tolerance)等功能。

Bonding 提供了下面几种模式,但要注意的是其中的 active-backup (mode=1),balance-tlb (mode=5) , balance-alb (mode=6) 是不需要 switch 特别支持设定的。但是其它模式 round-robin(mode=0), XOR(mode=2), broadcast(mode=3), 802.3ad policies(mode=4)则需要特别 switch 来支持.如果在设定 Bonding 时没有指定预设将会使用 mode 0 balance-rr(round-robin).

1.balance-rr or 0

假设将两张网络卡设成Balance时, 同时间Balance包含容错功能如果一张网卡故障另一张依然运作。

2.active-backup or 1

假设有两张网卡时一张是PRIMARY另一张是STANDBY 这时候流量只在PRIMARY上跑,当PRIMARY挂掉时STANDBY会自动启用接手变成PRIMARY ,如果原来PRIMARY恢复时会

自动变成STANDBY 。

至于下面几种模式我实在也搞不清楚,如果希望了解更详细的讯息,可以参考 ‘/usr/src/linux-[version]/Documentation/networking/bonding.txt。

3.balance-xor or 2

XOR policy: Transmit based on [(source MAC address XOR'd with destination MAC address) modula slave count]. This selects the same slave for each

destination MAC address. This mode provides load balancing and fault tolerance.

4.broadcast or 3

Broadcast policy: transmits everything on all slave interfaces. This mode provides fault tolerance.

5.802.3ad or 4 (Dynamic Link Aggregation)

假设将两张网络卡设成Dynamic Link Aggregation时 , 进来流量为200M出去流量为200M, 这时候需接往支持Dynamic Link Aggregation的交换器(switch),同时间

Dynamic Link Aggregation包含容错功能如果一张网卡故障另一张依然运作。

6.balance-tlb or 5(Transmit load balancing)

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.

进来流量为100M出去流量为200M

7.balance-alb or 6(Adaptive load balancing)

Adaptive load balancing: includes balance-tlb + 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 server on their way out and

overwrites the src hw address with the unique hw address of one of the slaves in the bond such that different clients use different hw addresses

for the server.

进来流量为100M出去流量为200M

以下实例以eth1和eth2组成bonding:

一,各网卡的设置。

[iyunv@localhost network-scripts]# more ifcfg-eth*

::::::::::::::

ifcfg-eth0

::::::::::::::

# Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet

DEVICE=eth0

BOOTPROTO=static

IPADDR=10.35.14.124

NETMASK=255.255.255.0

GATEWAY=10.35.14.254

ONBOOT=yes

::::::::::::::

ifcfg-eth1

::::::::::::::

# Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet

DEVICE=eth1

BOOTPROTO=none

MASTER=bond0

SLAVE=yes

ONBOOT=yes

::::::::::::::

ifcfg-eth2

::::::::::::::

# Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet

DEVICE=eth2

BOOTPROTO=none

MASTER=bond0

SLAVE=yes

ONBOOT=yes

[iyunv@localhost network-scripts]# vi ifcfg-bond0

# Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet

DEVICE=bond0

BOOTPROTO=static

IPADDR=192.168.35.1

NETMASK=255.255.255.0

ONBOOT=yes

二,进行绑定:

[iyunv@localhost network-scripts]# modprobe bonding miimon=100 mode=0

说明:miimon=100,miimon是指多久时间要检查网络一次,单位是ms(毫秒) ,这边的100,是100ms,即是0.1秒 ,

意思是假设其中有一条网络断线,会在0.1秒内自动备援。

     mode=0 即balance-rr(round-robin). 这个模式主要是做负载平衡(load-balancing)。

[iyunv@localhost network-scripts]# /etc/init.d/network restart

Shutting down interface bond0:  [  OK  ]

Shutting down interface eth0:  [  OK  ]

Shutting down loopback interface:  [  OK  ]

Bringing up loopback interface:  [  OK  ]

Bringing up interface bond0:  [  OK  ]

Bringing up interface eth0:  [  OK  ]

三,设置好的状态:

[iyunv@localhost network-scripts]# ifconfig

bond0     Link encap:Ethernet  HWaddr 78:2B:CB:12:3B:B8

         inet addr:192.168.35.1  Bcast:192.168.35.255  Mask:255.255.255.0

         inet6 addr: fe80::7a2b:cbff:fe12:3bb8/64 Scope:Link

         UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1

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

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

         collisions:0 txqueuelen:0

         RX bytes:29346 (28.6 KiB)  TX bytes:8938 (8.7 KiB)

eth0      Link encap:Ethernet  HWaddr 78:2B:CB:12:3B:B6

         inet addr:10.35.14.124  Bcast:10.35.14.255  Mask:255.255.255.0

         inet6 addr: fe80::7a2b:cbff:fe12:3bb6/64 Scope:Link

         UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

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

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

         collisions:0 txqueuelen:1000

         RX bytes:5333 (5.2 KiB)  TX bytes:11214 (10.9 KiB)

         Interrupt:106 Memory:d6000000-d6012800

eth1      Link encap:Ethernet  HWaddr 78:2B:CB:12:3B:B8

         UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1

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

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

         collisions:0 txqueuelen:1000

         RX bytes:14960 (14.6 KiB)  TX bytes:4220 (4.1 KiB)

         Interrupt:114 Memory:d8000000-d8012800

eth2      Link encap:Ethernet  HWaddr 78:2B:CB:12:3B:B8

         UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1

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

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

         collisions:0 txqueuelen:1000

         RX bytes:14386 (14.0 KiB)  TX bytes:4718 (4.6 KiB)

         Interrupt:122 Memory:da000000-da012800

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:136 errors:0 dropped:0 overruns:0 frame:0

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

         collisions:0 txqueuelen:0

         RX bytes:20638 (20.1 KiB)  TX bytes:20638 (20.1 KiB)

四,加入到modprobe里面:

[iyunv@localhost network-scripts]# vi /etc/modprobe.conf

alias eth0 bnx2

alias eth1 bnx2

alias eth2 bnx2

alias eth3 bnx2

alias eth2 bnx2

alias bond0 bonding

options bond0 miimon=100 mode=0

[iyunv@localhost ~]# modprobe -r bonding

[iyunv@localhost ~]# modprobe bonding miimon=100 mode=4

[iyunv@localhost ~]# /etc/init.d/network restart

Shutting down interface bond0:  [  OK  ]

Shutting down interface eth0:  [  OK  ]

Shutting down loopback interface:  [  OK  ]

Bringing up loopback interface:  [  OK  ]

Bringing up interface bond0:  [  OK  ]

Bringing up interface eth0:  [  OK  ]

[iyunv@localhost ~]# more /proc/net/bonding/bond0

Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008)

Bonding Mode: IEEE 802.3ad Dynamic link aggregation

Transmit Hash Policy: layer2 (0)

MII Status: up

MII Polling Interval (ms): 100

Up Delay (ms): 0

Down Delay (ms): 0

802.3ad info

LACP rate: slow

Active Aggregator Info:

       Aggregator ID: 3

       Number of ports: 1

       Actor Key: 9

       Partner Key: 1

       Partner Mac Address: 00:00:00:00:00:00

Slave Interface: eth1

MII Status: up

Link Failure Count: 0

Permanent HW addr: 78:2b:cb:12:3b:b8

Aggregator ID: 3

Slave Interface: eth2

MII Status: up

Link Failure Count: 0

Permanent HW addr: 78:2b:cb:12:3b:ba

Aggregator ID: 4



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-8725-1-1.html 上篇帖子: linux进程管理和作业任务 下篇帖子: Ubuntu中无法将属主改为域帐号解决办法 linux 网卡

尚未签到

发表于 2013-12-19 06:58:07 | 显示全部楼层
只要有想见的人就不是孤身一人了

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表