很多情况下我们都需要用到网卡绑定这中情况,例如:大数据传输备份、网卡冗余。使用网卡绑定可以提高网络的传输速度,并且还能保证网络安全性,做到网卡的高可用,甚至可以节省IP地址。
网卡绑定模式
- mode=0:轮询模式
链路的负载均衡,传输带宽增加,具有容错性,当其中一条链路有故障时可以自动切换到正常链路。
- mode=1:主备模式
一块网卡处于活跃状态,另一块处于备份状态,时刻检查活跃网卡的使用情况,当网卡出现故障时,备份网卡自动切换为主网卡。
- mode=2:平衡策略
基于指定的传输HASH策略传输数据包。对负载和容错能力有提升。
- mode=3:广播策略
在每个slave接口上传输每个数据包,此模式提供了容错能力。
- mode=4:动态链路聚合
创建聚合组,根据802.3ad规范将多个slave工作在同一个激活的聚合体下。
- mode=5:适配器传输负载均衡
根据每个slave的负载情况选择slave进行发送,接收时使用当前轮到的slave。该模式要求slave接口的网络设备驱动有某种ethtool支持;而且ARP监控不可用。
- mode=6:适配器适应性负载均衡
在适配器传输负载均衡的基础上增加了接收负载均衡,接收负载均衡通过ARP协商实现。
配置网卡绑定
查看当前内核是否支持bonding
modinfo bonding
filename: /lib/modules/3.10.0-693.el7.x86_64/kernel/drivers/net/bonding/bonding.ko.xz
author: Thomas Davis, tadavis@lbl.gov and many others
description: Ethernet Channel Bonding Driver, v3.7.1
version: 3.7.1
license: GPL
alias: rtnl-link-bond
rhelversion: 7.4
srcversion: 3F7A5A65495F3B40F22AEFD
depends:
intree: Y
vermagic: 3.10.0-693.el7.x86_64 SMP mod_unload modversions
signer: CentOS Linux kernel signing key
sig_key: DA:18:7D:CA:7D:BE:53:AB:05:BD:13:BD:0C:4E:21:F4:22:B6:A4:9C
sig_hashalgo: sha256
parm: max_bonds:Max number of bonded devices (int)
parm: tx_queues:Max number of transmit queues (default = 16) (int)
parm: num_grat_arp:Number of peer notifications to send on failover event (alias of num_unsol_na) (int)
parm: num_unsol_na:Number of peer notifications to send on failover event (alias of num_grat_arp) (int)
parm: miimon:Link check interval in milliseconds (int)
parm: updelay:Delay before considering link up, in milliseconds (int)
parm: downdelay:Delay before considering link down, in milliseconds (int)
parm: use_carrier:Use netif_carrier_ok (vs MII ioctls) in miimon; 0 for off, 1 for on (default) (int)
parm: mode:Mode of operation; 0 for balance-rr, 1 for active-backup, 2 for balance-xor, 3 for broadcast, 4 for 802.3ad, 5 for balance-tlb, 6 for balance-alb (charp)
parm: primary:Primary network device to use (charp)
parm: primary_reselect:Reselect primary slave once it comes up; 0 for always (default), 1 for only if speed of primary is better, 2 for only on active slave failure (charp)
parm: lacp_rate:LACPDU tx rate to request from 802.3ad partner; 0 for slow, 1 for fast (charp)
parm: ad_select:802.3ad aggregation selection logic; 0 for stable (default), 1 for bandwidth, 2 for count (charp)
parm: min_links:Minimum number of available links before turning on carrier (int)
parm: xmit_hash_policy:balance-xor and 802.3ad hashing method; 0 for layer 2 (default), 1 for layer 3+4, 2 for layer 2+3, 3 for encap layer 2+3, 4 for encap layer 3+4 (charp)
parm: arp_interval:arp interval in milliseconds (int)
parm: arp_ip_target:arp targets in n.n.n.n form (array of charp)
parm: arp_validate:validate src/dst of ARP probes; 0 for none (default), 1 for active, 2 for backup, 3 for all (charp)
parm: arp_all_targets:fail on any/all arp targets timeout; 0 for any (default), 1 for all (charp)
parm: fail_over_mac:For active-backup, do not set all slaves to the same MAC; 0 for none (default), 1 for active, 2 for follow (charp)
parm: all_slaves_active:Keep all frames received on an interface by setting active flag for all slaves; 0 for never (default), 1 for always. (int)
parm: resend_igmp:Number of IGMP membership reports to send on link failure (int)
parm: packets_per_slave:Packets to send per slave in balance-rr mode; 0 for a random slave, 1 packet per slave (default), >1 packets per slave. (int)
parm: lp_interval:The number of seconds between instances where the bonding driver sends learning packets to each slaves peer switch. The default is 1. (uint)
modprobe bonding
lssmod |grep "bonding"
bonding 145728 0
以上信息表名,我们的内核已经支持bonding,后续直接配置即可,目前大多数的操作系统都已经支持网卡绑定了,我们这里就不在过多的描述不支持该操作的服务器如何进行安装了,如果不支持,网上搜个博客看看吧。
操作前规划
物理接口 | 绑定后的虚拟接口 |
---|---|
ens192/ens224 | bond0 |
当前双网卡的速率都是万兆网。
修改物理网卡配置文件
vim /etc/sysconfig/network-scripts/ifcfg-ens224
DEVICE=ens224
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
vim /etc/sysconfig/network-scripts/ifcfg-ens192
DEVICE=ens192
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
配置虚拟网卡配置文件
vim /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
BONDING_OPTS="mode=0 miimon=100"
BOOTPROTO=none
ONBOOT=yes
BROADCAST=10.240.1.255
IPADDR=10.240.1.1
NETMASK=255.255.0.0
NETWORK=10.240.0.0
USERCTL=no
修改modprobe相关文件
vim /etc/modprobe.d/bonding.conf
alias bond0 bonding
options bonding mode=0 miimon=100
miimon:监控网络链接的频率,单位为毫秒。
mode:配置绑定选用模式。
systemctl restart network
查看绑定后信息
我们可以发现绑定的虚拟网卡已经启动,并且传输速率为20000Mb/S。
查看当前网卡绑定信息。