针对centos(Linux)多网卡bond绑定模式及其操作

前端之家收集整理的这篇文章主要介绍了针对centos(Linux)多网卡bond绑定模式及其操作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

一、简介



二、模式

注*建议学之前先看这个文章

http://blog.51cto.com/sf1314/2071298

1、balance-rr

轮转策略:按照顺序轮流使用每个接口来发送和接收数据包,提高了负载均衡的能力,但是需要交换机的支持,因为该模式所有端口的mac地址相同,交换机不能识别多个一个Mac地址对应多个端口,所以需要做链路聚合 ----Ethernet Channel

mode=0

2、active-backup

主备策略:只使用其中一个网卡,当网卡损坏时激活另外的一个网卡

mode=1

3、balance-xor

平衡策略: 基于所选择的传送hash策略

mode=2

4、

广播策略:所有卡上都接收和发送报文,提高了容错性

mode=3

5、802.3ad

链路聚合模式

802.3ad策略: LACP 链路聚合模式,交换机得开启链路聚合,将两张网卡当做一张来使用,提高链路性能,需要交换机支持802.3ad 动态链路聚合和服务器硬件支持ethtool。

mode=4

6、balance-tlb

自适应传输负载均衡

不需要配置交换机。在每个网卡会根据上根据当前的负载情况来分配流量。如果一个网卡出现故障,那么另外一个网卡会接管故障网卡

mode=5

7、balance-alb

自适应负载均衡:包括balance-tlb,不需要另外配置交换机,接受负载均衡通过ARP协商实现

当本机发送ARP请求时,bonding驱动把对端的IP信息从ARP包中复制并保存下来,当ARP应答从对端到达 时,bonding驱动把它的硬件地址提取出来,并发起一个ARP应答给bond中的某个slave。使用ARP协商进行负载均衡的一个问题是:每次广播 ARP请求时都会使用bond的硬件地址,因此对端学习到这个硬件地址后,接收流量将会全部流向当前的slave。这个问题可以通过给所有的对端发送更新 (ARP应答)来解决,应答中包含他们独一无二的硬件地址,从而导致流量重新分布。当新的slave加入到bond中时,或者某个未激活的slave重新 激活时,接收流量也要重新分布。接收的负载被顺序地分布(round robin)在bond中最高速的slave上

当某个链路被重新接上,或者一个新的slave加入到bond中,接收流量在所有当前激活的slave中全部重新分配,通过使用指定的MAC地址给每个 client发起ARP应答。下面介绍的updelay参数必须被设置为某个大于等于switch(交换机)转发延时的值,从而保证发往对端的ARP应答 不会被switch(交换机)阻截。

mode=6

三、安装

准备 多网卡主机一台

网卡桥接

选择局域网内空闲ip地址一枚

[root@localhost~]#ipa
1:lo:<LOOPBACK,UP,LOWER_UP>mtu65536qdiscnoqueuestateUNKNOWN
link/loopback00:00:00:00:00:00brd00:00:00:00:00:00
inet127.0.0.1/8scopehostlo
valid_lftforeverpreferred_lftforever
inet6::1/128scopehost
valid_lftforeverpreferred_lftforever
2:eno16777736:<BROADCAST,MULTICAST,LOWER_UP>mtu1500qdiscpfifo_faststateUPqlen1000
link/ether00:0c:29:fd:1d:cfbrdff:ff:ff:ff:ff:ff
inet192.168.3.151/24brd192.168.3.255scopeglobaldynamiceno16777736
valid_lft258897secpreferred_lft258897sec
inet6fe80::20c:29ff:fefd:1dcf/64scopelink
valid_lftforeverpreferred_lftforever
3:eno33554984:<BROADCAST,LOWER_UP>mtu1500qdiscpfifo_faststateUPqlen1000
link/ether00:0c:29:fd:1d:d9brdff:ff:ff:ff:ff:ff
inet192.168.3.154/24brd192.168.3.255scopeglobaldynamiceno33554984
valid_lft258897secpreferred_lft258897sec
inet6fe80::20c:29ff:fefd:1dd9/64scopelink
valid_lftforeverpreferred_lftforever
4:eno50332208:<BROADCAST,LOWER_UP>mtu1500qdiscpfifo_faststateUPqlen1000
link/ether00:0c:29:fd:1d:e3brdff:ff:ff:ff:ff:ff
inet192.168.3.155/24brd192.168.3.255scopeglobaldynamiceno50332208
valid_lft258897secpreferred_lft258897sec
inet6fe80::20c:29ff:fefd:1de3/64scopelink
valid_lftforeverpreferred_lftforever

#查看硬件状态

[root@localhost~]#nmclidevicestatus
设备类型状态CONNECTION
eno16777736ethernet连接的eno16777736
eno33554984ethernet连接的有线连接1
eno50332208ethernet连接的有线连接2
loloopback未管理--

#查看linux是否支持Bond

[root@localhost~]#modinfobondingfilename:
/lib/modules/3.10.0-229.el7.x86_64/kernel/drivers/net/bonding/bonding.ko
alias:rtnl-link-bond
author:ThomasDavis,tadavis@lbl.govandmanyothers
description:EthernetChannelBondingDriver,v3.7.1
version:3.7.1
license:GPL
..........
..........

#以上信息反映机器支持bond

#本人选取其中两种方式来制作bond绑定,

一种是active-backup,

另外一种选择balance-tlb,并且做相应测试

方式1:nmcli方式

使用nmcli命令来创建bond卡

nmcli connection add type bond ifname bond1 mode 1

nmcli connection add type bond-slave ifname eno33554984 master bond1

nmcli connection add type bond-slave ifname eno50332208 master bond1

nmcli connection add type bond-slave ifnameeno16777736master bond1

#connection add 添加新的连接

#con-name 连接名称 暂时没使用

#type 设备类型

#ifname 接口设备名称

#master 指定该硬件的master

# 执行完成以上命令后会生成以下文件

[root@localhost~]#cd/etc/sysconfig/network-scripts/
[root@localhostnetwork-scripts]#ll
总用量248
-rw-r--r--.1rootroot3283月2918:08ifcfg-bond-bond1
-rw-r--r--.1rootroot1373月2918:08ifcfg-bond-slave-eno16777736
-rw-r--r--.1rootroot1373月2918:08ifcfg-bond-slave-eno33554984
-rw-r--r--.1rootroot1373月2918:08ifcfg-bond-slave-eno50332208

#修改已经生成配置文件

[root@localhostnetwork-scripts]#vimifcfg-bond-bond1
DEVICE=bond1
BONDING_OPTS=mode=active-backup
TYPE=Bond
BONDING_MASTER=yes
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=bond-bond1
UUID=5ed04865-5802-4fd5-9d80-917d1fadae70ON
BOOT=yes
IPADDR=192.168.3.200
PREFIX=24
GATEWAY=192.168.3.254
DNS1=192.168.30.202

#重启网卡

[root@localhostnetwork-scripts]#systemctlrestartnetwork


#查看网络和路由状态

[root@localhost~]#ipa
1:lo:<LOOPBACK,SLAVE,LOWER_UP>mtu1500qdiscpfifo_fastmasterbond1stateUPqlen1000
link/ether
00:0c:29:fd:1d:cf
brdff:ff:ff:ff:ff:ff
3:eno33554984:<BROADCAST,LOWER_UP>mtu1500qdiscpfifo_fastmasterbond1stateUPqlen1000
link/ether00:0c:29:fd:1d:cfbrdff:ff:ff:ff:ff:ff
4:eno50332208:<BROADCAST,LOWER_UP>mtu1500qdiscpfifo_fastmasterbond1stateUPqlen1000
link/ether00:0c:29:fd:1d:cfbrdff:ff:ff:ff:ff:ff
6:bond1:<BROADCAST,MASTER,LOWER_UP>mtu1500qdiscnoqueuestateUP
link/ether00:0c:29:fd:1d:cfbrdff:ff:ff:ff:ff:ff
inet192.168.3.200/24brd192.168.3.255scopeglobalbond1
valid_lftforeverpreferred_lftforever
inet6fe80::20c:29ff:fefd:1dcf/64scopelink
valid_lftforeverpreferred_lftforever


[root@localhost~]#iproute
defaultvia192.168.3.254devbond1protostaticmetric300
192.168.3.0/24devbond1protokernelscopelinksrc192.168.3.200metric300


[root@localhost~]#cat/proc/net/bonding/bond1
EthernetChannelBondingDriver:v3.7.1(April27,2011)

BondingMode:fault-tolerance(active-backup)
PrimarySlave:None
CurrentlyActiveSlave:eno16777736#这为当前打开的网卡
MIIStatus:up
MIIPollingInterval(ms):100
UpDelay(ms):0
DownDelay(ms):0

SlaveInterface:eno16777736
MIIStatus:up
Speed:1000Mbps
Duplex:full
LinkFailureCount:0
PermanentHWaddr:00:0c:29:fd:1d:cf
SlavequeueID:0

SlaveInterface:eno33554984
MIIStatus:up
Speed:1000Mbps
Duplex:full
LinkFailureCount:0
PermanentHWaddr:00:0c:29:fd:1d:d9
SlavequeueID:0

SlaveInterface:eno50332208
MIIStatus:up
Speed:1000Mbps
Duplex:full
LinkFailureCount:0
PermanentHWaddr:00:0c:29:fd:1d:e3
SlavequeueID:0

#测试


#三张网卡随意关闭任意两张

ifdown em1


#关闭掉两张网卡后,会有一次断点,切换网卡的过程

#网卡已经切换为eno50332208

[root@localhost~]#cat/proc/net/bonding/bond1
EthernetChannelBondingDriver:v3.7.1(April27,2011)

BondingMode:fault-tolerance(active-backup)
PrimarySlave:None
CurrentlyActiveSlave:eno50332208
MIIStatus:up
MIIPollingInterval(ms):100
UpDelay(ms):0
DownDelay(ms):0

SlaveInterface:eno16777736
MIIStatus:down
Speed:Unknown
Duplex:Unknown
LinkFailureCount:1
PermanentHWaddr:00:0c:29:fd:1d:cf
SlavequeueID:0

SlaveInterface:eno33554984
MIIStatus:down
Speed:Unknown
Duplex:Unknown
LinkFailureCount:1
PermanentHWaddr:00:0c:29:fd:1d:d9
SlavequeueID:0

SlaveInterface:eno50332208
MIIStatus:up
Speed:1000Mbps
Duplex:fullLinkFailureCount:0
PermanentHWaddr:00:0c:29:fd:1d:e3
SlavequeueID:0


#实验完成

#删除原有配置

#清除bond网卡配置

[root@localhost~]#cd/etc/sysconfig/network-scripts/
[root@localhostnetwork-scripts]#rm-rfifcfg-bond-*

#显示所有活动的连接

[root@localhostnetwork-scripts]#nmcliconnectionshow
名称UUID类型设备
有线连接24013b28a-31dd-43b0-9b32-6582a20353f9802-3-ethernet--
有线连接19cca4859-5085-4cb3-a660-4664fac689c5802-3-ethernet--
eno167777365dcd1c25-9d8b-4c0f-967c-cd0b250ff929802-3-ethernet--
bond-slave-eno1677773624c73fe2-9c55-4202-92f3-d4ff259a6d84802-3-etherneteno16777736
bond-slave-eno50332208ea727513-602e-450e-ad36-dd15cc5d2e82802-3-etherneteno50332208
bond-slave-eno33554984ca74b313-4a4e-44e3-bb5b-84d5dfa1d3aa802-3-etherneteno33554984
bond-bond15ed04865-5802-4fd5-9d80-917d1fadae70bondbond1

#删除网卡配置连接

[root@localhostnetwork-scripts]#nmclicondelbond-slave-eno50332208
[root@localhostnetwork-scripts]#nmclicondelbond-slave-eno33554984

[root@localhostnetwork-scripts]#cat/proc/net/bonding/bond1
EthernetChannelBondingDriver:v3.7.1(April27,2011)

BondingMode:fault-tolerance(active-backup)
PrimarySlave:NoneCurrently
ActiveSlave:eno16777736
MIIStatus:up
MIIPollingInterval(ms):100Up
Delay(ms):0
DownDelay(ms):0
SlaveInterface:eno16777736

MIIStatus:up
Speed:1000Mbps
Duplex:full
LinkFailureCount:1
PermanentHWaddr:00:0c:29:fd:1d:cf
SlavequeueID:0


[root@localhostnetwork-scripts]#nmclicondelbond-slave-eno16777736

[root@localhostnetwork-scripts]#nmclicondelbond-bond1

网卡恢复

#方式2:cli方式

文件方式配置Bond

#备份原有网卡配置文件

[root@localhost~]#mkdir-p/data/backup/network
[root@localhost~]#cd/etc/sysconfig/network-scripts/
[root@localhost~]#cpifcfg-eno*/data/backup/network/

#因为是新加入的卡,所以没有配置文件,但是硬件信息中是可以查到的

[root@localhostnetwork-scripts]#nmclidevicestatus
设备类型状态CONNECTION
eno16777736ethernet连接的eno16777736
eno33554984ethernet连接的有线连接1
eno50332208ethernet连接的有线连接2
loloopback未管理--


[root@localhostnetwork-scripts]#ll
总用量236
-rw-r--r--.1rootroot2958月252015ifcfg-eno16777736
-rw-r--r--.1rootroot2953月2919:13ifcfg-eno33554984
[root@localhostnetwork-scripts]#cpifcfg-eno16777736ifcfg-eno33554984


[root@localhostnetwork-scripts]#vimifcfg-bond5
DEVICE=bond5
BONDING_OPTS="mode=balance-tlb"
TYPE=BondBONDING_MASTER=yes
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
NAME=bond5
ONBOOT=yes
IPADDR=192.168.3.200
PREFIX=24
GATEWAY=192.168.3.254
DNS1=192.168.30.202

[root@localhostnetwork-scripts]#vimifcfg-eno16777736
TYPE=Ethernet
#BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=yes
NAME=eno16777736
DEVICE=eno16777736
ONBOOT=yes
MASTER=bond5
SLAVE=yes


[root@localhostnetwork-scripts]#vimifcfg-eno33554984
TYPE=Ethernet
#BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=yes
NAME=eno33554984
DEVICE=eno33554984
ONBOOT=yes
MASTER=bond5
SLAVE=yes

[root@localhostnetwork-scripts]#vimifcfg-eno50332208
TYPE=Ethernet
#BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=yes
NAME=eno50332208
DEVICE=eno50332208
ONBOOT=yes
MASTER=bond5
SLAVE=yes

[root@localhost~]#nmcliconnectionshow
名称UUID类型设备
eno50332208d2665055-8e83-58f1-e9e3-49a5fb133641802-3-etherneteno50332208
eno1677773613756690-ac77-b776-4fc1-f5535cee6f16802-3-etherneteno16777736
有线连接24013b28a-31dd-43b0-9b32-6582a20353f9802-3-ethernet--
有线连接19cca4859-5085-4cb3-a660-4664fac689c5802-3-ethernet--
eno33554984fb67dbad-ec81-39b4-42b1-ebf975c3ff13802-3-etherneteno33554984
bond5d1a49a62-2f2d-2e41-a63d-be3a81b6a2fbbondbond5

[root@localhost~]#ipa
1:lo:<LOOPBACK,LOWER_UP>mtu1500qdiscpfifo_fastmasterbond5stateUPqlen1000
link/ether00:0c:29:fd:1d:cfbrdff:ff:ff:ff:ff:ff
3:eno33554984:<BROADCAST,LOWER_UP>mtu1500qdiscpfifo_fastmasterbond5stateUPqlen1000
link/ether00:0c:29:fd:1d:d9brdff:ff:ff:ff:ff:ff
4:eno50332208:<BROADCAST,LOWER_UP>mtu1500qdiscpfifo_fastmasterbond5stateUPqlen1000
link/ether00:0c:29:fd:1d:e3brdff:ff:ff:ff:ff:ff
7:bond5:<BROADCAST,LOWER_UP>mtu1500qdiscnoqueuestateUP
link/ether00:0c:29:fd:1d:cfbrdff:ff:ff:ff:ff:ff
inet192.168.3.200/24brd192.168.3.255scopeglobalbond5
valid_lftforeverpreferred_lftforever
inet6fe80::a81d:6bff:feac:5cd6/64scopelink
valid_lftforeverpreferred_lftforever

#个人建议各位跟balance-rr模式做个对比

[root@localhost~]#cat/proc/net/bonding/bond5
EthernetChannelBondingDriver:v3.7.1(April27,2011)

BondingMode:transmitloadbalancing
PrimarySlave:None
CurrentlyActiveSlave:eno16777736
MIIStatus:up
MIIPollingInterval(ms):100
UpDelay(ms):0
DownDelay(ms):0

SlaveInterface:eno16777736
MIIStatus:up
Speed:1000Mbps
Duplex:full
LinkFailureCount:0
PermanentHWaddr:00:0c:29:fd:1d:cf
SlavequeueID:0

SlaveInterface:eno33554984
MIIStatus:upSpeed:1000Mbps
Duplex:full
LinkFailureCount:0
PermanentHWaddr:00:0c:29:fd:1d:d9
SlavequeueID:0

SlaveInterface:eno50332208
MIIStatus:up
Speed:1000Mbps
Duplex:full
LinkFailureCount:0
PermanentHWaddr:00:0c:29:fd:1d:e3
SlavequeueID:0

注*模式选择有以下这些

balance-rr(0)

active-backup(1)

balance-xor(2)

broadcast(3)

802.3ad (4)

balance-tlb(5)

balance-alb (6)

原文链接:https://www.f2er.com/centos/374707.html

猜你在找的CentOS相关文章