CentOS 7 下配置 openvswitch 和 bonding

好风 发表于 2016-11-10T09:02:10.275857Z
引用地址:https://plus.ooclab.com/note/article/1290

情景

HP Proliant Microserver Gen8 有两块千兆网卡,我希望通过 Linux bonding 功能实现:

  1. 服务固定1个IP
  2. 任意一个网卡插上网线,服务器网络即可访问(取出网卡单点故障)
  3. 如果同时插上2根网线,可以增加 gen8 网络IO
  4. 配置 openvswitch (可以提供 KVM/docker 内网地址)

操作

  • br0 为 OVS 网口
  • bond0 为 bonding 网口
  • eno1, eno2 为 gen8 的2个物理网口

配置文件

/etc/sysconfig/network-scripts/ifcfg-br0 内容:

DEVICE=br0
BOOTPROTO=none
IPADDR=192.168.1.130
PREFIX=24
GATEWAY=192.168.1.1
NM_CONTROLLED=no
ONBOOT=yes
TYPE="OVSBridge"
DEVICETYPE="ovs"

/etc/sysconfig/network-scripts/ifcfg-bond0 内容:

DEVICE=bond0
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
BONDING_OPTS="mode=1 miimon=100"
OVS_BRIDGE=br0
TYPE="OVSPort"
DEVICETYPE="ovs"

/etc/sysconfig/network-scripts/ifcfg-eno1 内容:

DEVICE=eno1
MASTER=bond0
SLAVE=yes
USERCTL=no
ONBOOT=yes
BOOTPROTO=none

/etc/sysconfig/network-scripts/ifcfg-eno2 内容:

DEVICE=eno2
MASTER=bond0
SLAVE=yes
USERCTL=no
ONBOOT=yes
BOOTPROTO=none

禁用 NetworkManager :

systemctl disable NetworkManager

重启 network :

systemctl restart network

查看状态

ovs-vsctl:

# ovs-vsctl show
0aa108ab-dffc-4f2c-b4df-d4a29d3fdcbf
    Bridge "br0"
        Port "bond0"
            Interface "bond0"
        Port "br0"
            Interface "br0"
                type: internal
    ovs_version: "2.6.1"
# ifconfig 
bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST>  mtu 1500
        inet6 fe80::3ea8:2aff:fe9f:b57c  prefixlen 64  scopeid 0x20<link>
        ether 3c:a8:2a:9f:b5:7c  txqueuelen 0  (Ethernet)
        RX packets 2481  bytes 438186 (427.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 393  bytes 63223 (61.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.130  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::1054:54ff:fef0:d244  prefixlen 64  scopeid 0x20<link>
        ether 3c:a8:2a:9f:b5:7c  txqueuelen 0  (Ethernet)
        RX packets 2334  bytes 395121 (385.8 KiB)
        RX errors 0  dropped 476  overruns 0  frame 0
        TX packets 354  bytes 58251 (56.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eno1: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether 3c:a8:2a:9f:b5:7c  txqueuelen 1000  (Ethernet)
        RX packets 2319  bytes 403151 (393.7 KiB)
        RX errors 0  dropped 2656  overruns 0  frame 0
        TX packets 349  bytes 59163 (57.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 16  

eno2: flags=6147<UP,BROADCAST,SLAVE,MULTICAST>  mtu 1500
        ether 3c:a8:2a:9f:b5:7c  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 17

bond0 状态(目前只插了一根网线):

# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eno1
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eno1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 3c:a8:2a:9f:b5:7c
Slave queue ID: 0

Slave Interface: eno2
MII Status: down
Speed: Unknown
Duplex: Unknown
Link Failure Count: 0
Permanent HW addr: 3c:a8:2a:9f:b5:7d
Slave queue ID: 0

注意 上面示例中使用了 bonding mode 1 ,关于模式请参考 Types of Network Bonding

资料

  1. Link Aggregation and LACP with Open vSwitch