linux下绑定双网卡

简介:

linux 下绑定双网卡


系统环境:

操作系统: RedHat EL55

wKiom1M6fhKwdgYLAAA4kMgRAJE381.jpg


     双网卡绑定单个IP 地址为了提供网络的高可用性,我们可能需要将多块网卡绑定成一块虚拟网卡对外提供服务,这样即使其中的一块物理网卡出现故障,也不会导致连接中断。

    为了提供网络的高可用性,我们可能需要将多块网卡绑定成一块虚拟网卡对外提供服务,这样即使其中的一块物理网卡出现故障,也不会导致连接中断。在Linux下叫bondingIBM称为etherchanelbroadcomteam

1、查看内核是否支持网卡绑定


[root@bjsrv ~]# modinfo bonding

filename:       /lib/modules/2.6.18-194.el5xen/kernel/drivers/net/bonding/bonding.ko

author:         Thomas Davis, tadavis@lbl.gov and many others

description:    Ethernet Channel Bonding Driver, v3.4.0

version:        3.4.0

license:        GPL

srcversion:     A2FB5CCCDB38BE9A099CC9C

depends:        ipv6

vermagic:       2.6.18-194.el5xen SMP mod_unload 686 REGPARM 4KSTACKS gcc-4.1

parm:           max_bonds:Max number of bonded devices (int)

parm:           num_grat_arp:Number of gratuitous ARP packets to send on failover event (int)

parm:           num_unsol_na:Number of unsolicited IPv6 Neighbor Advertisements packets to send on failover event (int)

parm:           miimon:Link check interval in milliseconds (int)

parm:           updelay:Delay before considering link up, in milliseconds (int)

parm:           downdelay:Delay before considering link down, in milliseconds (int)

parm:           use_carrier:Use netif_carrier_ok (vs MII ioctls) in miimon; 0 for off, 1 for on (default) (int)

parm:           mode:Mode of operation : 0 for balance-rr, 1 for active-backup, 2 for balance-xor, 3 for broadcast, 4 for 802.3ad, 5 for balance-tlb, 6 for balance-alb (charp)

parm:           primary:Primary network device to use (charp)

parm:           primary_reselect:Reselect primary slave once it comes up; 0 for always (default), 1 for only if speed of primary is better, 2 for only on active slave failure (charp)

parm:           lacp_rate:LACPDU tx rate to request from 802.3ad partner (slow/fast) (charp)

parm:           xmit_hash_policy:XOR hashing method: 0 for layer 2 (default), 1 for layer 3+4 (charp)

parm:           arp_interval:arp interval in milliseconds (int)

parm:           arp_ip_target:arp targets in n.n.n.n form (array of charp)

parm:           arp_validate:validate src/dst of ARP probes: none (default), active, backup or all (charp)

parm:           fail_over_mac:For active-backup, do not set all slaves to the same MAC.  none (default), active or follow (charp)

parm:           debug:Print debug messages; 0 for off (default), 1 for on (int)

module_sig:     883f3504ba03af81e1fa4939f6a629311282410a0c9263f8f3007023d923512d2ecbb7e81cefc609f41f79cd9bf13e480d0b17e94899d3c4408c6a6

[root@bjsrv ~]#


2、配置虚拟网卡


[root@bjsrv ~]# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-bond0

[root@bjsrv ~]#


[root@bjsrv ~]# cat /etc/sysconfig/network-scripts/ifcfg-bond0

# Intel Corporation 82540EM Gigabit Ethernet Controller

DEVICE=bond0

BOOTPROTO=static

IPADDR=192.168.10.254

NETMASK=255.255.255.0

GATEWAY=192.168.10.1

ONBOOT=yes

[root@bjsrv ~]#


[root@bjsrv ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1

# Intel Corporation 82540EM Gigabit Ethernet Controller

DEVICE=eth1

BOOTPROTO=none

ONBOOT=yes

MASTER=bond0

SLAVE=yes

[root@bjsrv ~]#


[root@bjsrv ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth2

# Intel Corporation 82540EM Gigabit Ethernet Controller

DEVICE=eth2

BOOTPROTO=none

ONBOOT=yes

MASTER=bond0

SLAVE=none

[root@bjsrv ~]#


[root@bjsrv ~]# grep  bond /etc/modprobe.d/modprobe.conf.dist

alias bond0 bonding

options bond0 miimon=100 mode=1

[root@bjsrv ~]# grep  bond /etc/modprobe.conf

alias bond0 bonding

options bond0 miimon=100 mode=1


三、参数说明


options bond0 miimon=100 mode=1

如果达到负载均衡的目的,应该是0,1是热备状态。

miimon是毫秒数,每100毫秒触发检测线路稳定性的事件。

mode= 是ifenslave的工作状态。

一共有7种方式:

=0: (balance-rr) Round-robin policy: (平衡抡循环策略):传输数据包顺序是依次传输,直到最后一个传输完毕,

     此模式提供负载平衡和容错能力,这需要设置交换机的配合才能完成。

=1: (active-backup) Active-backup policy:(主-备份策略):只有一个设备处于活动状态。

     一个宕掉另一个马上由备份转换为主设备。mac地址是外部可见得。 此模式提供了容错能力。

=2:(balance-xor) XOR policy:(广播策略):将所有数据包传输给所有接口。 此模式提供了容错能力。

=3:(balance-xor) XOR policy:   (平衡 策略): 传输根据原地址布尔值选择传输设备。

    此模式提供负载平衡和容错能力。

=4:(802.3ad) IEEE 802.3ad Dynamic link aggregation.  

    IEEE 802.3ad 动态链接聚合:创建共享相同的速度和双工设置的聚合组。

=5:(balance-tlb) Adaptive transmit load balancing(适配器传输负载均衡)

   :没有特殊策略,第一个设备传不通就用另一个设备接管第一个设备正在处理的mac地址,帮助上一个传。

=6:(balance-alb) Adaptive load balancing: (适配器传输负载均衡):大致意思是包括mode5,bonding驱动程序截获 ARP 在本地系统发送出的请求,用其中之一的硬件地址覆盖从属设备的原地址。就像是在服务器上不同的人使用不同的硬件地址一样。


四、重新启动网络服务


[root@bjsrv ~]#service network restart

Shutting down interface bond0:  [  OK  ]

Shutting down interface eth0:  [  OK  ]

Shutting down loopback interface:  [  OK  ]

Bringing up loopback interface:  [  OK  ]

Bringing up interface bond0:  [  OK  ]

Bringing up interface eth0:  [  OK  ]


五、查看虚拟网卡信息


[root@bjsrv ~]# cat /proc/net/bonding/bond0

Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008)


Bonding Mode: fault-tolerance (active-backup)

Primary Slave: None

Currently Active Slave: eth1

MII Status: up

MII Polling Interval (ms): 100

Up Delay (ms): 0

Down Delay (ms): 0


Slave Interface: eth1

MII Status: up

Link Failure Count: 0

Permanent HW addr: 08:00:27:99:ce:df


Slave Interface: eth2

MII Status: up

Link Failure Count: 0

Permanent HW addr: 08:00:27:ce:7a:4d

[root@bjsrv ~]#


[root@bjsrv ~]# netstat -nr

Kernel IP routing table

Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface

192.168.10.0    0.0.0.0         255.255.255.0   U         0 0          0 bond0

192.168.122.0   0.0.0.0         255.255.255.0   U         0 0          0 virbr0

192.168.8.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0

169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0

0.0.0.0         192.168.10.1    0.0.0.0         UG        0 0          0 bond0

[root@bjsrv ~]#


六、down 掉主网卡测试

wKioL1M6f77RnEA9AALVyytdXTg870.jpg

  在测试中,主网卡down 后,会有连接超时,但会立刻联通备份网卡!

查看虚拟网卡状态:

[root@bjsrv ~]# cat /proc/net/bonding/bond0

Ethernet Channel Bonding Driver: v3.4.0 (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: eth1

MII Status: down

Link Failure Count: 1

Permanent HW addr: 08:00:27:99:ce:df


Slave Interface: eth2

MII Status: up

Link Failure Count: 0

Permanent HW addr: 08:00:27:ce:7a:4d

[root@bjsrv ~]#










本文转自 客居天涯 51CTO博客,原文链接:http://blog.51cto.com/tiany/1388453,如需转载请自行联系原作者
相关实践学习
部署高可用架构
本场景主要介绍如何使用云服务器ECS、负载均衡SLB、云数据库RDS和数据传输服务产品来部署多可用区高可用架构。
负载均衡入门与产品使用指南
负载均衡(Server Load Balancer)是对多台云服务器进行流量分发的负载均衡服务,可以通过流量分发扩展应用系统对外的服务能力,通过消除单点故障提升应用系统的可用性。 本课程主要介绍负载均衡的相关技术以及阿里云负载均衡产品的使用方法。
目录
相关文章
|
4月前
|
Linux 调度
linux中进程与cpu核的绑定
linux中进程与cpu核的绑定
73 0
|
16天前
|
运维 网络协议 Linux
Linux(28) Linux双网卡配置为连接到Linux主机的PC提供外网访问
Linux(28) Linux双网卡配置为连接到Linux主机的PC提供外网访问
51 1
|
10月前
|
Linux
Linux系统的目录绑定配置
Linux系统的目录绑定配置
88 2
|
10月前
|
Linux
Linux 设置双网卡通信,外网网卡和内网网卡
Linux 设置双网卡通信,外网网卡和内网网卡
310 0
|
11月前
|
Linux Go 人机交互
嵌入式linux之go语言开发(十三)LittlevGL,漂亮的嵌入式GUI的go语言绑定
嵌入式linux之go语言开发(十三)LittlevGL,漂亮的嵌入式GUI的go语言绑定
|
缓存 Linux API
Linux 中用c++实现线程绑定CPU
Linux 中用c++实现线程绑定CPU
592 0
Linux 中用c++实现线程绑定CPU
|
Web App开发 存储 Unix
【Linux】【操作】Linux操作集锦系列之三——进程管理系列之(五)进程与控制终端(shell)去绑定(解耦)的操作
【Linux】【操作】Linux操作集锦系列之三——进程管理系列之(五)进程与控制终端(shell)去绑定(解耦)的操作
131 0
【Linux】【操作】Linux操作集锦系列之三——进程管理系列之(五)进程与控制终端(shell)去绑定(解耦)的操作
|
XML 安全 Linux
Linux下双网卡Firewalld的配置流程
实验室拟态存储的项目需要通过LVS-NAT模式通过LVS服务器来区隔内外网的服务,所以安全防护的重心则落在了LVS服务器之上。笔者最终选择通过firewalld放行端口的方式来实现需求,由于firewall与传统Linux使用的iptable工具有不小的区别,接下来通过博客来记录一下firewalld的配置流程。
1799 0
|
网络协议 Linux .NET
使用.NetCore在Linux上写TCP listen 重启后无法绑定地址
拥抱.net core的过程中, 将公司的一套java项目改成了.net core 2.0版的. 里面的tcp服务被我用msdn的SocketAsyncEventArgs方式重写了, 然而在测试的过程中发现, 偶尔会出现重启无法再次绑定监听的情况.
1640 0
|
Linux
linux修改主机名,关闭图形化界面,绑定ip地址,修改ip地址
1关闭图形化界面 vi /etc/inittab 改成id:3:initdefault: 注意:不要选0或6 2.修改主机名 vi /etc/sysconfig/network   修改即可 3,修改ip地址 vi /etc/sysconfig/network-scripts/ifcfg-eth0   4.
1145 0