redhat8.0双网卡绑定技术bond模式

什么是bond?
在英语中,bond的意思有团结的意思,但是在网卡绑定技术中
bond的意思是:是通过多张网卡绑定为一个逻辑网卡,实现本地网卡的冗余,带宽扩容和负载均衡,在生产场景中是一种常用的技术。
bond的模式有6种
其中主要模式有:

bond0:
round-robin(论循)
特点是:按照设备顺序依次传输数据包,提供负载均衡和容错能力。
对交换机的要求是:交换机需要配置trunking
缺点:需要接入交换机做端口聚合,否则可能无法使用
bond1:
active-backup(主动备份)简称主备模式
特点是:只有一个设备处理数据,当他宕机的时候就会由备份代替,仅提供容错能力。冗余能力高
对交换机的要求是:不需要配置trunking
缺点:链路利用率低,两块网卡只有1块在工作
bond的其他模式:
bond2:
load-balancing(xor) (平衡策略):
特点是:根据MAC地质异或运算的结果来选择传入设备,提供负载均衡和容错能力。
是要配置trunking的
bond3:
broadcast(广播策略)
特点是:通过全部设备来传输所有数据,提供容错能力,要配置trunking。
bond4(lacp)(动态链路聚合):
特点:通过创建聚合组来共享相同的传输速度,需要交换机也支持802.3ad模式,提供容错能力。
但是交换机需要支持802.3ad、交换机需要配置trunking。
bond5(transmit load balancing)(适配器传输负载均衡):
特点是:由负载最轻的网口发送,由当前使用的网口接受。提供负载均衡和容错能力。
交换机不需要配置trunking。
bond6(adaptive load balancing):
特点是:用负载最轻的网口进行发送和接收。提供负载均衡和容错能力。
不需要配置trunking。

以上是对bond模式的详解

接下来是对bond的实战详解:
bond,双网卡绑定,我们可以使用vim来编辑,不过体现不出来技术含量,所以我们用nmcli来配置。
我们实战用主备模式和桥接模式来进行实操。
废话不多说,开始实战。

[root@guochanghe ~]# nmcli con add type #这个地方,我们选择模式,选择bond模式。
6lowpan           adsl              cdma              gsm               macvlan           ovs-port          vlan              wimax
802-11-olpc-mesh  bluetooth         dummy             infiniband        olpc-mesh         pppoe             vpn               wpan
802-11-wireless   bond              ethernet          ip-tunnel         ovs-bridge        team              vxlan             
802-3-ethernet    bridge            generic           macsec            ovs-interface     tun               wifi              
[root@guochanghe ~]# nmcli con add type bond ifname bond0 con-name bond0 mode 
#ifname是们定义的网络接口名 bond0
#con-name 是我们定义的连接名bond0
#mode是模式,mode后面跟的是选择bond的哪个模式,我们以准备模式为例,所以选择active-backup模式
802.3ad        active-backup  balance-alb    balance-rr     balance-tlb    balance-xor    broadcast      
[root@guochanghe ~]# nmcli con add type bond ifname bond0 con-name bond0 mode active-backup miimon 1000
#miimon 1000 意思为端口的速率是1000 Mpbs 
连接 "bond0" (c4f0bd90-76a8-45d5-a3d1-8bc2ab30d807) 已成功添加。
#经过以上操作,成功添加了bond0,
#去网卡配置目录查看:
[root@guochanghe network-scripts]# ls
ifcfg-bond0  ifcfg-ens160
#成功的添加到里面去,但是并没有配置IP地址。
[root@guochanghe network-scripts]#nmcli con modify bond0 ipv4.addresses 172.16.8.10/24 ipv4.method manual
#手动使用nmcli命令
[root@guochanghe network-scripts]# nmcli con show
NAME    UUID                                  TYPE      DEVICE 
ens160  ea74cf24-c2a2-ecee-3747-a2d76d46f93b  ethernet  ens160 
virbr0  9a0d29a3-6adb-40f6-bb67-66f5adb7316f  bridge    virbr0 
bond0   c4f0bd90-76a8-45d5-a3d1-8bc2ab30d807  bond      bond0 
#也可以看到bond0的连接
[root@guochanghe ~]# nmcli con add type ethernet slave-type bond ifname ens192 con-name bond0-port1 master bond0 
连接 "bond0-port1" (5d085791-ad66-4dd9-a754-b82cc66ab80d) 已成功添加。
[root@guochanghe ~]# nmcli con add type ethernet slave-type bond ifname ens224 con-name bond0-port2 master bond0 
连接 "bond0-port2" (93a0ec6e-7b34-46d7-b552-1d182790a22e) 已成功添加。
#这两行命令的意思是将ens192网卡和ens224网卡添加到bond0这个网卡里面

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

Bonding Mode: fault-tolerance (active-backup)  #模式为准备模式
Primary Slave: None
Currently Active Slave: ens192
MII Status: up					#接口状态: up(MII是Media Independent Interface简称, 接口的意思)
MII Polling Interval (ms): 1000  #间隔时间为1000ms
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: ens192		#备接口: ens192
MII Status: up
Speed: 10000 Mbps
Duplex: full				#全双工
Link Failure Count: 0		#链接失败次数为0
Permanent HW addr: 00:0c:29:74:bd:65 #永久的MAC地址
Slave queue ID: 0

Slave Interface: ens224		#备接口:ens224
MII Status: up
Speed: 10000 Mbps
Duplex: full				#全双工
Link Failure Count: 0		#链接失败次数为0
Permanent HW addr: 00:0c:29:74:bd:6f #永久的MAC地址
Slave queue ID: 0
#通过/proc/net/bonding/bond0这个文件里面的内容,我们可以清楚的看到,ens192和ens224成功的被添加到里面去,绑定了一个网卡。
#接下来激活这个网卡。
[root@guochanghe ~]# nmcli con up bond0
连接已成功激活(master waiting for slaves)(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/17)
[root@guochanghe ~]# ifconfig
bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST>  mtu 1500
        inet 172.16.8.10  netmask 255.255.255.0  broadcast 172.16.8.255
        inet6 fe80::8fce:a2ff:506d:e210  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:74:bd:65  txqueuelen 1000  (Ethernet)
        RX packets 26  bytes 3756 (3.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 134  bytes 15652 (15.2 KiB)
        TX errors 0  dropped 2 overruns 0  carrier 0  collisions 0
        [root@guochanghe ~]# ping -c2 172.16.8.10
PING 172.16.8.10 (172.16.8.10) 56(84) bytes of data.
64 bytes from 172.16.8.10: icmp_seq=1 ttl=64 time=0.040 ms
64 bytes from 172.16.8.10: icmp_seq=2 ttl=64 time=0.043 ms

--- 172.16.8.10 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 50ms
rtt min/avg/max/mdev = 0.040/0.041/0.043/0.006 ms
#可以ping成功,说明可用
       #以上就是bond模式的测试,

接下来是对桥接模式的测试:

[root@guochanghe ~]# nmcli con add type bridge ifname br0 con-name br0 
连接 "br0" (5c985ceb-9279-47d0-8029-66146570d201) 已成功添加
#类型为bridge桥接类型。
[root@guochanghe ~]# nmcli con modify br0 ipv4.addresses 192.168.10.11/16 ipv4.method manual 
#手动设置一个静态的ip地址
[root@guochanghe ~]# nmcli connection add type ethernet slave-type bridge ifname ens192 con-name br0-port1 master br0 
连接 "br0-port1" (9a4e20db-5949-43dd-a131-f28893278ef7) 已成功添加。
[root@guochanghe ~]# nmcli connection add type ethernet slave-type bridge ifname ens224 con-name br0-port2 master br0 
连接 "br0-port2" (51c238bf-eb0f-4796-98e4-3a17282bda0b) 已成功添加。
#将ens192和ens224网卡绑定进br0网卡
[root@guochanghe ~]# nmcli con up br0
连接已成功激活(master waiting for slaves)(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/26)
[root@guochanghe ~]# ifconfig 
br0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.10.11  netmask 255.255.0.0  broadcast 192.168.255.255
        ether 00:0c:29:74:bd:65  txqueuelen 1000  (Ethernet)
        RX packets 4  bytes 750 (750.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 44  bytes 5504 (5.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        #激活这个网卡并查看ip地址
[root@guochanghe ~]# ping -c2 192.168.10.11
PING 192.168.10.11 (192.168.10.11) 56(84) bytes of data.
64 bytes from 192.168.10.11: icmp_seq=1 ttl=64 time=0.034 ms
64 bytes from 192.168.10.11: icmp_seq=2 ttl=64 time=0.052 ms

--- 192.168.10.11 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 43ms
rtt min/avg/max/mdev = 0.034/0.043/0.052/0.009 ms
#ping 一下进行测试

成功,以上就是对bond模式的一些见解和一些测试实战。方法都差不多。

原创文章 3 获赞 2 访问量 1654

猜你喜欢

转载自blog.csdn.net/lvjie13450/article/details/106034441