centos双网卡绑定负载均衡

通过linux自带的bond技术实现linux双网卡绑定和负载均衡

绑定的前提条件:芯片组型号相同,而且网卡应该具备自己独立的BIOS芯片

一、建立虚拟网络接口ifcfg-bond0文件
[root@jason ~]# cd /etc/sysconfig/network-scripts/
[root@jason network-scripts]# cp ifcfg-eth0 ifcfg-bond0
其内容为:
[root@jason network-scripts]# more ifcfg-bond0
# Broadcom Corporation NetXtreme II BCM5708 Gigabit Ethernet
DEVICE=bond0
BROADCAST=10.0.0.255
IPADDR=10.0.0.3
NETMASK=255.255.255.0
NETWORK=10.0.0.0

MTU=1500
GATEWAY=10.0.0.1
[root@jason network-scripts]#

二、编辑原有网卡eth0和eth信息文件
使其内容为:
[root@jason network-scripts]# more ifcfg-eth0
# Broadcom Corporation NetXtreme II BCM5708 Gigabit Ethernet
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
TYPE=Ethernet
MASTER=bond0
slave=yes

[root@jason network-scripts]# more ifcfg-eth1
# Broadcom Corporation NetXtreme II BCM5708 Gigabit Ethernet
DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
TYPE=Ethernet
MASTER=bond0
slave=yes

[root@jason network-scripts]#

三、编辑/etc/modprobe.conf加入下面两行
[root@jason network-scripts]# vi /etc/modprobe.conf
alias bond0 bonding
options bond0 miimon=100 mode=1

 

说明:miimon是用来进行链路监测的。 比如:miimon=100,那么系统每100ms监测一次链路连接状态,如果有一条线路不通就转入另一条线路;mode的值表示工作模式,他共有0,1,2,3四种模式,常用的为0,1两种。

mode=0表示load balancing (round-robin)为负载均衡方式,两块网卡都工作。

mode=1表示fault-tolerance (active-backup)提供冗余功能,工作方式是主备的工作方式,也就是说默认情况下只有一块网卡工作,另一块做备份.

bonding只能提供链路监测,即从主机到交换机的链路是否接通。如果只是交换机对外的链路down掉了,而交换机本身并没有故障,那么bonding会认为链路没有问题而继续使用

加入后我的modprobe.conf内容为:
[root@jason network-scripts]# more /etc/modprobe.conf
alias eth0 bnx2
alias eth1 bnx2
alias scsi_hostadapter aacraid
alias scsi_hostadapter1 ata_piix
alias peth0 bnx2
alias bond0 bonding
options bond0 miimon=100 mode=1


四、编辑/etc/rc.d/rc.local文件,加入
ifenslave bond0 eth0 eth1

重新启动后,负载均衡就能正常工作了,可以用ifconfig查看具体信息
[root@jason network-scripts]# ifconfig
bond0 Link encap:Ethernet HWaddr 00:1A:64:6A:55:98
inet addr:10.0.0.3 Bcast:10.0.0.255 Mask:255.255.255.0
inet6 addr: fe80::21a:64ff:fe6a:5598/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:985369 errors:0 dropped:0 overruns:0 frame:0
TX packets:804306 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:148943796 (142.0 MiB) TX bytes:2097755332 (1.9 GiB)

eth0 Link encap:Ethernet HWaddr 00:1A:64:6A:55:98
inet6 addr: fe80::21a:64ff:fe6a:5598/64 Scope:Link
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:984133 errors:0 dropped:0 overruns:0 frame:0
TX packets:804292 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:148805154 (141.9 MiB) TX bytes:2097751381 (1.9 GiB)

eth1 Link encap:Ethernet HWaddr 00:1A:64:6A:55:98
inet6 addr: fe80::21a:64ff:fe6a:5598/64 Scope:Link
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:1236 errors:0 dropped:0 overruns:0 frame:0
TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:138642 (135.3 KiB) TX bytes:4275 (4.1 KiB)
Interrupt:16 Memory:ca000000-ca011100

 

 

通过查看bond0的工作状态查询能详细的掌握bonding的工作状态

[root@redflag bonding]# cat /proc/net/bonding/bond0

bonding.c:v2.4.1 (September 15, 2003)

 

Bonding Mode: load balancing (round-robin)

MII Status: up

MII Polling Interval (ms): 0

Up Delay (ms): 0

Down Delay (ms): 0

Multicast Mode: all slaves

 

Slave Interface: eth1

MII Status: up

Link Failure Count: 0

Permanent HW addr: 00:0e:7f:25:d9:8a

 

Slave Interface: eth0

MII Status: up

Link Failure Count: 0

Permanent HW addr: 00:0e:7f:25:d9:8b

你可能感兴趣的:(linux,centos,技术,接口,网卡)