因项目需要做——ubuntu16.04 双网卡绑定

官方文档:https://help.ubuntu.com/community/UbuntuBonding


绑定,也称为端口聚合或链路聚合,意味着将多个网络接口(NIC)组合到单个链路,从而提供高可用性,负载平衡,最大吞吐量或这些组合。 详情请参阅维基百科。


1、安装

sudo apt-get install ifenslave


2、确保内核支持

在Ubuntu可以将网卡配置为NIC绑定之前,您需要确保存在正确的内核模块绑定,并在引导时加载。


编辑你的/ etc / modules配置:

sudo vim /etc/modules


确保bonding模块已加载

# /etc/modules: kernel modules to load at boot time.

#

# This file contains the names of kernel modules that should be loaded

# at boot time,one per line. Lines beginning with "#" are ignored.

loop

lp

rtc

bonding


注意:从Ubuntu 9.04开始,如果您使用ifup / ifdown配置绑定,则此步骤是可选的。 在这种情况下,绑定界面被提起时,绑定模块会自动加载。


3、配置网络接口

确保您的网络已关闭

/etc/init.d/networking stop


然后加载绑定内核模块:

sudo modprobe bonding


现在您已准备好配置您的NIC。

一般指导原则是:

1、选择哪些可用的NIC将成为bond的一部分。

2、像往常一样配置所有其他网卡

3、 配置所有绑定的NIC:

1、 要手动配置

2、加入指定的 bond-master

4、配置绑定网卡就好像它是一个正常的网卡

5、按如下所示向绑定NIC添加绑定特定参数。


编辑你的接口配置:

sudo vi /etc/network/interfaces


例如,要使用简单的活动备份设置将eth0和eth1作为 active-backup 到bonding接口bond0,并将eth0作为主接口:



以太网绑定可以使用不同的模式。 您可以在/ etc / network / interfaces中指定您的绑定接口的模式。 例如:

bond-mode 1


bonding一共有7种工作模式

  0:(balance-rr) Round-robin policy: (平衡轮询策略):传输数据包顺序是依次传输,直到最后一个传输完毕, 此模式提供负载平衡和容错能力。

  1:(active-backup) Active-backup policy:(活动备份策略):只有一个设备处于活动状态。 一个宕掉另一个马上由备份转换为主设备。mac地址是外部可见得。 此模式提供了容错能力。

  2:(balance-xor) XOR policy:(平衡策略):传输根据[(源MAC地址xor目标MAC地址)mod 设备数量]的布尔值选择传输设备。 此模式提供负载平衡和容错能力。

  3:(broadcast) broadcast policy:(广播策略):将所有数据包传输给所有设备。 此模式提供了容错能力。

  4:(802.3ad) IEEE 802.3ad Dynamic link aggregation. IEEE 802.3ad 动态链接聚合:创建共享相同的速度和双工设置的聚合组。此模式提供了容错能力。每个设备需要基于驱动的重新获取速度和全双工支持;如果使用交换机,交换机也需启用 802.3ad 模式。

  5:(balance-tlb) Adaptive transmit load balancing(适配器传输负载均衡):通道绑定不需要专用的交换机支持。发出的流量根据当前负载分给每一个设备。由当前设备处理接收,如果接受的设备传不通就用另一个设备接管当前设备正在处理的mac地址。

  6:(balance-alb) Adaptive load balancing: (适配器负载均衡):包括mode5,由 ARP 协商完成接收的负载。bonding驱动程序截获 ARP 在本地系统发送出的请求,用其中之一的硬件地址覆盖从属设备的原地址。就像是在服务器上不同的人使用不同的硬件地址一样。


如果是多个bond?(经过测试,无需这一步也是可行)

如果是多个bond,如:

eth0 和 eth1 做一个bond0

eth1 和 eth2 做一个bond1

那么需要将 /etc/modules 中的内容改为:

bonding mode=1 miimon=100 max_bonds=2

也就是在原有基础上加一个 max_bonds=2 。

网卡配置部分与bond0 的相同,只不过将配置中的eth0和eth1改为 eth2和eth3.

完。


故障测试结果:

情况1:eth0 作为主,eth1作为备, eth0断掉,会自动切换到eth1,如eth0恢复后,接线顺序为:先拔掉eth1,再马上插上eth0,接着将eth1接回去


测试环境配置文件

root@node1:~# cat /etc/network/interfaces

# This file describes the network interfaces available on your system

# and how to activate them. For more information,see interfaces(5).


source /etc/network/interfaces.d/*


# The loopback network interface

auto lo

iface lo inet loopback


# The primary network interface

auto ens33

iface ens33 inet manual

bond-master bond0

bond-primary ens33


auto ens34

iface ens34 inet manual

bond-master bond0



auto ens35

iface ens35 inet manual

bond-master bond1

bond-primary ens35


auto ens36

iface ens36 inet manual

bond-master bond1


auto bond0

iface bond0 inet static

address 192.168.89.160

gateway 192.168.89.2

netmask 255.255.255.0

bond-mode active-backup

bond-miimon 100

bond-slaves none


auto bond1

iface bond1 inet static

address 192.168.68.144

netmask 255.255.255.0

bond-mode active-backup

bond-miimon 100

bond-slaves none

相关文章

目录前言一、创建Hadoop用户二、更新apt和安装Vim编辑器三、...
原文连接:https://www.cnblogs.com/yasmi/p/5192694.html ...
电脑重启后,打开VirtualBox,发现一直用的虚拟机莫名的消失...
参见:https://blog.csdn.net/weixin_38883338/article/deta...
Ubuntu 18.04 LTS 已切换到 Netplan 来配置网络接口。Netpla...
介绍每个 Web 服务都可以通过特定的 URL 在 Internet 上访问...