首页 > 代码库 > bond绑定模式与操作(centos7)

bond绑定模式与操作(centos7)

一、简介

 

 

二、模式

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

        http://blog.csdn.net/galdys/article/details/7506495

     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 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:fd:1d:cf brd ff:ff:ff:ff:ff:ff
    inet 192.168.3.151/24 brd 192.168.3.255 scope global dynamic eno16777736
       valid_lft 258897sec preferred_lft 258897sec
    inet6 fe80::20c:29ff:fefd:1dcf/64 scope link
       valid_lft forever preferred_lft forever
3: eno33554984: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:fd:1d:d9 brd ff:ff:ff:ff:ff:ff
    inet 192.168.3.154/24 brd 192.168.3.255 scope global dynamic eno33554984
       valid_lft 258897sec preferred_lft 258897sec
    inet6 fe80::20c:29ff:fefd:1dd9/64 scope link
       valid_lft forever preferred_lft forever
4: eno50332208: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:fd:1d:e3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.3.155/24 brd 192.168.3.255 scope global dynamic eno50332208
       valid_lft 258897sec preferred_lft 258897sec
    inet6 fe80::20c:29ff:fefd:1de3/64 scope link
       valid_lft forever preferred_lft forever
[root@localhost ~]#

 

 

#查看硬件状态

[root@localhost ~]#  nmcli device status
设备         类型      状态    CONNECTION  
eno16777736  ethernet  连接的  eno16777736
eno33554984  ethernet  连接的  有线连接 1  
eno50332208  ethernet  连接的  有线连接 2  
lo           loopback  未管理  --         

 

 

#查看linux是否支持Bond

[root@localhost ~]# modinfo bonding
filename:       /lib/modules/3.10.0-229.el7.x86_64/kernel/drivers/net/bonding/bonding.ko
alias:          rtnl-link-bond
author:         Thomas Davis, tadavis@lbl.gov and many others
description:    Ethernet Channel Bonding Driver, 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 ifname eno16777736 master bond1

 

#connection add   添加新的连接

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

#type   设备类型

#ifname    接口设备名称

#master  指定该硬件的master

 



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

[root@localhost ~]# cd /etc/sysconfig/network-scripts/

[root@localhost network-scripts]# ll
总用量 248
-rw-r--r--. 1 root root   328 3月  29 18:08 ifcfg-bond-bond1
-rw-r--r--. 1 root root   137 3月  29 18:08 ifcfg-bond-slave-eno16777736
-rw-r--r--. 1 root root   137 3月  29 18:08 ifcfg-bond-slave-eno33554984
-rw-r--r--. 1 root root   137 3月  29 18:08 ifcfg-bond-slave-eno50332208

 

 

#修改已经生成的配置文件

[root@localhost network-scripts]# vim ifcfg-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-917d1fadae70
ONBOOT=yes
IPADDR=192.168.3.200
PREFIX=24
GATEWAY=192.168.3.254
DNS1=192.168.30.202

 

 

#重启网卡

[root@localhost network-scripts]# systemctl restart network

 

#查看网络和路由状态

[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond1 state UP qlen 1000
    link/ether 00:0c:29:fd:1d:cf brd ff:ff:ff:ff:ff:ff
3: eno33554984: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond1 state UP qlen 1000
    link/ether 00:0c:29:fd:1d:cf brd ff:ff:ff:ff:ff:ff
4: eno50332208: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond1 state UP qlen 1000
    link/ether 00:0c:29:fd:1d:cf brd ff:ff:ff:ff:ff:ff
6: bond1: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
    link/ether 00:0c:29:fd:1d:cf brd ff:ff:ff:ff:ff:ff
    inet 192.168.3.200/24 brd 192.168.3.255 scope global bond1
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fefd:1dcf/64 scope link
       valid_lft forever preferred_lft forever

 

[root@localhost ~]# ip route
default via 192.168.3.254 dev bond1  proto static  metric 300
192.168.3.0/24 dev bond1  proto kernel  scope link  src 192.168.3.200  metric 300

 

 

[root@localhost ~]# 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: eno16777736
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eno16777736
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:fd:1d:cf
Slave queue ID: 0

Slave Interface: eno33554984
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:fd:1d:d9
Slave queue ID: 0

Slave Interface: eno50332208
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:fd:1d:e3
Slave queue ID: 0


 

#标红为当前打开的网卡

 

#测试

技术分享

 

 

 

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

技术分享

 

 

 

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

技术分享

 

#网卡已经切换为eno50332208

[root@localhost ~]# 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: eno50332208
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eno16777736
MII Status: down
Speed: Unknown
Duplex: Unknown
Link Failure Count: 1
Permanent HW addr: 00:0c:29:fd:1d:cf
Slave queue ID: 0

Slave Interface: eno33554984
MII Status: down
Speed: Unknown
Duplex: Unknown
Link Failure Count: 1
Permanent HW addr: 00:0c:29:fd:1d:d9
Slave queue ID: 0

Slave Interface: eno50332208
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:fd:1d:e3
Slave queue ID: 0


#实验完成

 

#删除原有配置

 

#清除bond网卡配置 

[root@localhost ~]# cd /etc/sysconfig/network-scripts/

[root@localhost network-scripts]# rm -rf ifcfg-bond-*


 

 

#显示所有活动的连接

[root@localhost network-scripts]# nmcli connection show
名称                    UUID                                  类型            设备       
有线连接 2              4013b28a-31dd-43b0-9b32-6582a20353f9  802-3-ethernet  --         
有线连接 1              9cca4859-5085-4cb3-a660-4664fac689c5  802-3-ethernet  --         
eno16777736             5dcd1c25-9d8b-4c0f-967c-cd0b250ff929  802-3-ethernet  --         
bond-slave-eno16777736  24c73fe2-9c55-4202-92f3-d4ff259a6d84  802-3-ethernet  eno16777736
bond-slave-eno50332208  ea727513-602e-450e-ad36-dd15cc5d2e82  802-3-ethernet  eno50332208
bond-slave-eno33554984  ca74b313-4a4e-44e3-bb5b-84d5dfa1d3aa  802-3-ethernet  eno33554984
bond-bond1              5ed04865-5802-4fd5-9d80-917d1fadae70  bond            bond1      

 

#删除网卡配置连接

[root@localhost network-scripts]# nmcli con del bond-slave-eno50332208
[root@localhost network-scripts]# nmcli con del bond-slave-eno33554984

 

[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: eno16777736
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eno16777736
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 1
Permanent HW addr: 00:0c:29:fd:1d:cf
Slave queue ID: 0

 

 

[root@localhost network-scripts]# nmcli con del bond-slave-eno16777736

 

[root@localhost network-scripts]# nmcli con del bond-bond1

 

网卡恢复

 

 

#方式2:cli方式

 

以文件方式配置Bond

 

 

#备份原有网卡配置文件

[root@localhost ~]# mkdir -p /data/backup/network

[root@localhost ~]# cd /etc/sysconfig/network-scripts/

[root@localhost ~]#  cp ifcfg-eno*  /data/backup/network/

 

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

[root@localhost network-scripts]# nmcli device status
设备         类型      状态    CONNECTION 
eno16777736  ethernet  连接的  eno16777736
eno33554984  ethernet  连接的  有线连接 1 
eno50332208  ethernet  连接的  有线连接 2 
lo           loopback  未管理  --        

[root@localhost network-scripts]# ll
总用量 236
-rw-r--r--. 1 root root   295 8月  25 2015 ifcfg-eno16777736
-rw-r--r--. 1 root root   295 3月  29 19:13 ifcfg-eno33554984

 

 [root@localhost network-scripts]# cp ifcfg-eno16777736 ifcfg-eno33554984

[root@localhost network-scripts]# vim ifcfg-bond5

DEVICE=bond5
BONDING_OPTS="mode=balance-tlb"
TYPE=Bond
BONDING_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@localhost network-scripts]# vim ifcfg-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@localhost network-scripts]# vim ifcfg-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@localhost network-scripts]# vim ifcfg-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 network-scripts]# systemctl restart network

 

[root@localhost ~]# nmcli connection show
名称         UUID                                  类型            设备       
eno50332208  d2665055-8e83-58f1-e9e3-49a5fb133641  802-3-ethernet  eno50332208
eno16777736  13756690-ac77-b776-4fc1-f5535cee6f16  802-3-ethernet  eno16777736
有线连接 2   4013b28a-31dd-43b0-9b32-6582a20353f9  802-3-ethernet  --         
有线连接 1   9cca4859-5085-4cb3-a660-4664fac689c5  802-3-ethernet  --         
eno33554984  fb67dbad-ec81-39b4-42b1-ebf975c3ff13  802-3-ethernet  eno33554984
bond5        d1a49a62-2f2d-2e41-a63d-be3a81b6a2fb  bond            bond5      

 

 

[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond5 state UP qlen 1000
    link/ether 00:0c:29:fd:1d:cf brd ff:ff:ff:ff:ff:ff
3: eno33554984: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond5 state UP qlen 1000
    link/ether 00:0c:29:fd:1d:d9 brd ff:ff:ff:ff:ff:ff
4: eno50332208: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond5 state UP qlen 1000
    link/ether 00:0c:29:fd:1d:e3 brd ff:ff:ff:ff:ff:ff
7: bond5: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
    link/ether 00:0c:29:fd:1d:cf brd ff:ff:ff:ff:ff:ff
    inet 192.168.3.200/24 brd 192.168.3.255 scope global bond5
       valid_lft forever preferred_lft forever
    inet6 fe80::a81d:6bff:feac:5cd6/64 scope link
       valid_lft forever preferred_lft forever

 

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

 

[root@localhost ~]# cat /proc/net/bonding/bond5
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: transmit load balancing
Primary Slave: None
Currently Active Slave: eno16777736
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eno16777736
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:fd:1d:cf
Slave queue ID: 0

Slave Interface: eno33554984
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:fd:1d:d9
Slave queue ID: 0

Slave Interface: eno50332208
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:fd:1d:e3
Slave queue ID: 0

 

 

 

注*模式选择有以下这些

balance-rr(0)

active-backup(1)

balance-xor (2)

broadcast (3)

802.3ad (4)

balance-tlb (5) 

balance-alb (6)

 

 

 

#暂时就这么多,希望各位多多指点!!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

本文出自 “张浩宇” 博客,请务必保留此出处http://zhanghaoyu.blog.51cto.com/8202592/1911345

bond绑定模式与操作(centos7)