linux内核端口绑定,linux 多网卡bonding 绑定 端口聚合

将多个Linux网络端口绑定为一个,可以提升网络的性能,比如对于备份服务器,需要在一个晚上备份几个T的数据,

如果使用单个的千兆网口将会是很严重的瓶颈。其它的应用,比如ftp服务器,高负载的下载网站, 都有类似的问题。

因此使用Linux teaming或bond来绑定多个网卡作为一个逻辑网口,配置单个的IP地址,会大幅提升服务器的网络吞吐(I/O)。

Linux的多网卡绑定功能使用的是内核中的"bonding"模块,关于此模块可以参考Linux Ethernet Bonding Driver文档,

但是目前发布各个Linux版本内核均已包含了此模块,大多数情况下不需要重新编译内核。

Linux 的 bonding 驱动提供了绑定/集成(bond)多个网卡为一个虚拟逻辑网口的功能。并请注意绑定的网口(bonded)有多种工作模式;

一般来说,分为 热后备(hot standby) 和 负载均衡(load balancing). 在Redhat/Fedora和其它类Redhat Linux中是比较容易配置的。

1.创建bond0配置文件

vi /etc/sysconfig/network-scripts/ifcfg-bond0

[root@localhost network-scripts]# less ifcfg-bond0

DEVICE=bond0

#HWADDR=00:10:18:D8:62:58

TYPE=Ethernet

#UUID=85f545ec-5add-48e0-bcc6-3699a2202972

ONBOOT=yes

NM_CONTROLLED=no

BOOTPROTO=none

IPADDR=192.168.2.10

NETMASK=255.255.255.0

GATEWAY=192.168.2.1

MTU=9000

BONDING_OPTS="mode=4 miimon=100"

2.修改被绑定的eth0和eth1的配置文件

[root@localhost network-scripts]# cat ifcfg-eth2

DEVICE=eth2

HWADDR=00:10:18:D8:62:58

TYPE=Ethernet

UUID=85f545ec-5add-48e0-bcc6-3699a2202972

ONBOOT=yes

NM_CONTROLLED=no

BOOTPROTO=none

MASTER=bond0

SLAVE=yes

MTU=9000

[root@localhost network-scripts]# cat ifcfg-eth3

DEVICE=eth3

#HWADDR=00:10:18:D8:62:58

TYPE=Ethernet

UUID=85f545ec-5add-48e0-bcc6-3699a2202972

ONBOOT=yes

NM_CONTROLLED=no

BOOTPROTO=none

MASTER=bond0

SLAVE=yes

MTU=9000

[root@localhost network-scripts]# cat ifcfg-eth4

DEVICE=eth4

#HWADDR=00:10:18:D8:62:58

TYPE=Ethernet

UUID=85f545ec-5add-48e0-bcc6-3699a2202972

ONBOOT=yes

NM_CONTROLLED=no

BOOTPROTO=none

MASTER=bond0

SLAVE=yes

MTU=9000

[root@localhost network-scripts]# cat ifcfg-eth5

DEVICE=eth5

#HWADDR=00:10:18:D8:62:58

TYPE=Ethernet

UUID=85f545ec-5add-48e0-bcc6-3699a2202972

ONBOOT=yes

NM_CONTROLLED=no

BOOTPROTO=none

MASTER=bond0

SLAVE=yes

MTU=9000

3.装在bond模块驱动

编辑/etc/modprobe.conf或者/etc/modules.conf文件,加入如下内容,使系统启动时加载bonding模块驱动

如果没有modprobe.conf 就vi modprobe.conf 一个文件

alias bond0 bonding

option bond0 miimon=100 mode=1

说明:

1).miimon=100 用来进行链路监测的。即每100ms监测一次链路状态。bonding只监测主机与交换机之间链路。如果交换机出去的链路出问题而本身没有问题,那么bonding认为链路没有问题而继续使用。

2).mode=1 表示提供冗余功能。除此之外还可以为0、2、3,共四种模式。0表示负载均衡

4.在/etc/rc.d/rc.local文件中加入如下语句,使得系统启动自动运行

ifenslave bond0 eth0 eth1

route add -net 192.168.1.254 netmask 255.255.255.0 bond0 #如有需要才加该路由

5.检测、验证配置

首先执行命令装载bonding模块:modprobe bonding

重启网络服务,并确认bond0正确启动:service network restart

确认设备已经正确加载:less /proc/net/bonding/bond0

[root@localhost network-scripts]# less /proc/net/bonding/bond0

Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)

Bonding Mode: IEEE 802.3ad Dynamic link aggregation

Transmit Hash Policy: layer2 (0)

MII Status: up

MII Polling Interval (ms): 100

Up Delay (ms): 0

Down Delay (ms): 0

802.3ad info

LACP rate: slow

Aggregator selection policy (ad_select): stable

Active Aggregator Info:

Aggregator ID: 15

Number of ports: 1

Actor Key: 17

Partner Key: 1

Partner Mac Address: 00:00:00:00:00:00

Slave Interface: eth2

MII Status: up

Speed: 1000 Mbps

Duplex: full

Link Failure Count: 5

Permanent HW addr: 00:10:18:d8:62:58

Aggregator ID: 12

Slave queue ID: 0

Slave Interface: eth3

MII Status: up

Speed: 1000 Mbps

Duplex: full

Link Failure Count: 1

Permanent HW addr: 00:10:18:d8:62:5a

Aggregator ID: 13

Slave queue ID: 0

Slave Interface: eth4

MII Status: up

Speed: 1000 Mbps

Duplex: full

Link Failure Count: 2

Permanent HW addr: 00:10:18:d8:62:5c

Aggregator ID: 14

Slave queue ID: 0

Slave Interface: eth5

MII Status: up

Speed: 1000 Mbps

Duplex: full

Link Failure Count: 0

Permanent HW addr: 00:10:18:d8:62:5e

Aggregator ID: 15

Slave queue ID: 0

至此,bond 的设置就基本结束了

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值