
将多个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
DEVICE=bond0
--物理设备名字
IPADDR=192.168.1.2
--IP地址
NETMASK=255.255.255.0
--子网掩码
GATEWAY=192.168.1.1
--网关
DNS=8.8.8.8
--DNS
ONBOOT=yes
--随机启动
NAME=bond0
BOOTPROTO=none
USERCTL=no
--是否允许非root用户控制该设备
2.修改被绑定的eth0和eth1的配置文件
vi
/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=“eth0”
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none
HWADDR=00:15:17:CC:FC:35
eth1的配置文件与之相同,只是device的值改为eth1即可。
3.装在bond模块驱动
编辑/etc/modprobe.conf或者/etc/modules.conf文件,加入如下内容,使系统启动时加载bonding模块驱动
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
列出所有网口:ifconfig
上面就是Linux下多网卡绑定bond模式原理的介绍了,bond模式原来一般有7种,这里只介绍了其中的一种,希望对你有所帮助。
系统版本
[root@ ~]# cat /etc/redhat-release
CentOS release 6.8 (Final)
[root@ ~]# uname -r
2.6.32-642.6.1.el6.x86_64
网卡说明
eth0 192.168.1.8(服务器外网卡)
eth1 服务器网卡(内网)
eth2 服务器网卡(内网)
[root@ ~]# /etc/init.d/iptables stop
[root@ ~]# chkconfig iptables off
关闭selinux
[root@ ~]#setenforce 0
[root@ ~]#sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/‘ /etc/selinux/config
禁用NetworkManager
[root@ ~]# /etc/init.d/NetworkManager stop
Stopping NetworkManager daemon: [ OK ]
[root@ ~]# chkconfig NetworkManager off
[root@ ~]# /etc/init.d/network restart
双网卡绑定配置过程
[root@ ~]# cd /etc/sysconfig/network-scripts/
编辑eth1网卡
[root@ network-scripts]# cat >ifcfg-eth1 <>DEVICE=eth1
>ONBOOT=yes
>BOOTPROTO=none
>USERCTL=no
>MASTER=bind0
>EOF
编辑eth2网卡
[root@ network-scripts]# cat >ifcfg-eth2
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
MASTER=bind0
EOF
编辑bind0网卡
[root@ network-scripts]# cat >ifcfg-bind0 <>DEVICE=bind0
>TYPE=Ethernet
>ONBOOT=yes
>BOOTPROTO=none
>IPADDR=10.0.0.8
>NETMASK=255.255.255.0
>GATEWAY=10.0.0.254
>IPV6INIT=no
>USERCTL=no
>EOF
配置bond参数
[root@ network-scripts]# cat >/etc/modprobe.conf <>alias bind0 bonding
>options bind0 miimon=100 mode=6
>EOF
加入开机自启动(/etc/rc.local)
[root@ network-scripts]# cat >>/etc/rc.local <>ifenslave bind0 eth1 eth2
>EOF
重启网络服务
[root@LVS-2 network-scripts]# service network restart
Shutting down interface eth0: [ OK ]
Shutting down interface eth1: [ OK ]
Shutting down interface eth2: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface bind0: WARNING: Deprecated config file /etc/modprobe.conf, all config files belong into /etc/modprobe.d/.
WARNING: Deprecated config file /etc/modprobe.conf, all config files belong into /etc/modprobe.d/.
Determining if ip address 10.0.0.8 is already in use for device bind0..[ OK ]
Bringing up interface eth0: Determining if ip address 192.168.1.8 is already in use for device eth0... [ OK ]
Bringing up interface eth1: RTNETLINK answers: File exists [ OK ]
Bringing up interface eth2: RTNETLINK answers: File exists [ OK ]
配置使绑定立即生效
[root@LVS-2 network-scripts]# ifenslave bind0 eth1 eth2
测试联通
[root@LVS-2 network-scripts]# ping 10.0.0.8
PING 10.0.0.8 (10.0.0.8) 56(84) bytes of data.
64 bytes from 10.0.0.8: icmp_seq=1 ttl=64 time=0.089 ms
64 bytes from 10.0.0.8: icmp_seq=2 ttl=64 time=0.046 ms
^C
--- 10.0.0.8 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1921ms
rtt min/avg/max/mdev = 0.046/0.067/0.089/0.023 ms
此时会发现系统多一个网卡
[root@LVS-2 network-scripts]# ifconfig bind0
bind0
Link encap:Ethernet HWaddr 00:0C:29:CC:9B:5
inet addr:10.0.0.8 Bcast:10.0.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fecc:9b55/64 Scope:LinkUP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:151 errors:0 dropped:0 overruns:0 frame:0
TX packets:3 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:11826 (11.5 KiB) TX bytes:258 (258.0 b)
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)