很多情況下我們都需要用到網路卡繫結這中情況,例如:大資料傳輸備份、網路卡冗餘。使用網路卡繫結可以提高網路的傳輸速度,並且還能保證網路安全性,做到網路卡的高可用,甚至可以節省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。
檢視當前網路卡繫結資訊。