Linux 服务器配置网卡绑定(bonding)详解

目录

  • Linux 服务器配置网卡绑定(bonding)详解
    • 一、查看系统内核是否支持 bonding
    • 二、bonding 的七种工作模式
      • 1、mode=0(balance-rr):Round-robin policy(平衡轮询策略)
      • 2、mode=1(active-backup):Active-backup policy(主-备份策略)
      • 3、mode=2(balance-xor):XOR policy(平衡策略)
      • 4、mode=3(broadcast):broadcast(广播策略)
      • 5、802.3ad(mode=4):IEEE 802.3adDynamic link aggregation(IEEE 802.3ad 动态 链接聚合)
      • 6、mode=5(balance-tlb):Adaptive transmit load balancing(适配器传输负载均衡)
      • 7、mode=6(balance-alb):Adaptive load balancing(适配器适应性负载均衡)
    • 三、Centos7 配置网卡绑定(bonding)
      • 1、停止 NetworkManager 服务
      • 2、加载 bonding 模块
      • 3、创建基于 bond1 接口的网卡配置文件
      • 4、修改 ens33、ens34 接口文件的内容
      • 5、加载 bond1 接口到内核
      • 6、重启网络,查看网卡绑定信息
    • 四、设置多个 bond
      • 1、创建基于 bond2 接口的网卡配置文件
      • 2、修改 ens35、ens39 接口文件的内容
      • 3、修改 /etc/modprobe.d/bonding.conf 文件
      • 4、加载模块(或重启系统)
      • 5、检查模块是否加载成功
      • 6、重启网络,查看网卡绑定信息

网卡绑定(bonding)是将多张网卡绑定为一个逻辑网卡,实现本地网卡的冗余、带宽扩容和负载均衡,在生产环境中经常使用。

一、查看系统内核是否支持 bonding

bonding 技术是 Linux 系统内核层面实现的,它是一个内核模块(驱动)。

[root@rac1 boot]# cd /boot[root@rac1 boot]# ll
总用量 22447
-rw-r--r--. 1 root root   105195 11月 22 2013 config-2.6.32-431.el6.x86_64
drwxr-xr-x. 3 root root     1024 6月   3 07:02 efi
drwxr-xr-x. 2 root root     1024 6月   3 07:03 grub
-rw-------. 1 root root 16014947 6月   3 07:03 initramfs-2.6.32-431.el6.x86_64.img
drwx------. 2 root root    12288 6月   3 07:01 lost+found
-rw-r--r--. 1 root root   193758 11月 22 2013 symvers-2.6.32-431.el6.x86_64.gz
-rw-r--r--. 1 root root  2518236 11月 22 2013 System.map-2.6.32-431.el6.x86_64
-rwxr-xr-x. 1 root root  4128368 11月 22 2013 vmlinuz-2.6.32-431.el6.x86_64[root@rac1 boot]# cat config-2.6.32-431.el6.x86_64 |grep -i bonding
CONFIG_BONDING=m

二、bonding 的七种工作模式

bonding 技术提供了七种工作模式,常用的模式有 0、1、4、6,每种工作模式都有其各自的优缺点:

1、mode=0(balance-rr):Round-robin policy(平衡轮询策略)

特点:传输数据包顺序是依次传输,比如第一个包走 eth0,第二个包走 eth1,直到数据包发送完毕。增加了带宽,同时支持容错能力,当有链路出问题,会把流量切换到正常的链路上。
缺点:需要接入交换机做端口聚合。

2、mode=1(active-backup):Active-backup policy(主-备份策略)

特点:当一个宕掉另一个马上由备份转换为主设备。冗余性高,不需要交换机端支持。
缺点:资源利用率较低,只有一个接口处于工作状态。

3、mode=2(balance-xor):XOR policy(平衡策略)

特点:基于指定的传输 HASH 策略传输数据包。此模式提供负载平衡和容错能力。
缺点:需要交换机配置端口聚合。

4、mode=3(broadcast):broadcast(广播策略)

特点:在每个 slave 接口上传输每个数据包,此模式提供了容错能力。

5、802.3ad(mode=4):IEEE 802.3adDynamic link aggregation(IEEE 802.3ad 动态 链接聚合)

创建一个聚合组,它们共享同样的速率和双工设定。根据 802.3ad 规范将多个 slave 工作在同一个激活的聚合体下。
特点:
(1)ethtool支持获取每个slave的速率和双工设定。
(2)交换机支持 IEEE 802.3ad Dynamic link aggregation。
(3)大多数交换机需要经过特定配置才能支持 802.3ad模式。

6、mode=5(balance-tlb):Adaptive transmit load balancing(适配器传输负载均衡)

特点:不需要任何特别的交换机支持的通道 bonding。在每个 slave 上根据当前的负载(根据速度计算)分配外出流量。如果正在接受数据的 slave 出故障了,另一个 slave 接管失败的 slave 的 MAC 地址。

7、mode=6(balance-alb):Adaptive load balancing(适配器适应性负载均衡)

特点:该模式包含了 balance-tlb 模式,同时加上针对 IPV4 流量的接收负载均衡(receive load balance,rlb),而且不需要任何交换机的支持。

三、Centos7 配置网卡绑定(bonding)

配置信息如下:

操作系统: Centos7
网卡: ens33、ens34
bond1:192.168.1.102
负载模式: mode1(adaptive load balancing)  #主备模式

1、停止 NetworkManager 服务

执行如下命令:

[root@localhost ~]# systemctl stop NetworkManager[root@localhost ~]# systemctl disable NetworkManager
Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service.

2、加载 bonding 模块

[root@localhost ~]# modprobe --first-time bonding
modprobe: ERROR: could not insert 'bonding': Module already in kernel

3、创建基于 bond1 接口的网卡配置文件

[root@localhost ~]# cd /etc/sysconfig/network-scripts/[root@localhost network-scripts]# ll ifcfg-*
-rw-r--r--. 1 root root 309 6月  10 00:28 ifcfg-ens33
-rw-r--r--. 1 root root 309 6月  10 00:28 ifcfg-ens34
-rw-r--r--. 1 root root 309 6月  10 00:28 ifcfg-ens35
-rw-r--r--. 1 root root 215 6月  11 2022 ifcfg-ens39
-rw-r--r--. 1 root root 254 9月  12 2016 ifcfg-lo[root@localhost network-scripts]# touch ifcfg-bond1
[root@localhost network-scripts]# ll ifcfg-*
-rw-r--r--. 1 root root   0 6月  10 18:15 ifcfg-bond1
-rw-r--r--. 1 root root 309 6月  10 00:28 ifcfg-ens33
-rw-r--r--. 1 root root 309 6月  10 00:28 ifcfg-ens34
-rw-r--r--. 1 root root 309 6月  10 00:28 ifcfg-ens35
-rw-r--r--. 1 root root 215 6月  11 2022 ifcfg-ens39
-rw-r--r--. 1 root root 254 9月  12 2016 ifcfg-lo

配置文件 ifcfg-bond1 的内容如下:

DEVICE=bond1
TYPE=Bond
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.1.102
GATEWAY=192.168.1.1
DNS1=192.168.1.1
PREFIX=24
USERCTL=no
BONDING_OPTS="mode=1 miimon=100"

4、修改 ens33、ens34 接口文件的内容

配置文件 ens33 内容如下:

[root@rac1 modprobe.d]# cd /etc/sysconfig/network-scripts/
[root@rac1 network-scripts]# vi ifcfg-ens33## 内容如下
DEVICE=ens33
MASTER=bond1
SLAVE=yes
USERCTL=no
ONBOOT=yes
BOOTPROTO=none

配置文件 ens34 内容如下:

[root@rac1 network-scripts]# vi ifcfg-eth2## 内容如下
DEVICE=ens34
MASTER=bond1
SLAVE=yes
USERCTL=no
ONBOOT=yes
BOOTPROTO=none

5、加载 bond1 接口到内核

# (1)创建加载 bonding 的文件
[root@rac1 network-scripts]# vi /etc/modprobe.d/bonding.conf##内容如下
lias bond1 bonding
options bonding mode=1 miimon=200# (2)加载模块(或重启系统)
[root@localhost network-scripts]# modprobe bonding
libkmod: kmod_config_parse: /etc/modprobe.d/bonding.conf line 1: ignoring bad line starting with 'lias'# (3)检查模块是否加载成功
[root@localhost network-scripts]# lsmod | grep bonding
bonding               141566  0

6、重启网络,查看网卡绑定信息

[root@localhost network-scripts]# systemctl restart network[root@localhost network-scripts]# cat /proc/net/bonding/bond1
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)Bonding Mode: fault-tolerance (active-backup)  # bonding模式为 active-backup(mode=1)
Primary Slave: None
Currently Active Slave: ens33   # 网卡 ens33 为 Active 状态
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0Slave Interface: ens33
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:88:a6:53
Slave queue ID: 0Slave Interface: ens34
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:88:a6:5d
Slave queue ID: 0

四、设置多个 bond

现在需要增加一组 bond,名称为 bond2,包含 ens35 和 ens39 两块网卡,IP 地址设置为 10.1.1.102,配置过程如下:

1、创建基于 bond2 接口的网卡配置文件

[root@localhost network-scripts]# cp ifcfg-bond1 ifcfg-bond2
[root@localhost network-scripts]# ll ifcfg*
-rw-r--r--. 1 root root 161 6月  10 18:18 ifcfg-bond1
-rw-r--r--. 1 root root 161 6月  10 18:56 ifcfg-bond2
-rw-r--r--. 1 root root  73 6月  10 18:22 ifcfg-ens33
-rw-r--r--. 1 root root  74 6月  10 18:23 ifcfg-ens34
-rw-r--r--. 1 root root 309 6月  10 00:28 ifcfg-ens35
-rw-r--r--. 1 root root 219 6月  10 18:28 ifcfg-ens39
-rw-r--r--. 1 root root 254 9月  12 2016 ifcfg-lo

配置文件 ifcfg-bond2 的内容如下:

DEVICE=bond2
TYPE=Bond
BOOTPROTO=none
ONBOOT=yes
IPADDR=10.1.1.102
PREFIX=24
USERCTL=no
BONDING_OPTS="mode=1 miimon=100"

2、修改 ens35、ens39 接口文件的内容

配置文件 ens35 内容如下:

DEVICE=ens35
MASTER=bond2
SLAVE=yes
USERCTL=no
ONBOOT=yes
BOOTPROTO=none

配置文件 ens39 内容如下:

DEVICE=ens39
MASTER=bond2
SLAVE=yes
USERCTL=no
ONBOOT=yes
BOOTPROTO=none

3、修改 /etc/modprobe.d/bonding.conf 文件

<span style="color:#000000;">alias bond1 bonding
alias bond2 bonding
options bonding max_bonds=2 miimon=200 mode=1
</span># 或<span style="color:#000000;">alias bond1 bonding
options bond1 miimon=100 mode=1
install bond2 /sbin/modprobe bonding -o bond2 miimon=200 mode=1
</span># 参数说明:
# miimon:监视网络链接的频度,单位是毫秒
# max_bonds:配置的 bond 个数
# mode bond:工作模式

4、加载模块(或重启系统)

[root@localhost network-scripts]# modprobe bonding
libkmod: kmod_config_parse: /etc/modprobe.d/bonding.conf line 1: ignoring bad line starting with '<span'
libkmod: kmod_config_parse: /etc/modprobe.d/bonding.conf line 4: ignoring bad line starting with '</span>'

5、检查模块是否加载成功

[root@localhost network-scripts]# lsmod | grep bonding
bonding               141566  0

6、重启网络,查看网卡绑定信息

[root@localhost network-scripts]# systemctl restart network#====================================   bond1  =========================================
[root@localhost network-scripts]# cat /proc/net/bonding/bond1
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: ens33
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0Slave Interface: ens33
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:88:a6:53
Slave queue ID: 0Slave Interface: ens34
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:88:a6:5d
Slave queue ID: 0#====================================   bond2  =========================================
[root@localhost network-scripts]# cat /proc/net/bonding/bond2
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: ens35
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0Slave Interface: ens35
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:88:a6:67
Slave queue ID: 0Slave Interface: ens39
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:88:a6:71
Slave queue ID: 0

Linux 服务器配置网卡绑定(bonding)详解相关推荐

  1. suse linux双网卡绑定,suse linux双网卡绑定设置详解

    <suse linux双网卡绑定设置详解>由会员分享,可在线阅读,更多相关<suse linux双网卡绑定设置详解(2页珍藏版)>请在人人文库网上搜索. 1.suse linu ...

  2. Linux双网卡绑定bond详解

    Linux双网卡绑定bond详解 bond 网卡bond是通过多张网卡绑定为一个逻辑网卡,实现本地网卡的冗余,带宽扩容和负载均衡,在生产场景中是一种常用的技术 通过以下命令确定内核是否支持 bondi ...

  3. linux 双网卡绑定(bonding)实现负载均衡或故障转移

    linux 双网卡绑定(bonding)实现负载均衡或故障转移 我们在这介绍的Linux双网卡绑定实现就是使用两块网卡虚拟成为一块网卡,这个聚合起来的设备看起来是一个单独的以太网接口设备,通俗点讲就是 ...

  4. linux网卡详解,Linux系统网卡设图文详解

    这篇文章主要介绍了Linux系统网卡的设置教程,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 由于做了虚拟机的克隆,发现克隆机和被克隆机的MAC地址相同了,下面我将要介绍一下linux中网卡的配置 ...

  5. linux更换网卡不识别_详解Linux双网卡绑定脚本的方法示例

    概述 linux运维及配置工作中,常常会用到双网卡绑定,少数几台服务器的配置还好,如果是需要配置几十甚至上百台,难免会枯燥乏味,易于出错,我编写了这个双网卡绑定的辅助脚本,可傻瓜式地完成linux双网 ...

  6. Linux网卡配置文件-参数详解

    Linux网卡配置文件-参数详解 DEVICE=eth0 #指出网卡名称比如这个是eth0 NM_CONTROLLED=yes #network mamager的参数,实时生效,不需要重启,表示是否受 ...

  7. Linux多网卡绑定(bond)及网络组(team)

    Linux多网卡绑定(bond)及网络组(team)   很多时候,由于生产环境业务的特殊需求,我们需要对服务器的物理网卡实施特殊的配置,从而来满足不同业务场景下对服务器网络的特殊性要求.如高并发的网 ...

  8. Linux文件系统的目录结构详解(转)

    Linux文件系统的目录结构详解(转) 原文链接https://www.cnblogs.com/cyjaysun/p/4462325.html 一.前 言 文章对Linux下所有目录一一说明,对比较重 ...

  9. Linux 双网卡绑定测试

    Linux 双网卡绑定测试 先介绍一下情况,服务器A和服务器B都是CentOS 4.6的系统,现在要做HA Cluster,为了避免裂脑的发生,要提高心跳链路的可靠性,下图是现时的连接情况,服务器A的 ...

最新文章

  1. apache+tomcat 搭建负载均衡系统
  2. 你该认识这样的Linux_shell之循环控制
  3. MFC视图切换大全总结
  4. JavaSE项目之聊天室swing版
  5. MFC 线程的退出方法
  6. java excil表格开发_JAVA导出Excel电子表格的方法
  7. CISICO 路由器和交换机的基本配置命令
  8. python 文件服务器
  9. jenkins 自动化部署常用插件
  10. 网站运营直通车——7天精通SEO
  11. .chm文件打开方式,解决.CHM文件打不开或者打开空白
  12. 【C语言】创建各类三角形图案
  13. Unity学习:瓦片地图
  14. 直方图中bin的说明
  15. 开源3D图形渲染引擎OGRE学习笔记
  16. 【Python脚本】得王者金币,王者大佬快来带我飞
  17. 心电matlab,基于matlab检测心电信号
  18. oracle rfs进程过多,oracle 11g data guard 中RFS、MRP进程的说明
  19. IMX6ULL - 移植uboot-imx_v2020.04_5.4.70_2.3.0
  20. 高级软件工程学习总结

热门文章

  1. 2021-HUASACM第二周周练题解
  2. 湖南大学21夏训练三15.公交系统
  3. 以前做的一种特殊的平衡车----三轮球上平衡车
  4. nginx lua 调试 - 死磕
  5. NDK开发使用addr2line定位到错误代码行
  6. mysql 二进制格式_解析MYSQL BINLOG 二进制格式(3)--QUERY_EVENT
  7. 在Python中,输出格式:%d , %6d , %-6d, %06d , %.6f的一些区分
  8. Oracle-DataGuard参数enabled_PDBs_on_standby禁用PDB同步
  9. 计算机网络从逻辑上是由终端系统和什么组成,计算机网络答案
  10. “Catch That Cow“