Centos7双网卡绑定

(一)简述
1.双网卡绑定技术在centos7中使用了teaming技术,而在rhel6/centos7中使用的是bonding技术,
在centos7中双网卡绑定既能使用teaming也可以使用bonding,这里推荐使用teaming技术,方便与查看和监控。

  1. 原理
    这里介绍两种最常见的双网卡绑定模式:
    (1) roundrobin - 轮询模式
    所有链路处于负载均衡状态,这种模式的特点增加了带宽,同时支持容错能力。
    (2) activebackup - 主备模式
    一个网卡处于活动状态,另一个处于备份状态,所有流量都在主链路上处理,当活动网卡down掉时,启用备份网卡。
    3.查看服务器的相关信息:

    [[email protected]calhost ~]# nmcli dev
    DEVICE  TYPE      STATE        CONNECTION
    em1     ethernet  connected   --
    em2     ethernet  connected    --
    em3     ethernet  unavailable  --
    em4     ethernet  unavailable  --
    lo      loopback  unmanaged    --
    [[email protected] ~]# ip a
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
    2: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master team0 state UP qlen 1000
    link/ether 36:3c:c4:19:d0:ef brd ff:ff:ff:ff:ff:ff
    3: em2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master team0 state UP qlen 1000
    link/ether 36:3c:c4:19:d0:ef brd ff:ff:ff:ff:ff:ff
    4: em3: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN qlen 1000
    link/ether 24:6e:96:a2:dd:ae brd ff:ff:ff:ff:ff:ff
    5: em4: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN qlen 1000
    link/ether 24:6e:96:a2:dd:af brd ff:ff:ff:ff:ff:ff
    18: team0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
    link/ether 36:3c:c4:19:d0:ef brd ff:ff:ff:ff:ff:ff
    inet 10.128.105.156/24 brd 10.128.105.255 scope global team0
       valid_lft forever preferred_lft forever
    inet6 fe80::718:e575:f031:47d4/64 scope link
       valid_lft forever preferred_lft forever

    ###########其中state UP 为网卡有网线或启用的网口,有上边的参数可知,em1和em2有网线接口,其他的网口没有。lo为本地回环网卡

(二)Roundrobin(轮询)安装步骤
1,查看网卡的连接信息:nmcli con sh

[[email protected] ~]# nmcli con sh
NAME         UUID                                  TYPE            DEVICE
em1          4c8a8aee-327b-4f29-9ec4-ea2b2551420b  802-3-ethernet  --
em2          62bde3ef-9f40-42aa-9b3a-4fe8b1aabf42  802-3-ethernet  --
em3          56ef9d05-3a5d-4cd6-af5b-3d39adce619f  802-3-ethernet  --
em4          761f7809-d10c-4e3b-bc06-c0906ca55d1c  802-3-ethernet  --  

2,删除无用的网卡:nmcli con del em3

[[email protected] ~]# nmcli con del em3
Connection ‘em3‘ (56ef9d05-3a5d-4cd6-af5b-3d39adce619f) successfully deleted.
[[email protected] ~]# nmcli con sh
NAME         UUID                                  TYPE            DEVICE
em1          4c8a8aee-327b-4f29-9ec4-ea2b2551420b  802-3-ethernet  --
em2          62bde3ef-9f40-42aa-9b3a-4fe8b1aabf42  802-3-ethernet  --
em4          761f7809-d10c-4e3b-bc06-c0906ca55d1c  802-3-ethernet  --  

3,# 使用nmcli命令操作,创建team接口team0,同时设置teaming模式为roundrobin

[[email protected] ~]# nmcli con add type team con-name team0 ifname team0 config ‘{"runner":{"name": "roundrobin"}}‘
[[email protected] ~]# nmcli con sh
NAME         UUID                                  TYPE            DEVICE
team0        5a1976d7-2c91-456e-8dda-0b12c6ef0c04  team            team0
em1          4c8a8aee-327b-4f29-9ec4-ea2b2551420b  802-3-ethernet  --
em2          62bde3ef-9f40-42aa-9b3a-4fe8b1aabf42  802-3-ethernet  --
em4          761f7809-d10c-4e3b-bc06-c0906ca55d1c  802-3-ethernet  -- 

4,给接口team0设置ip地址和网关,并取消手动模式:

[[email protected] ~]# nmcli con modify team0 ipv4.address ‘10.128.105.157/24‘ ipv4.gateway ‘10.128.105.254‘
###设置为手动模式,取消DHCP
[[email protected] ~]# nmcli con modify team0 ipv4.method manual

5,使用ifup team0 启用team0网卡,然后重启网络服务。

[[email protected] ~]# ifup team0
[[email protected] ~]# /etc/init.d/network restart
Restarting network (via systemctl):                        [  OK  ]
[[email protected] ~]# ip a |grep team0
2: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master team0 state UP qlen 1000
10: team0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
    inet 10.128.105.157/24 brd 10.128.105.255 scope global team0

6,再次将两张物理网卡添加到team

[[email protected] ~]# nmcli con add type team-slave con-name team0-port2 ifname em1 master team0
Connection ‘team0-port2‘ (e01c37f5-b3a1-4e6d-96ab-a6e676ad3c32) successfully added.
[[email protected] ~]# nmcli con add type team-slave con-name team0-port2 ifname em2 master team0
Connection ‘team0-port2‘ (8b13a9de-d64c-44fc-a86d-ea45d2f511cf) successfully added.
[[email protected] ~]# nmcli con sh
NAME         UUID                                  TYPE            DEVICE
team0        64b123d5-189d-43b0-a850-77d47c0da86c  team            team0
team0-port1  24181898-bffe-4ae1-90e8-f47da64b5512  802-3-ethernet  em1
team0-port2  8b13a9de-d64c-44fc-a86d-ea45d2f511cf  802-3-ethernet  em2
em1          4c8a8aee-327b-4f29-9ec4-ea2b2551420b  802-3-ethernet  --
em2          62bde3ef-9f40-42aa-9b3a-4fe8b1aabf42  802-3-ethernet  --
em4          761f7809-d10c-4e3b-bc06-c0906ca55d1c  802-3-ethernet  --  

7,现在查看team0的状态模式是否是roundrobin。teamdctl team0 st

[[email protected] ~]# teamdctl team0 st
setup:
  runner: roundrobin
ports:
  em1
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
        down count: 0
  em2
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
        down count: 0

这样,team模式的roundrobin搭建成功。

8,测试是否正常工作
8.1,首先把em1网卡禁用,用其他的服务器ping看是否断。

[[email protected] etc]# ifdown em1
Device ‘em1‘ successfully disconnected.
[[email protected] etc]# nmcli con sh
NAME         UUID                                  TYPE            DEVICE
team0        64b123d5-189d-43b0-a850-77d47c0da86c  team            team0
team0-port2  8b13a9de-d64c-44fc-a86d-ea45d2f511cf  802-3-ethernet  em2
em1          4c8a8aee-327b-4f29-9ec4-ea2b2551420b  802-3-ethernet  --
em2          62bde3ef-9f40-42aa-9b3a-4fe8b1aabf42  802-3-ethernet  --
em4          761f7809-d10c-4e3b-bc06-c0906ca55d1c  802-3-ethernet  --
team0-port1  24181898-bffe-4ae1-90e8-f47da64b5512  802-3-ethernet  --
[[email protected] ~]# teamdctl team0 st
setup:
  runner: roundrobin
ports:
  em2
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
        down count: 0



从上图看出实在正常的。

8.2,把网卡em1启用,em2禁用查看下下
[[email protected] etc]# ifup em1
[[email protected] etc]# nmcli con sh
NAME         UUID                                  TYPE            DEVICE
team0        64b123d5-189d-43b0-a850-77d47c0da86c  team            team0
team0-port1  24181898-bffe-4ae1-90e8-f47da64b5512  802-3-ethernet  em1
team0-port2  8b13a9de-d64c-44fc-a86d-ea45d2f511cf  802-3-ethernet  em2
em1          4c8a8aee-327b-4f29-9ec4-ea2b2551420b  802-3-ethernet  --
em2          62bde3ef-9f40-42aa-9b3a-4fe8b1aabf42  802-3-ethernet  --
em4          761f7809-d10c-4e3b-bc06-c0906ca55d1c  802-3-ethernet  --
[[email protected] etc]# ifdown em2
Device ‘em2‘ successfully disconnected.
[[email protected] etc]# nmcli con sh
NAME         UUID                                  TYPE            DEVICE
team0        64b123d5-189d-43b0-a850-77d47c0da86c  team            team0
team0-port1  24181898-bffe-4ae1-90e8-f47da64b5512  802-3-ethernet  em1
em1          4c8a8aee-327b-4f29-9ec4-ea2b2551420b  802-3-ethernet  --
em2          62bde3ef-9f40-42aa-9b3a-4fe8b1aabf42  802-3-ethernet  --
em4          761f7809-d10c-4e3b-bc06-c0906ca55d1c  802-3-ethernet  --
team0-port2  8b13a9de-d64c-44fc-a86d-ea45d2f511cf  802-3-ethernet  --    

网卡流量em2没变,而em1变化了。

(三)双网卡绑定activebackup的实现
具体的大概步骤和上边差不多,省略如下:
(首先删除刚才绑定的网卡模式轮询:nmcli con del team0 team0-port1 team0-port2)

1, 添加逻辑网卡team0,并启用activebackup模式
[[email protected] ~]# nmcli con add type team con-name team0 ifname team0 config ‘{"runner":{"name":"activebackup"}}‘

2, 绑定ip

[[email protected] ~]# nmcli con modify team0 ipv4.address 10.128.105.157/24  ipv4.gateway 10.128.105.254
[[email protected] ~]# nmcli con modify team0 ipv4.method manual

3, 添加物理网卡到activebackup模式

[[email protected] ~]# nmcli con add type team-slave con-name team0-port1 ifname em1 master team0
Connection ‘team0-port1‘ (24181898-bffe-4ae1-90e8-f47da64b5512) successfully added.
[[email protected] ~]# nmcli con add type team-slave con-name team0-port2 ifname em2 master team0
Connection ‘team0-port2‘ (8b13a9de-d64c-44fc-a86d-ea45d2f511cf) successfully added.

4,查看状态

[[email protected] ~]# teamdctl team0 st
setup:
 runner: activebackup
ports:
 em1
  link watches:
   link summary: up
   instance[link_watch_0]:
    name: ethtool
    link: up
    down count: 0
 em2
  link watches:
   link summary: up
   instance[link_watch_0]:
    name: ethtool
    link: up
    down count: 0
runner:
 active port: em1

成功,处于活动中的网卡为 eno33554984

备注:注意 在做网卡绑定的时候,如果发现物理网卡总是无法绑定到team0,请检查该物理网卡是否处于up状态。还有就是主备模式在切换的过程中会有间隔,会丢几个包。

原文地址:http://blog.51cto.com/liqingbiao/2089733

时间: 2024-10-07 12:16:24

Centos7双网卡绑定的相关文章

RHEL7/CentOS7双网卡绑定-Network Teaming

RHEL7/CentOS7 Configure Network Teaming Network Teaming可联合或合并物理网络接口,形成具有较高吞吐量或冗余方式的逻辑网络接口.其作为网卡绑定的备选方式出现,在系统中和传统的bonding方式并存. 1. 系统环境 [[email protected] ~]# uname -a [[email protected] ~]# uname -a Linux test03 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19

centos7双网卡绑定bond0

Centos7双网卡主备模式配置(bond0)   通过双网卡设置主备模式,实现当一块网卡宕掉时,另外一块网卡可以自动顶替宕掉的网卡工作,保障网络正常访问. 1.修改网卡配置文件 切换工作目录 cd /etc/sysconfig/network-scripts/ 修改网卡配置文件ifcfg-eth0,保证以下内容正确: TYPE=Ethernet BOOTPROTO=none DEVICE=eth0 MASTER=bond0 SLAVE=yes ONBOOT=yes 修改网卡配置文件ifcfg-

Centos7 / RHEL 7 双网卡绑定

2. 原理    这里介绍两种最常见的双网卡绑定模式:        (1) roundrobin - 轮询模式            所有链路处于负载均衡状态,这种模式的特点增加了带宽,同时支持容错能力.        (2) activebackup - 主备模式            一个网卡处于活动状态,另一个处于备份状态,所有流量都在主链路上处理,当活动网卡down掉时,启用备份网卡. 在centos7中要生成网卡配置文件的方法很简单,使用如下命令: # 查看物理网卡信息 [[emai

centos7双网卡bond失败

centos7服务器进行双网卡绑定 配置文件 #cat ifcfg-em1 TYPE=Ethernet BOOTPROTO=none DEFROUTE=yes NAME=em1 DEVICE=em1 ONBOOT=yes MASTER=bond0 SLAVE=yes # cat ifcfg-em2 TYPE=Ethernet BOOTPROTO=none IPV4_FAILURE_FATAL=no NAME=em2 ONBOOT=yes MASTER=bond0 SLAVE=yes # cat 

Linux下bond双网卡绑定

bond,是一种双网卡绑定技术.即将多块物理网卡绑定成一个逻辑网卡,并实现网卡冗余.流量均衡等的一种可靠性强且高可用技术. 七种bond模式: 一.mod=0即banlance-rr(平衡轮循环策略) 特点:传输数据包的顺序是依次传输,第一个走eth0,第二个包走eth1--一直这样循环下去,直到传输完成.该模式提供负载均衡和容错能力. 假如当一个连接或会话的数据包从不同的接口发出,并经过不同的链路,客户端可能会出现数据包无序到达的情况,这样导致无序到达的数据需重新被发送,便会导致网络的吞吐量的

网络服务高可用——双网卡绑定同一IP

很多时候,企业里面的一些关键型网络服务,不仅数据吞量相当大,而且还不允许随便离线的,所以就要求我们的网络服务一定要具有高可用性.数据吞吐量大,很多人就说了,这个简单,在我们的关键业务服务器上多装几张网卡,均衡流量负载也就可以了.但如果多网卡,多IP,不仅浪费了IP资源,更麻烦的事在客户访问的过程中如果出现了某张网卡离线的情况时,还需要重新连接另一IP的网卡才能继续会话,这是一件很头疼的事,有没有一个两全其美的办法了.有,其实操作起来也很简单,那么今天就给大家分享一下,如何实现双网卡绑定同一IP,

Centos 6.5 64位双网卡绑定

1.环境描述      我的Vmware workstation 10 安装Centos 6.5 64位加上双口的Intel千兆网卡,通过ifconfig -a|grep eth命令看到eth2和eth3两张网卡. 2.双网卡绑定步骤: 2.1 修改/etc/sysconfig/network-scripts/ifcfg-eth2配置文档,修改后的内容如下:    DEVICE=eth2       ONBOOT=yes              #系统启动时自动启用该设备    BOOTPRO

LINUX 双网卡绑定

cd /etc/sysconfig/network-scripts cp ifcfg-eth0  bak.ifcfg-eth0 cp ifcfg-eth1  bak.ifcfg-eth1 vi ifcfg-bond0 DEVICE=bond0 BROADCAST=192.168.190.255 IPADDR=192.168.190.11 NETMASK=255.255.255.0 GATEWAY=192.168.190.1 ONBOOT=yes USERCTL=no BOOTPROTO=none

Linux双网卡绑定和解除绑定的实现

? 双网卡绑定实现就是使用两块网卡虚拟成为一块网卡,这个聚合起来的设备看起来是一个单独的以太网接口设备,通俗点讲就是两块网卡具有相同的IP地址而并行链接聚合成一个逻辑链路工作.根据交换机可支持的功能不同,最常见的是设定为主备方式的双网卡绑定.Linux双网卡绑定和解除绑定的实现