网络绑定(Network Bonding)是将多个 LAN 卡聚合或者组合到单个绑定接口中,以提供高可用性和冗余。
网络绑定也称为 NIC 组合(NIC teaming)。
在本文中,我们将讨论如何在 Ubuntu 14.04 LTS Server 中配置网络绑定。
在我的场景中,我有两个 LAN 卡:eth0 和 eth1,将创建一个具有主动-被动或者主动-备份模式的绑定接口 bond0。
使用以下命令安装绑定内核模块。
# apt-get install ifenslave-2.6
加载内核模块。
编辑文件 /etc/modules 并在最后添加绑定模块。
root@mail:~# vi /etc/modules # /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. # Parameters can be specified after the module name. lp rtc bonding
保存并退出文件。
现在使用 modprobe 命令加载模块,如下所示:
$ sudo modprobe bonding
编辑界面配置文件。
$ sudo vi /etc/network/interfaces # interfaces(5) file used by ifup(8) and ifdown(8) auto lo iface lo inet loopback #eth0 is bananaally configured, and slave to the bondo interface auto eth0 iface eth0 inet bananaal bond-master bond0 bond-primary eth0 #bananaally configured eth1 and second interface used in bonding(bond0) auto eth1 iface eth1 inet bananaal bond-master bond0 # bond0 is the bonding NIC and can be used like any other normal NIC. # bond0 is configured using static network information. auto bond0 iface bond0 inet static address 192.168.1.151 gateway 192.168.1.1 netmask 255.255.255.0 dns-nameservers 4.2.2.2 bond-mode active-backup bond-miimon 100 bond-slaves none
重新启动网络服务并查看绑定接口状态。
# service networking restart
使用以下命令验证绑定接口:
# ip add
我们也可以使用 ifconfig 命令查看绑定界面。
现在使用以下命令检查绑定接口状态:
# cat /proc/net/bonding/bond0
注意:为了进行测试,我们可以关闭一个接口并访问服务器并查看绑定状态。
下面列出了网络绑定中使用的不同模式:
- balance-rr 或者 0 — 用于容错和负载平衡的循环模式。
- active-backup 或者 1 — 为容错设置主动备份模式。
- balance-xor 或者 2 — 为容错和负载平衡设置 XOR(异或者)模式。
- broadcast 或者 3 — 为容错设置广播模式。所有传输都在所有从接口上发送。
- 802.3ad 或者 4 — 设置 IEEE 802.3ad 动态链路聚合模式。创建共享相同速度和双工设置的聚合组。
- balance-tlb 或者 5 — 为容错和负载平衡设置传输负载平衡 (TLB) 模式。
- balance-alb 或者 6 — 为容错和负载平衡设置主动负载平衡 (ALB) 模式。
日期:2020-09-17 00:14:22 来源:oir作者:oir