Bonding就是将多块网卡绑定同一IP地址对外提供服务,可以实现高可用或者负载均衡。当然,直接给两块网卡设置同一IP地址是不可能的。通过bonding,虚拟一块网卡对外提供连接,物理网卡的被修改为相同的MAC地址。
一、Bonding的常用工作模式
Mode 0 (balance-rr)
轮转( Round-robin)策略:从头到尾顺序的在每一个slave接口上面发送数据包。本模式提供负载均衡和容错的能力。
Mode 1 (active-backup)
活动-备份(主备)策略:在绑定中,只有一个slave被激活。当且仅当活动的slave接口失败时才会激活其他slave。为了避免交换机发生混乱此时绑定的MAC地址只有一个外部端口上可见。
Mode 3 (broadcast)
广播策略:在所有的slave接口上传送所有的报文。本模式提供容错能力。
二、Bonding配置
创建bonding设备的配置文件:
#vim /etc/sysconfig/network-scripts/ifcfg-bond0 DEVICE=bond0 BOOTPROTO=none BONDING_OPTS=“miimon=100 mode=0” #vim /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 BOOTPROTO=none MASTER=bond0 SLAVE=yes USERCTL=no
说明:miimon是用来进行链路监测的。如果miimon=100,那么系统每100ms 监测一次链路连接状态,如果有一条线路不通就转入另一条线路
查看bond0状态:cat /proc/net/bonding/bond
关于bonding的详细配置请参照:
/usr/src/linux-3.18.41/Documentation/networking/bonding.txt
三、bonding实验演示
步骤1:首先確定自己的操作系统是否支持bonding
[[email protected] ~]# modinfo bonding filename: /lib/modules/2.6.32-642.el6.x86_64/kernel/drivers/net/bonding/bonding.ko author: Thomas Davis, [email protected] and many others description: Ethernet Channel Bonding Driver, v3.7.1 version: 3.7.1 ...
如果没有消息返回,說明內核不支持bonding,需要重新编译內核。
步骤2:创建bonding配置文件
[[email protected] network-scripts]# cat ifcfg-bond0 DEVICE=bond0 BOOTPROTO=none IPADDR=192.168.1.9 GATEWAY=192.168.1.1 PREFIX=24 DNS1=8.8.8.8 BONDING_OPTS="miimon=100 mode=1"
步骤3:修改网卡配置文件
[[email protected] network-scripts]# cat ifcfg-eth0 DEVICE=eth0 BOOTPROTO=none MASTER=bond0 SLAVE=yes [[email protected] network-scripts]# cat ifcfg-eth1 DEVICE=eth1 BOOTOPRO=none MASTER=bond0 SLAVE=yes
步骤4:重启网络服务
[[email protected] network-scripts]# service network restart Shutting down interface bond0: ...
步骤5:查看配置情况
[[email protected] network-scripts]# ifconfig bond0 Link encap:Ethernet HWaddr 00:0C:29:30:84:C4 inet addr:192.168.1.9 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe30:84c4/64 Scope:Link UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1 RX packets:1000 errors:0 dropped:0 overruns:0 frame:0 TX packets:488 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:82884 (80.9 KiB) TX bytes:56939 (55.6 KiB) eth0 Link encap:Ethernet HWaddr 00:0C:29:30:84:C4 UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1 RX packets:1095 errors:0 dropped:0 overruns:0 frame:0 TX packets:677 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:95368 (93.1 KiB) TX bytes:75001 (73.2 KiB) eth1 Link encap:Ethernet HWaddr 00:0C:29:30:84:C4 UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1 RX packets:243 errors:0 dropped:0 overruns:0 frame:0 TX packets:8 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:14734 (14.3 KiB) TX bytes:614 (614.0 b) ... [[email protected] network-scripts]# 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): 100 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:30:84:c4 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:30:84:ce Slave queue ID: 0
步骤6:测试
时间: 2024-10-14 18:55:42