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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1、Bond的工作模式 Linux bonding驱动提供了一个把多个网络接口设备捆为单个的网络接口设置来使用,用于网络负载均衡及网络冗余。 bonding一共有7种工作模式(mode): 1)、bond=0,(balance-rr) Round-robin policy: (平衡轮询策略):传输数据包顺序是依次传输,直到最后一个传输完毕,此模式提供负载平衡和容错能力。 2)、bond=1,(active-backup) Active-backup policy:(活动备份策略):只有一个设备处于活动状态。一个宕掉另一个马上由备份转换为主设备。mac地址是外部可见得。此模式提供了容错能力。 3)、bond=2,(balance-xor) XOR policy:(平衡策略):传输根据[(源MAC地址xor目标MAC地址)mod设备数量]的布尔值选择传输设备。 此模式提供负载平衡和容错能力。 4)、bond=3,(broadcast) Broadcast policy:(广播策略):将所有数据包传输给所有设备。此模式提供了容错能力。 5)、bond=4,(802.3ad) IEEE 802.3ad Dynamic link aggregation. IEEE 802.3ad 动态链接聚合:创建共享相同的速度和双工设置的聚合组。此模式提供了容错能力。每个设备需要基于驱动的重新获取速度和全双工支持;如果使用交换机,交换机也需启用 802.3ad 模式。 6)、bond=5,(balance-tlb) Adaptive transmit load balancing(适配器传输负载均衡):通道不需要专用的交换机支持。发出的流量根据当前负载分给每一个设备。由当前设备处理接收,如果接受的设 备传不通就用另一个设备接管当前设备正在处理的mac地址。 7)、bond=6,(balance-alb) Adaptive load balancing: (适配器负载均衡):包括mode5,由 ARP 协商完成接收的负载。bonding驱动程序截获 ARP在本地系统发送出的请求,用其中之一的硬件地址覆盖从属设备的原地址。就像是在服务器上不同的人使用不同的硬件地址一样。
CentOS 7.6上实现双网卡teaming,可以按照以下步骤进行操作: 1. 确认系统中已经安装 teaming 相关软件包,如果没有安装,可以使用以下命令安装: ``` yum install -y teamd teamd-devel libteam ``` 2. 编辑网卡配置文件,例如 eth0 和 eth1,可以使用 vim 或者其他编辑器打开 /etc/sysconfig/network-scripts 目录下的 ifcfg-eth0 和 ifcfg-eth1 文件。 ``` vim /etc/sysconfig/network-scripts/ifcfg-eth0 ``` ``` vim /etc/sysconfig/network-scripts/ifcfg-eth1 ``` 在这两个文件中都添加以下内容: ``` TEAM_MASTER=team0 TEAM_PORT_CONFIG='{"prio": 100}' ``` 其中 TEAM_MASTER 指了 teaming 的主设备名称,这里取名为 team0;TEAM_PORT_CONFIG 义了端口的优先级,这里设置为 100。 3. 创建 team0 设备配置文件,可以使用以下命令创建 /etc/sysconfig/network-scripts/ifcfg-team0 文件。 ``` vim /etc/sysconfig/network-scripts/ifcfg-team0 ``` 在该文件中添加以下内容: ``` DEVICE=team0 DEVICETYPE=Team TEAM_CONFIG='{"runner": {"name": "activebackup"}}' BOOTPROTO=none ONBOOT=yes ``` 其中 TEAM_CONFIG 义了 teaming 的模式,这里设置为 activebackup(主备模式)。 4. 重启网络服务,使配置生效。 ``` systemctl restart network ``` 或者使用以下命令重启 teaming 服务。 ``` systemctl restart teamd ``` 5. 验证 teaming 是否生效,可以使用以下命令查看 teaming 设备的状态。 ``` teamdctl team0 state ``` 如果输出类似以下内容,说明 teaming 配置成功。 ``` setup: runner: activebackup ports: eth0 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up eth1 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up runner: active port: eth0 ``` 至此,双网卡 teaming 实现 mod=1 activebackup 主备模式的配置完成。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值