linux7双网卡绑定6,CENTOS 6/7 BONDING模式双网卡绑定

bonding(绑定)是一种linux系统下的网卡绑定技术,可以把服务器上n个物理网卡在系统内部抽象(绑定)成一个逻辑上的网卡,能够提升网络吞吐量、实现网络冗余、负载等功能,有很多优势。

bonding技术是linux系统内核层面实现的,它是一个内核模块(驱动)。使用它需要系统有这个模块, 我们可以modinfo命令查看下这个模块的信息, 一般来说都支持。

bonding技术提供了七种工作模式,在使用的时候需要指定一种,每种有各自的优缺点.

1、balance-rr (mode=0) 默认, 有高可用 (容错) 和负载均衡的功能, 需要交换机的配置,每块网卡轮询发包 (流量分发比较均衡).

2、active-backup (mode=1) 只有高可用 (容错) 功能, 不需要交换机配置, 这种模式只有一块网卡工作, 对外只有一个mac地址。缺点是端口利用率比较低

3、balance-xor (mode=2) 不常用

4、broadcast (mode=3) 不常用

5、802.3ad (mode=4) IEEE 802.3ad 动态链路聚合,需要交换机配置,没用过

6、balance-tlb (mode=5) 不常用

7、balance-alb (mode=6) 有高可用 ( 容错 )和负载均衡的功能,不需要交换机配置 (流量分发到每个接口不是特别均衡)

具体的网上有很多资料,了解每种模式的特点根据自己的选择就行, 一般会用到0、1、4、6这几种模式。

1、查看系统内核是否支持bonding

[root@cobbler-node1 ~]# cat /boot/config-3.10.0-693.el7.x86_64 | grep -i bonding

CONFIG_BONDING=m

2、备份系统自带的网卡配置文件,以及创建bond0网卡配置文件

[root@cobbler-node1 ~]# cd /etc/sysconfig/network-scripts

[root@cobbler-node1 network-scripts]# pwd

/etc/sysconfig/network-scripts

[root@cobbler-node1 network-scripts]# cp -a ifcfg-eth0 ifcfg-eth0.bak

[root@cobbler-node1 network-scripts]# cp -a ifcfg-eth1 ifcfg-eth1.bak

[root@cobbler-node1 network-scripts]# cp -a ifcfg-eth0.bak ifcfg-bond0

3、修改系统eth0、eth1、bond0网卡配置文件

[root@cobbler-node1 network-scripts]# vim ifcfg-eth0

TYPE=Ethernet

BOOTPROTO=none

DEVICE=eth0

ONBOOT=yes

USERCTL=no

MASTER=bond0 #需要和上面的ifcfg-bond0配置文件中的DEVICE的值对应

SLAVE=yes

[root@cobbler-node1 network-scripts]# vim ifcfg-eth1

TYPE=Ethernet

BOOTPROTO=none

DEVICE=eth1

ONBOOT=yes

USERCTL=no

MASTER=bond0 #需要和上面的ifcfg-bond0配置文件中的DEVICE的值对应

SLAVE=yes

[root@cobbler-node1 network-scripts]# vi ifcfg-bond0

TYPE=Bond

BOOTPROTO=none

DEVICE=bond0

ONBOOT=yes

IPADDR=10.129.49.240

NETMASK=255.255.255.0

GATEWAY=10.129.49.1

DNS1=10.112.15.30

DNS2=10.112.15.33

USERCTL=no

BONDING_OPTS="mode=6 miimon=100" #在bond0中加入这一项可以省略配置bonding.conf

4、将eth0、eth1网卡配置文件合并显示

[root@cobbler-node1 network-scripts]# paste ifcfg-eth0 ifcfg-eth1

TYPE=Ethernet TYPE=Ethernet

BOOTPROTO=none BOOTPROTO=none

DEVICE=eth0 DEVICE=eth1

ONBOOT=yes ONBOOT=yes

USERCTL=no USERCTL=no #控制用户是否有修改网卡的权限,必须设置为no,只有root用户才可以修改

MASTER=bond0 MASTER=bond0

SLAVE=yes SLAVE=yes

5、对比eth0、eth1网卡配置文件不同内容

[root@cobbler-node1 network-scripts]# diff ifcfg-eth0 ifcfg-eth1

3c3

< DEVICE=eth0

---

> DEVICE=eth1

6、在/etc/modprobe.d/目录下创建bonding.conf(网卡绑定模式)配置文件

[root@cobbler-node1 network-scripts]# echo -e "alias bond0 bonding\noptions bond0 mode=6 miimon=100" >> /etc/modprobe.d/bonding.conf

[root@cobbler-node1 network-scripts]# cat /etc/modprobe.d/bonding.conf

alias bond0 bonding

options bond0 mode=6 miimon=100

注意:

mode=6代表负载均衡;两块网卡同时工作,增加网络带宽,不需要依赖物理交换机设置

mode=1代表主备切换;只有一块网卡处于活动状态,活动网卡故障切换到备用网卡

miimon=100代表网络链路检测频率100ms检查一次,如果出现问题则切换到备用网卡

7、执行modprobe bonding命令更新加载bonding模块,使其系统支持网卡bonding

[root@cobbler-node1 network-scripts]# modprobe bonding

验证bonding模块是否加载成功,出现如下结果则证明加载成功

[root@cobbler-node1 network-scripts]# lsmod | grep bonding

bonding 145728 0

8、重启系统网络服务

[root@cobbler-node1 network-scripts]# systemctl restart network

9、查看网卡绑定的模式以及绑定的网卡状态信息

[root@cobbler-node1 network-scripts]# cat /proc/net/bonding/bond0

Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: load balancing (round-robin)

MII Status: up

MII Polling Interval (ms): 100

Up Delay (ms): 0

Down Delay (ms): 0

Slave Interface: eth0

MII Status: up

Speed: Unknown

Duplex: Unknown

Link Failure Count: 0

Permanent HW addr: 28:6e:d4:88:ce:5d

Slave queue ID: 0

Slave Interface: eth1

MII Status: up

Speed: Unknown

Duplex: Unknown

Link Failure Count: 0

Permanent HW addr: 28:6e:d4:88:ce:5e

Slave queue ID: 0

10、查看系统网络信息,验证绑定成功

[root@cobbler-node1 network-scripts]# ifconfig

bond0: flags=5187 mtu 1500

inet 10.129.49.240 netmask 255.255.255.0 broadcast 10.129.49.255

inet6 fe80::2a6e:d4ff:fe88:ce5d prefixlen 64 scopeid 0x20

ether 28:6e:d4:88:ce:5d txqueuelen 1000 (Ethernet)

RX packets 1675775 bytes 126050576 (120.2 MiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 3432 bytes 496778 (485.1 KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

eth0: flags=6211 mtu 1500

ether 28:6e:d4:88:ce:5d txqueuelen 1000 (Ethernet)

RX packets 837774 bytes 63015040 (60.0 MiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 1718 bytes 237790 (232.2 KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

eth1: flags=6211 mtu 1500

ether 28:6e:d4:88:ce:5d txqueuelen 1000 (Ethernet)

RX packets 838224 bytes 63053418 (60.1 MiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 1714 bytes 258988 (252.9 KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值