Centos7下⽹卡bonding配置之mode4
⼀、bonding技术
bonding(绑定)是⼀种linux系统下的⽹卡绑定技术,可以把服务器上n个物理⽹卡在系统内部抽象(绑定)成⼀个逻辑上的⽹卡,能够提升⽹络吞吐量、实现⽹络冗余、负载等功能,有很多优势。
bonding技术是linux系统内核层⾯实现的,它是⼀个内核模块(驱动)。使⽤它需要系统有这个模块, 我们可以modinfo命令查看下这个模块的信息, ⼀般来说都⽀持. modinfo bonding
filename: /lib/modules/3.10.0-957.1.3.el7.x86_64/kernel/drivers/net/bonding/
author: Thomas Davis, v and many others
description: Ethernet Channel Bonding Driver, v3.7.1
version: 3.7.1
license: GPL
alias: rtnl-link-bond
retpoline: Y
rhelversion: 7.6
srcversion: 120C91D145D649655185C69
depends:
intree: Y
vermagic: 3.10.0-957.1.3.el7.x86_64 SMP mod_unload modversions
signer: CentOS Linux kernel signing key
sig_key: E7:CE:F3:61:3A:9B:8B:D0:12:FA:E7:49:82:72:15:9B:B1:87:9C:65
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; 0for off, 1for on (default) (int)
parm: mode:Mode of operation; 0for balance-rr, 1for active-backup, 2for balance-xor, 3for broadcast, 4for802.3ad, 5for balance-tlb, 6for balance-alb (charp)
parm: primary:Primary network device to use (charp)
parm: primary_reselect:Reselect primary slave once it comes up; 0for always (default), 1for only if speed of primary is better, 2for only on active slave failure (charp)
parm: lacp_rate:LACPDU tx rate to request from 802.3ad partner; 0for slow, 1for fast (charp)
parm: ad_select:802.3ad aggregation selection logic; 0for stable (default), 1for bandwidth, 2for count (charp)
parm: min_links:Minimum number of available links before turning on carrier (int)
parm: xmit_hash_policy:balance-alb, balance-tlb, balance-xor, 802.3ad hashing method; 0for layer 2 (default), 1for layer 3+4, 2for layer 2+3, 3for encap layer 2+3, 4for encap layer 3+4 (charp) parm: arp_interval:arp interval in milliseconds (int)
parm: arp_ip_target:arp targets form (array of charp)
parm: arp_validate:validate src/dst of ARP probes; 0for none (default), 1for active, 2for backup, 3for all (charp)
parm: arp_all_targets:fail on any/all arp targets timeout; 0for any (default), 1for all (charp)
parm: fail_over_mac:For active-backup, do not set all slaves to the same MAC; 0for none (default), 1for active, 2for follow (charp)
parm: all_slaves_active:Keep all frames received on an interface by setting active flag for all slaves; 0for never (default), 1for 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; 0for 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)
bonding的七种⼯作模式:
bonding技术提供了七种⼯作模式,在使⽤的时候需要指定⼀种,每种有各⾃的优缺点.
1. balance-rr (mode=0) 默认, 有⾼可⽤ (容错) 和负载均衡的功能, 需要交换机的配置,每块⽹卡轮询发包 (流量分发⽐较均衡).
2. active-backup (mode=1) 只有⾼可⽤ (容错) 功能, 不需要交换机配置, 这种模式只有⼀块⽹卡⼯作, 对外只有⼀个mac地址。缺点是端⼝利⽤率⽐较低
3. balance-xor (mode=2) 不常⽤
4. broadcast (mode=3) 不常⽤
5. 802.3ad (mode=4) IEEE 802.3ad 动态链路聚合,需要交换机配置
6. balance-tlb (mode=5) 不常⽤
7. balance-alb (mode=6) 有⾼可⽤ ( 容错 )和负载均衡的功能,不需要交换机配置 (流量分发到每个接⼝不是特别均衡)。
⼆、Centos7配置bonding
系统: Centos7.5
⽹卡: ifcfg-eno49、ifcfg-eno50
bond0:10.162.97.41
负载模式: mode4(802.3ad 动态链路聚合)
1、关闭和停⽌NetworkManager服务
systemctl stop NetworkManager.service # 停⽌NetworkManager服务
systemctl disable NetworkManager.service # 禁⽌开机启动NetworkManager服务
ps: ⼀定要关闭,不关会对做bonding有⼲扰
2、加载bonding模块
modprobe bonding
没有提⽰说明加载成功, 如果出现modprobe: ERROR: could not insert 'bonding': Module already in kernel说明你已经加载了这个模块, 就不⽤管了
你也可以使⽤lsmod | grep bonding查看模块是否被加载
lsmod | grep bonding
bonding 136705 0
3、创建基于bond0接⼝的配置⽂件
vim /etc/sysconfig/network-scripts/ifcfg-bond0
修改成如下,根据你的情况:
DEVICE=bond0
TYPE=Bond
BOOTPROTO=none
ONBOOT=yes
IPADDR=10.162.97.41
NETMASK=255.255.255.0
GATEWAY=10.162.97.253
DNS1=10.1.0.62
BONDING_MASTER=yes
BONDING_OPTS="mode=4 miimon=100"
上⾯的BONDING_OPTS="mode=4 miimon=100" 表⽰这⾥配置的⼯作模式是802.3ad 动态链路聚合, miimon表⽰监视⽹络链接的频度 (毫秒), 我们设置的是100毫秒,根据你的需求也可以指定mode成其它的负载模式。
4、修改ifcfg-eno49接⼝的配置⽂件
vim /etc/sysconfig/network-scripts/ifcfg-eno49
修改成如下:
TYPE=Ethernet
PROXY_METHOD=none
dBROWSER_ONLY=no
BOOTPROTO=static
DEFROUT=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eno49
UUID=29d2526a-2eec-4a5e-8190-3d1fe5e04f57
DEVICE=eno49.97
ONBOOT=yes
MASTER=bond0
centos vim命令SLAVE=yes
VLAN=yes //此处配置VLAN,因为所处交换机端⼝为Trunk
TYPE=Vlan
VLAN_ID=97
5、修改ifcfg-eno50接⼝的配置⽂件
vim /etc/sysconfig/network-scripts/ifcfg-eno50
修改成如下:
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eno50
UUID=dae63958-841f-4666-9308-28bda92dc66f
DEVICE=eno50.97
ONBOOT=yes
MASTER=bond0
SLAVE=yes
VLAN=yes
TYPE=Vlan
VLAN_ID=97
6、测试
重启⽹络服务
systemctl restart network
查看bond0的接⼝状态信息 ( 如果报错说明没做成功,很有可能是bond0接⼝没起来)
# cat /proc/net/bonding/bond0
[root@bogon ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: IEEE 802.3ad Dynamic link aggregation //绑定模式: 当前是ald模式(mode 4), 也就是802.3ad 动态链路聚合
Transmit Hash Policy: layer2 (0)
MII Status: up //接⼝状态: up(MII是Media Independent Interface简称, 接⼝的意思)
MII Polling Interval (ms): 100 // 接⼝轮询的时间隔(这⾥是100ms)
Up Delay (ms): 0
Down Delay (ms): 0
802.3ad info //802.3ad 信息
LACP rate: slow
Min links: 0
Aggregator selection policy (ad_select): stable
System priority: 65535
System MAC address: 20:67:7c:1f:15:f0
Active Aggregator Info:
Aggregator ID: 1
Number of ports: 1
Actor Key: 15
Partner Key: 1
Partner Mac Address: 00:00:00:00:00:00
Slave Interface: eno49.97 // 备接⼝: eno49.97
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 20:67:7c:1f:15:f0
Slave queue ID: 0
Aggregator ID: 1
Actor Churn State: monitoring
Partner Churn State: monitoring
Actor Churned Count: 0
Partner Churned Count: 0
details actor lacp pdu:
system priority: 65535
system mac address: 20:67:7c:1f:15:f0
port key: 15
port priority: 255
port number: 1
port state: 197
details partner lacp pdu:
system priority: 65535
system mac address: 00:00:00:00:00:00
oper key: 1
port priority: 255
port number: 1
port state: 3
Slave Interface: eno50.97 // 备接⼝: eno50.97
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 20:67:7c:1f:15:f8
Slave queue ID: 0
Aggregator ID: 2
Actor Churn State: monitoring
Partner Churn State: monitoring
Actor Churned Count: 0
Partner Churned Count: 0
details actor lacp pdu:
system priority: 65535
system mac address: 20:67:7c:1f:15:f0
port key: 15
port priority: 255
port number: 2
port state: 197
details partner lacp pdu:
system priority: 65535
system mac address: 00:00:00:00:00:00
oper key: 1
port priority: 255
port number: 1
port state: 3
通过ifconfig命令查看下⽹络的接⼝信息
# ifconfig
[root@bogon ~]# ifconfig
bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST> mtu 1500 inet 10.162.97.41 netmask 255.255.255.0 broadcast 10.162.97.255
ether 20:67:7c:1f:15:f0 txqueuelen 1000 (Ethernet)
RX packets 22039 bytes 1436892 (1.3 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 6687 bytes 678240 (662.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eno49: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 20:67:7c:1f:15:f0 txqueuelen 1000 (Ethernet)
RX packets 16645 bytes 1894648 (1.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 7228 bytes 833488 (813.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 16 memory 0x96000000-967fffff
eno50: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 20:67:7c:1f:15:f8 txqueuelen 1000 (Ethernet)
RX packets 11163 bytes 1107408 (1.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 791 bytes 119264 (116.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 17 memory 0x95000000-957fffff
eno51: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 20:67:7c:1f:15:f1 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 17 memory 0x94000000-947fffff
eno52: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 20:67:7c:1f:15:f9 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 18 memory 0x93000000-937fffff
eno49.97: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500
ether 20:67:7c:1f:15:f0 txqueuelen 1000 (Ethernet)
RX packets 13004 bytes 1017228 (993.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 6404 bytes 658552 (643.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eno50.97: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500
ether 20:67:7c:1f:15:f0 txqueuelen 1000 (Ethernet)
RX packets 7632 bytes 351072 (342.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2 bytes 180 (180.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens2f0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 48:df:37:36:a9:24 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device memory 0xc8300000-c83fffff
ens2f1: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 48:df:37:36:a9:25 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device memory 0xc8200000-c82fffff
ens2f2: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 48:df:37:36:a9:26 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device memory 0xc8100000-c81fffff
ens2f3: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 48:df:37:36:a9:27 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device memory 0xc8000000-c80fffff
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 16 bytes 1356 (1.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 16 bytes 1356 (1.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
测试⽹络⾼可⽤, 我们拔掉其中⼀根⽹线进⾏测试, 结论是:
在本次mode=6模式下丢包1个, 恢复⽹络时( ⽹络插回去 ) 丢包在5-6个左右,说明⾼可⽤功能正常但恢复的时候丢包会⽐较多
测试mode=1模式下丢包1个,恢复⽹络时( ⽹线插回去 ) 基本上没有丢包,说明⾼可⽤功能和恢复的时候都正常
mode6这种负载模式除了故障恢复的时候有丢包之外其它都挺好的,如果能够忽略这点的话可以这种模式;⽽mode1故障的切换和恢复都很快,基本没丢包和延时。但端⼝利⽤率⽐较低,因为这种主备的模式只有⼀张⽹卡在⼯作.
引⾃于:
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论