仓酷云

标题: 带来一篇linux多网卡绑定教程 [打印本页]

作者: 愤怒的大鸟    时间: 2015-1-14 20:34
标题: 带来一篇linux多网卡绑定教程
欢迎大家来到仓酷云论坛!实行情况:RedhatEnterpriseLinux5.2VMwareworkstation7


图一 实行情况网卡设置:三块假造网卡,事情在NAT形式

  1、设置三个网卡及bond0
[root@redhat5~]#cd/etc/sysconfig/network-scripts
[root@redhat5network-scripts]#ls|grepifcfg
ifcfg-bond0
ifcfg-eth0
ifcfg-eth1
ifcfg-eth2
ifcfg-lo
[root@redhat5network-scripts]#

  用vi编纂器编纂ifcfg-eth0,在缘故原由的基本上保保存三个参数的设置便可:DEVICE=eth0,BOOTPROTO=static及ONBOOT=yes,别的的
参数值用#号正文失落或间接删除。

[root@redhat5network-scripts]#viifcfg-eth0
#AdvancedMicroDevices[AMD]79c970[PCnet32LANCE]
DEVICE=eth0
BOOTPROTO=static
#BROADCAST=192.168.249.255
#HWADDR=00:0C:29:42:42:61
#IPADDR=192.168.249.2
#IPV6INIT=yes
#IPV6_AUTOCONF=yes
#NETMASK=255.255.255.0
#NETWORK=192.168.249.0
ONBOOT=yes
~
~
~

"ifcfg-eth0"11L,248C
  别的的两个网卡eth1与eth2的设置与eth0的一样:
[root@redhat5network-scripts]#catifcfg-eth1
#AdvancedMicroDevices[AMD]79c970[PCnet32LANCE]
DEVICE=eth1
ONBOOT=yes
BOOTPROTO=static
#HWADDR=00:0c:29:42:42:6b
[root@redhat5network-scripts]#catifcfg-eth2
#AdvancedMicroDevices[AMD]79c970[PCnet32LANCE]
DEVICE=eth2
ONBOOT=yes
BOOTPROTO=static
#HWADDR=00:0c:29:42:42:75

  以某个网卡为模板创立bond0的设置文件ifcfg-bond0:
[root@redhat5network-scripts]#cpifcfg-eth0bond0
  用vi编纂修正ifcfg-bond0,内容以下,保存DEVICE=bond0,BOOTPROTO=static,IPADDR=192.168.249.2,NETMASK=255.255.2550便可。
[root@redhat5network-scripts]#catifcfg-bond0
#AdvancedMicroDevices[AMD]79c970[PCnet32LANCE]
DEVICE=bond0
BOOTPROTO=static
#BROADCAST=192.168.249.255
#HWADDR=00:0C:29:42:42:61
IPADDR=192.168.249.2
#IPV6INIT=yes
#IPV6_AUTOCONF=yes
NETMASK=255.255.255.0
#NETWORK=192.168.249.0
ONBOOT=yes

  2、编纂/etc/modprobe.conf文件
  在/etc/modprobe.conf文件中增加两行内容:
aliasbond0bonding
optionsbond0miimon=100mode=1

[root@redhat5/]#cat/etc/modprobe.conf
aliaseth0pcnet32
aliasscsi_hostadaptermptbase
aliasscsi_hostadapter1mptspi
aliasscsi_hostadapter2ata_piix
aliassnd-card-0snd-ens1371
optionssnd-card-0index=0
optionssnd-ens1371index=0
removesnd-ens1371{/usr/sbin/alsactlstore0>/dev/null2>&1||:;};/sbin/modprobe-r--ignore-removesnd-ens1371
aliaseth1pcnet32
aliaseth2pcnet32
aliasbond0bonding
optionsbond0miimon=100mode=1
[root@redhat5/]#

  miimon=100暗示网卡形态的检测工夫是100毫秒。mode参数表收集绑定的形式,形式1是三个网卡中只要一个网卡事情,别的的两个做备份。
  3、最初一步让绑定失效
  servicenetworkrestart对网卡及bond0接口等设置失效
[root@redhat5/]#servicenetworkrestart
Shuttingdowninte***cebond0:[OK]
Shuttingdowninte***ceeth0:[OK]
Shuttingdowninte***ceeth1:[OK]
Shuttingdowninte***ceeth2:[OK]
Shuttingdownloopbackinte***ce:[OK]
Bringinguploopbackinte***ce:[OK]
Bringingupinte***cebond0:[OK]
Bringingupinte***ceeth0:[OK]
Bringingupinte***ceeth1:[OK]
Bringingupinte***ceeth2:[OK]
[root@redhat5/]#

  运转ifenslavebond0eth0eth1eth2
[root@redhat5/]#ifenslavebond0eth0eth1eth2
为了让下次重启体系可以主动运转ifenslave下令,要实行上面下令:
[root@redhat5init.d]#echoifenslavebond0eth0eth1eth2>>/etc/rc.local

查验一下:
[root@redhat5/]#cat/etc/rc.local
#!/bin/sh
#
#Thisscriptwillbeexecuted*after*alltheotherinitscripts.
#Youcanputyourowninitializationstuffinhereifyoudont
#wanttodothefullSysVstyleinitstuff.

touch/var/lock/subsys/local
ifenslavebond0eth0eth1eth2

  下面这条下令的意义是bond0为主网卡,别的的为从网卡,个中eth0是以后举动的从网卡,即eth0用来通讯。检察bond0信息:
[root@redhat5/]#cat/proc/net/bonding/bond0
EthernetChannelBondingDriver:v3.2.4(January28,2008)

BondingMode:fault-tolerance(active-backup)
PrimarySlave:None
CurrentlyActiveSlave:eth0
MIIStatus:up
MIIPollingInterval(ms):100
UpDelay(ms):0
DownDelay(ms):0

SlaveInte***ce:eth0
MIIStatus:up
LinkFailureCount:0
PermanentHWaddr:00:0c:29:42:42:61

SlaveInte***ce:eth1
MIIStatus:up
LinkFailureCount:0
PermanentHWaddr:00:0c:29:42:42:6b

SlaveInte***ce:eth2
MIIStatus:up
LinkFailureCount:0
PermanentHWaddr:00:0c:29:42:42:75

  反省绑定效果,用host机一直地向假造机发送icmp数据包,顺次downeth0、eth1,看看收集是不是还能连通。


图二ping假造机



图三 断开假造机的eth0、eth1的网卡




图四 每断开一个网卡会丢一个icmp数据包


  当把eth0、eth1断开后,以后的举动网卡就是eth2了,
[root@redhat5/]#cat/proc/net/bonding/bond0
EthernetChannelBondingDriver:v3.2.4(January28,2008)

BondingMode:fault-tolerance(active-backup)
PrimarySlave:None
CurrentlyActiveSlave:eth2
MIIStatus:up
MIIPollingInterval(ms):100
UpDelay(ms):0
DownDelay(ms):0

SlaveInte***ce:eth0
MIIStatus:down
LinkFailureCount:1
PermanentHWaddr:00:0c:29:42:42:61

SlaveInte***ce:eth1
MIIStatus:down
LinkFailureCount:1
PermanentHWaddr:00:0c:29:42:42:6b

SlaveInte***ce:eth2
MIIStatus:up
LinkFailureCount:0
PermanentHWaddr:00:0c:29:42:42:75
[root@redhat5/]#

  4、多网卡绑定,完成负载平衡
  修正/etc/modprobe.conf文件,mode=0,把绑定形式修正为负载平衡(round-robin)。
[root@redhat5~]#cat/etc/modprobe.conf
aliaseth0pcnet32
aliasscsi_hostadaptermptbase
aliasscsi_hostadapter1mptspi
aliasscsi_hostadapter2ata_piix
aliassnd-card-0snd-ens1371
optionssnd-card-0index=0
optionssnd-ens1371index=0
removesnd-ens1371{/usr/sbin/alsactlstore0>/dev/null2>&1||:;};/sbin/modprobe-r--ignore-removesnd-ens1371
aliaseth1pcnet32
aliaseth2pcnet32
aliasbond0bonding
optionsbond0miimon=100mode=0

[root@redhat5~]#cat/proc/net/bonding/bond0
EthernetChannelBondingDriver:v3.2.4(January28,2008)

BondingMode:loadbalancing(round-robin)
MIIStatus:up
MIIPollingInterval(ms):100
UpDelay(ms):0
DownDelay(ms):0

SlaveInte***ce:eth0
MIIStatus:up
LinkFailureCount:0
PermanentHWaddr:00:0c:29:42:42:61

SlaveInte***ce:eth1
MIIStatus:up
LinkFailureCount:0
PermanentHWaddr:00:0c:29:42:42:6b

SlaveInte***ce:eth2
MIIStatus:up
LinkFailureCount:0
PermanentHWaddr:00:0c:29:42:42:75

  别的形式:
mode=2
[root@redhat5~]#cap/proc/net/bonding/bond0
-bash:cap:commandnotfound
[root@redhat5~]#cat/proc/net/bonding/bond0
EthernetChannelBondingDriver:v3.2.4(January28,2008)

BondingMode:loadbalancing(xor)
TransmitHashPolicy:layer2(0)
MIIStatus:up
MIIPollingInterval(ms):100
UpDelay(ms):0
DownDelay(ms):0

SlaveInte***ce:eth0
MIIStatus:up
LinkFailureCount:0
PermanentHWaddr:00:0c:29:42:42:61

SlaveInte***ce:eth1
MIIStatus:down
LinkFailureCount:0
PermanentHWaddr:00:0c:29:42:42:6b

SlaveInte***ce:eth2
MIIStatus:up
LinkFailureCount:0
PermanentHWaddr:00:0c:29:42:42:75
mode=3
[root@redhat5~]#cat/proc/net/bonding/bond0
EthernetChannelBondingDriver:v3.2.4(January28,2008)

BondingMode:fault-tolerance(broadcast)
MIIStatus:up
MIIPollingInterval(ms):100
UpDelay(ms):0
DownDelay(ms):0

SlaveInte***ce:eth0
MIIStatus:up
LinkFailureCount:0
PermanentHWaddr:00:0c:29:42:42:61

SlaveInte***ce:eth1
MIIStatus:up
LinkFailureCount:0
PermanentHWaddr:00:0c:29:42:42:6b

SlaveInte***ce:eth2
MIIStatus:up
LinkFailureCount:0
PermanentHWaddr:00:0c:29:42:42:75

mode=4
[root@redhat5~]#cat/proc/net/bonding/bond0
EthernetChannelBondingDriver:v3.2.4(January28,2008)

BondingMode:IEEE802.3adDynamiclinkaggregation
TransmitHashPolicy:layer2(0)
MIIStatus:up
MIIPollingInterval(ms):100
UpDelay(ms):0
DownDelay(ms):0

802.3adinfo
LACPrate:slow
ActiveAggregatorInfo:
AggregatorID:1
Numberofports:1
ActorKey:9
PartnerKey:1
PartnerMacAddress:00:00:00:00:00:00

SlaveInte***ce:eth0
MIIStatus:up
LinkFailureCount:0
PermanentHWaddr:00:0c:29:42:42:61
AggregatorID:1

SlaveInte***ce:eth1
MIIStatus:up
LinkFailureCount:0
PermanentHWaddr:00:0c:29:42:42:6b
AggregatorID:2

SlaveInte***ce:eth2
MIIStatus:up
LinkFailureCount:0
PermanentHWaddr:00:0c:29:42:42:75
AggregatorID:3

  必要注重的是:当mode=0能够完成负载平衡但不克不及完成容错。这些机制是必要互换机撑持的。好比:IEEE链路聚合协定。
欢迎大家来到仓酷云论坛!
作者: admin    时间: 2015-1-16 20:37
标题: 带来一篇linux多网卡绑定教程
现在的linux操作系统如redhat,难点,红旗等,都是用这么一个内核,加上其它的用程序(包括X)构成的。
作者: 活着的死人    时间: 2015-2-2 18:05
学习Linux应具备的。[书籍+网络资源]
作者: 精灵巫婆    时间: 2015-2-8 06:02
随着Linux技术的更加成熟、完善,其应用领域和市场份额继续快速增大。目前,其主要应用领域是服务器系统和嵌入式系统。然而,它的足迹已遍布各个行业,几乎无处不在。
作者: 灵魂腐蚀    时间: 2015-2-25 01:00
一些显而易见的小错误还是用vi改正比较方便。以后的大一点的程序就得在Linux下调试了,因为有的头文件在VC里面说找不到。?
作者: 因胸联盟    时间: 2015-3-7 18:22
其次,Linux简单易学,因为我们初学者只是学的基础部分,Linux的结构体系非常清晰,再加上老师循序渐进的教学以及耐心的讲解,使我们理解起来很快,短期内就基本掌握了操作和运行模式。
作者: 老尸    时间: 2015-3-15 17:51
掌握在Linux系统中安装软件,在安装Linux工具盘后大致日常所需的软件都会有,一般网络提供下载的软件都会有安装说明。
作者: 谁可相欹    时间: 2015-3-22 04:15
可以说自己收获很大,基本上完成了老师布置的任务,对于拔高的题目没有去做,因为我了解我的水平,没有时间和精力去做。?




欢迎光临 仓酷云 (http://ckuyun.com/) Powered by Discuz! X3.2