一、 环境和需求
Linux主机只有一块网卡接到交换机上,为了消除交换机的单点,新增一台交换机,Linux主机端新接一块网卡到新交换机上,对这两块网卡做聚合达到目的。
二、 物理连线
使用网线连接新增交换机和新网卡
三、 停应用
对网卡做聚合改造,会造成网络中断,为了消除对生产的影响,建议停止应用后再做改造
四、 网络聚合改造
1) 对/etc/modprobe.conf文件新增以下内容
# vi /etc/modprobe.conf
alias bond0 bonding
options bond0 mode=1 miimon=100 use_carrier=0
说明:
miimon=100,那么系统每100ms 监测一次链路连接状态,如果有一条线路不通就转入另一条线路;
mode 的值表示工作模式:
mode=0 表示为负载均衡方式,两块网卡都工作。
mode=1 表示提供冗余功能,工作方式是主备的工作方式
2) 建立虚拟网卡配置文件
# vi /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.0.215
USERCTL=no
NETMASK=255.255.255.0
NETWORK=192.168.0.0
BROADCAST=192.168.0.255
GATEWAY=192.168.0.1
TYPE=Ethernet
其中IPADDR=192.168.0.215是原网卡的IP地址
3) 更改原有网卡属性
#vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
MASTER=bond0
SLAVE=yes
HWADDR=00:0C:29:38:37:23
4) 更改新增网卡属性
#vi /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
MASTER=bond0
SLAVE=yes
HWADDR=00:0c:29:38:37:2d
5) 用命令 /etc/rc.d/init.d/network restart 重新启动网络子系统,也可以重新启动系统来使 bond0生效。
# /etc/rc.d/init.d/network restart
Shutting down interface bond0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface bond0: [ OK ]
重启网络的时候,对IP做PING测试,中间有丢包,后续又恢复通讯
检查IP地址:
# ifconfig
bond0 Link encap:Ethernet HWaddr 00:0C:29:38:37:23
inet addr:192.168.0.214 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:48915 errors:0 dropped:0 overruns:0 frame:0
TX packets:4804 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3857250 (3.6 MiB) TX bytes:394142 (384.9 KiB)
eth0 Link encap:Ethernet HWaddr 00:0C:29:38:37:23
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:26942 errors:0 dropped:0 overruns:0 frame:0
TX packets:4754 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2121514 (2.0 MiB) TX bytes:385269 (376.2 KiB)
eth1 Link encap:Ethernet HWaddr 00:0C:29:38:37:23
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:21973 errors:0 dropped:0 overruns:0 frame:0
TX packets:50 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1735736 (1.6 MiB) TX bytes:8873 (8.6 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:1375 errors:0 dropped:0 overruns:0 frame:0
TX packets:1375 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:4201832 (4.0 MiB) TX bytes:4201832 (4.0 MiB)
# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.4.0-1 (October 7, 2008)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth2
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth2
MII Status: up
Speed: 100 Mbps
Duplex: full
Link Failure Count: 1
Permanent HW addr: b8:ca:3a:f9:6b:33
Slave Interface: eth3
MII Status: down
Speed: 100 Mbps
Duplex: full
Link Failure Count: 2
Permanent HW addr: b8:ca:3a:f9:6b:34
6) 设置成聚合开机自启动
# vi /etc/rc.d/rc.local
ifenslave bond0 eth0 eth1
7) 网卡切换测试
拔eth0网卡网线,查看是否会自动切到eth1网卡上,检查丢包情况
使用cat /proc/net/bonding/bond0 命令查看
切到eth1网卡上
接回eth0网线,不会自动切回到eth0上,除非拔出 eth1网卡
原文地址:http://12865902.blog.51cto.com/12855902/1920535