双网卡绑定之负载均衡高可用(bond)

简介:

一、bond的工作原理 

    所谓的bond就是将两块或两块以上网卡绑定同一个IP地址对外提供服务,从而实现负载均衡高可用。当然,直接给两块网卡设置同一IP地址 是不可能的。通过bonding,虚拟一块网卡对外提供连接, 物理网卡的被修改为相同的MAC地址。

   

 

二、bond工作模式分类

 1)Mode 0 (balance-rr) 轮转(Round-robin)策略:从头到尾顺序的在每一个slave 接口上面发送数据包。本模式提供负载均衡和容错的能力 


2)Mode 1 (active-backup) 活动-备份(主备)策略:在绑定中,只有一个slave被激活。 当且仅当活动的slave接口失败时才会激活其他slave。为了 避免交换机发生混乱此时绑定的MAC地址只有一个外部端口上可见 


3)Mode 3 (broadcast) 广播策略:在所有的slave接口上传送所有的报文。本模式提供 无容错能力。



三、实现步骤

1、为每个设备生成独立的接口配置文件,关闭NetworkManager服务。 

chkconfig --level 3 NetworkManager off   


2、添加网卡,配置静态联网(bond0)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@centos6 network-scripts] # cat ifcfg-bond0
DEVICE=bond0
IPADDR=10.1.249.34
PRFIX=16
GATEWAY=10.1.249.254
DNS1=8.8.8.8
BONDING_OPTS= "miimon=101 mode=0"  #如果mode=0则为轮转模式,为1则为主备模式,为3则为广播策略
[root@centos6 network-scripts] # cat ifcfg-eth0
DEVICE=eth0
SLAVE= yes
MASTER=bond0
[root@centos6 network-scripts] # cat ifcfg-eth1
DEVICE=eth1
SLAVE= yes
MASTER=bond0
[root@centos6 network-scripts] #


3、随意断开一网卡测试,并查看结果 



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
[root@centos6 network-scripts] # !cat
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: eth0
MII Status: up
MII Polling Interval (ms): 102
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:7c:55:8d
Slave queue ID: 0
Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:7c:55:97
Slave queue ID: 0
[root@centos6 network-scripts] #
[root@centos6 ~] # cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: load balancing (round-robin)
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 3
Permanent HW addr: 00:0c:29:7c:55:8d
Slave queue ID: 0
Slave Interface: eth1
MII Status: down
Speed: Unknown
Duplex: Unknown
Link Failure Count: 3
Permanent HW addr: 00:0c:29:7c:55:97
Slave queue ID: 0
[root@centos6 ~] # cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (broadcast)
MII Status: up
MII Polling Interval (ms): 101
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 2
Permanent HW addr: 00:0c:29:7c:55:8d
Slave queue ID: 0
Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 1
Permanent HW addr: 00:0c:29:7c:55:97
Slave queue ID: 0
[root@centos6 ~] #

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[root@centos6 network-scripts] # ifconfig
bond0     Link encap:Ethernet  HWaddr 00:0C:29:7C:55:8D  #三的MAC地址信息是一样的,代表绑定为一块网卡
           inet addr:10.1.249.34  Bcast:10.255.255.255  Mask:255.0.0.0
           inet6 addr: fe80::20c:29ff:fe7c:558d /64  Scope:Link
           UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
           RX packets:62258 errors:0 dropped:0 overruns:0 frame:0
           TX packets:7493 errors:0 dropped:0 overruns:0 carrier:0
           collisions:0 txqueuelen:0
           RX bytes:5599522 (5.3 MiB)  TX bytes:716163 (699.3 KiB)
eth0      Link encap:Ethernet  HWaddr 00:0C:29:7C:55:8D  #三的MAC地址信息是一样的,代表绑定为一块网卡
           UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
           RX packets:32698 errors:0 dropped:0 overruns:0 frame:0
           TX packets:4300 errors:0 dropped:0 overruns:0 carrier:0
           collisions:0 txqueuelen:1000
           RX bytes:2915521 (2.7 MiB)  TX bytes:393343 (384.1 KiB)
eth1      Link encap:Ethernet  HWaddr 00:0C:29:7C:55:8D  #三的MAC地址信息是一样的,代表绑定为一块网卡
           UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
           RX packets:33832 errors:0 dropped:0 overruns:0 frame:0
           TX packets:3359 errors:0 dropped:0 overruns:0 carrier:0
           collisions:0 txqueuelen:1000
           RX bytes:3059478 (2.9 MiB)  TX bytes:339826 (331.8 KiB)
lo        Link encap:Local Loopback
           inet addr:127.0.0.1  Mask:255.0.0.0
           inet6 addr: ::1 /128  Scope:Host
           UP LOOPBACK RUNNING  MTU:65536  Metric:1
           RX packets:425 errors:0 dropped:0 overruns:0 frame:0
           TX packets:425 errors:0 dropped:0 overruns:0 carrier:0
           collisions:0 txqueuelen:0
           RX bytes:42694 (41.6 KiB)  TX bytes:42694 (41.6 KiB)
[root@centos6 network-scripts] #




截图演示:


1、关闭NetworkManager服务

wKioL1fJjBTAPCF0AAAa-WuYsO4622.png


2、准备所有配置文件

wKioL1fJjaPjhGOHAAAy2TK9XYc695.png


3、重启网络服务

wKiom1fJjbnBHirJAAAg6m8gc7s840.png


4、断开一网卡在物理机上ping本ip地址,测试主备功能

wKioL1fJkMfiPbdCAADRtup6ssA496.png





结论:

同理可使用不同的bond工作模式进行测试,结果为,当处于mode0时为轮转模式有容错能力可坏一块网卡,当处于mode1时为主备模式有容错能力可坏一块网卡,当处于mode3时为广播策略模式,亲测,只要工作的网卡不坏则正常工作,当开始不是工作的网卡切换为工作网卡时则不能工作。



本文转自chengong1013 51CTO博客,原文链接:http://blog.51cto.com/purify/1845804,如需转载请自行联系原作者

相关实践学习
部署高可用架构
本场景主要介绍如何使用云服务器ECS、负载均衡SLB、云数据库RDS和数据传输服务产品来部署多可用区高可用架构。
负载均衡入门与产品使用指南
负载均衡(Server Load Balancer)是对多台云服务器进行流量分发的负载均衡服务,可以通过流量分发扩展应用系统对外的服务能力,通过消除单点故障提升应用系统的可用性。 本课程主要介绍负载均衡的相关技术以及阿里云负载均衡产品的使用方法。
相关文章
|
7月前
|
负载均衡 网络安全
|
7月前
|
缓存 负载均衡 关系型数据库
Pgpool-II实现高可用+读写分离+负载均衡(一)---- 规划及安装
Pgpool-II是一款工作在PostgreSQL服务器和PostgreSQL数据库客户端之间的中间件。提供了连接池、复制、负载均衡、限制过多连接、看门狗、查询缓存等功能。
476 0
|
7月前
|
负载均衡
Pgpool-II实现高可用+读写分离+负载均衡(七)---- recovery_1st_stage分析
recovery_1st_stage是Pgpool online recovery的第一阶段,位于PG_DATA目录下,主要功能就是使用pg_basebackup恢复(recovery)从节点。
225 0
|
8月前
|
tengine Kubernetes Cloud Native
Tengine-Ingress 高性能高可用的云原生网关
Tengine-Ingress 高性能高可用的云原生网关
235 0
|
3月前
|
存储 缓存 运维
解密一致性哈希算法:实现高可用和负载均衡的秘诀
解密一致性哈希算法:实现高可用和负载均衡的秘诀
217 0
|
4月前
|
Kubernetes 负载均衡 监控
Kubernetes高可用集群二进制部署(一)主机准备和负载均衡器安装
Kubernetes高可用集群二进制部署(一)主机准备和负载均衡器安装
|
5月前
|
tengine Kubernetes Cloud Native
Tengine-Ingress 高性能高可用的云原生网关
Tengine-Ingress 高性能高可用的云原生网关
|
6月前
|
负载均衡 算法 网络协议
Keepalived+LVS搭建高可用负载均衡
Keepalived+LVS搭建高可用负载均衡
194 1
|
6月前
|
负载均衡 关系型数据库 PostgreSQL
Pgpool-II实现高可用+读写分离+负载均衡(八)---- 维护工具
Pgpool提供了一些维护工具,用于日常观察Pgpool运行状态、上线、下线节点等操作。主要有:pcp_stop_pgpool,pcp_node_count,pcp_node_info,pcp_health_check_stats,pcp_proc_count,pcp_proc_info,pcp_detach_node,pcp_attach_node,pcp_recovery_node,pcp_promote_node,pcp_pool_status,pcp_watchdog_info,pcp_reload_config
200 0
|
6月前
|
负载均衡 前端开发 网络协议
Keepalived+HAProxy 搭建高可用负载均衡(二)
Keepalived+HAProxy 搭建高可用负载均衡