openvswitch 网络

虚拟化软件交换机-openvswitch

1. 什么是ovs ?

Openvswitch  是一个软件实现出来的虚拟交换,可以实现大型网络的管理变得自动化,同时支持标准得管理接口和协议。

Openvswitch 是可以跨物理服务器,kvm 虚拟机可以通过openvswitch 接入网络,相比于linux bridge 网络openvswitch 网络灵活性更好一些。

2. Ovs (openvswitch ) 概念 

Bridge: bridge可以理解为一个虚拟的以太网交换机,在一个主机上可以创建一个或者多个bridge

Port:  端口可以理解为交换机得端口,每个port 口都属于一个bridge

Interface: 连接port 的网络接口设备,正常情况下是port 与interface 是一对一的关系,如果配置port 为bond 模式,port 与interface可以为一对多

Controller: openflow 控制器,ovs 可以接受一个或者多个openflow 控制器的管理

Datapath:  ovs 中datapatch 和flow table 关联,当datapath 接受到数据后,ovs 可以在flow table 中可以查看到匹配的flow 。

3. ovs 基础创建配置

Ovs 中port 口默认是trunk 模式的,如果想和外部的网络通信需要指定其vlan tag。 我们的ovs 上游服务器的物理端口(这里描述物理网口为eth1) 连接交换机的trunk端口。 这个样我们的网络才可以出去。

相比于传统的linux bridge 网桥,用来实现类似的功能配置起来是比较复杂的。使用ovs 可以以通过ovs-vsctrl set port  $port-name  tag=$vlan-id

安装 ovs 

root@testyk:~# apt-get install openvswitch-switch

执行ovs 命令检查

root@testyk:~# ovs-vsctl show
2cc0eba7-cb3d-41ff-9498-356bdc178880
ovs_version: "2.0.2"

创建ovs 网桥 
root@testyk:~# ovs-vsctl add-br br-test

将物理端口加入网桥中
root@testyk:~# ovs-vsctl add-port br-test eth2
root@testyk:~# ovs-vsctl show
2cc0eba7-cb3d-41ff-9498-356bdc178880
Bridge br-test
Port "eth2"
Interface "eth2"
Port br-test
Interface br-test
type: internal
ovs_version: "2.0.2"

添加新的port 口

root@testyk:~# ovs-vsctl add-port br-test tap

查看ovs 网桥
root@testyk:~# ovs-vsctl show
2cc0eba7-cb3d-41ff-9498-356bdc178880
Bridge br-test
Port "eth2"
Interface "eth2"
Port tap
Interface tap
Port br-test
Interface br-test
type: internal
ovs_version: "2.0.2"

给ovs port 绑定vlan  
root@testyk:~# ovs-vsctl set port tap tag=2
root@testyk:~# ovs-vsctl show
2cc0eba7-cb3d-41ff-9498-356bdc178880
Bridge br-test
Port "eth2"
Interface "eth2"
Port tap
tag: 2
Interface tap
Port br-test
Interface br-test
type: internal
ovs_version: "2.0.2"

4. ovs-bond 配置 

linux 实现的bond ,ovs 也可以实现,bond 可以提高网络的可靠性还可以提高性能。 高可用的bond 都是两块网卡来配置的。 一块可以做冗余

ovs-bond 模式: 

1. active-backup: 将所用的流量分发给一块网卡取用,这块网卡坏了或者down 了回将流量切换给另一块 。

2. balance-slb:  将流量根据mac 和输出的vlan id 在物理网卡之间实现负载均衡

3. balance-tcp: 和blance-slb 类似但是比它实现的功能更多一些,如ip 地址和tcp 端口等,但是这种模式需要上游交换机支持802.3ad 且与lacp 协商成功才可以,如果不满足条件,bodn 的模式模式回回退到balance-slb

创建bond,生成port 名为bond0 的端口将物理网口添加到bond0 口瞎

root@testyk:~# ovs-vsctl add-bond br-test bond0 eth0 eth2 lacp=active

查看ovs端口
root@testyk:~# ovs-vsctl show
2cc0eba7-cb3d-41ff-9498-356bdc178880
Bridge br-test
Port tap
tag: 2
Interface tap
Port "bond0"
Interface "eth2"
Interface "eth0"
Port br-test
Interface br-test
type: internal
ovs_version: "2.0.2"

设置bond 的模式
root@testyk:~# ovs-vsctl set port bond0 bond_mode=balance-slb

检查当前ovs 下所有的bond 
root@testyk:~# ovs-appctl bond/show

5. ovs ovs 中两个网桥怎么连接

如何将两个网桥连接起来,可以理解怎么将两个虚拟交换机连接起来,我们的真实的交换机直接只要由一个网线就可以两台交换机可以连接起来。 怎么在ovs 中实现这个物理网线的作用?

方法一: 利用VETH 设备

veth 设备作用是做反转通信数据,需要发送数据会被转换成所需要的数据进入内核网络层进行处理的,VETH 是成对出现的,一个端口发出数据,veth 会改变数据方向将他送入内核网络核心,完成数据注入,在里一个端口可以读到此数据。

创建两个ovs 网桥

root@testyk:~# ovs-vsctl add-br test1
root@testyk:~# ovs-vsctl add-br test2

root@testyk:~# ovs-vsctl show
2cc0eba7-cb3d-41ff-9498-356bdc178880
Bridge "test1"
Port "test1"
Interface "test1"
type: internal
Bridge "test2"
Port "test2"
Interface "test2"
type: internal
ovs_version: "2.0.2"

创建一对veth 端口
root@testyk:~# ip link add name test-veth0 type veth peer name test-veth1
root@testyk:~#

创建完端口可以通过ip 查看到 (这里可以理解为这是一个网线,这个两个 test-veth0   test-veth1可以理解为网桥两端 )
root@testyk:~# ip a | grep test
8: test1: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1
9: test2: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1
10: test-veth1@test-veth0: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN group default qlen 1000
11: test-veth0@test-veth1: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN group default qlen 1000

将veth 设备加入网桥中
root@testyk:~# ovs-vsctl add-port test1 test-veth0
root@testyk:~# ovs-vsctl add-port test2 test-veth1

检查ovs 
root@testyk:~# ovs-vsctl show
2cc0eba7-cb3d-41ff-9498-356bdc178880
Bridge "test1"
Port "test1"
Interface "test1"
type: internal
Port "test-veth0"
Interface "test-veth0"
Bridge "test2"
Port "test2"
Interface "test2"
type: internal
Port "test-veth1"
Interface "test-veth1"
ovs_version: "2.0.2"

方法2: 利用ovs patch 类型端口实现

创建两个bridge 

root@testyk:~# ovs-vsctl add-br test1
root@testyk:~# ovs-vsctl add-br test2

创建port口

root@testyk:~# ovs-vsctl add-port test1 test-veth0
root@testyk:~# ovs-vsctl add-port test2 test-veth1

设置port 端口为patch 类型

root@testyk:~# ovs-vsctl set interface test-veth0 type=patch
root@testyk:~# ovs-vsctl show
2cc0eba7-cb3d-41ff-9498-356bdc178880
Bridge "test1"
Port "test1"
Interface "test1"
type: internal
Port "test-veth0"
Interface "test-veth0"
type: patch
Bridge "test2"
Port "test2"
Interface "test2"
type: internal
Port "test-veth1"
Interface "test-veth1"
ovs_version: "2.0.2"

设置patch 直接的绑定
root@testyk:~# ovs-vsctl set interface test-veth0 options:peer=test-veth1
root@testyk:~# ovs-vsctl show
2cc0eba7-cb3d-41ff-9498-356bdc178880
Bridge "test1"
Port "test1"
Interface "test1"
type: internal
Port "test-veth0"
Interface "test-veth0"
type: patch
options: {peer="test-veth1"}
Bridge "test2"
Port "test2"
Interface "test2"
type: internal
Port "test-veth1"
Interface "test-veth1"
ovs_version: "2.0.2"
root@testyk:~# ovs-vsctl set interface test-veth1 type=patch
root@testyk:~# ovs-vsctl set interface test-veth1 options:peer=test-veth0
root@testyk:~#
root@testyk:~#
root@testyk:~# ovs-vsctl show
2cc0eba7-cb3d-41ff-9498-356bdc178880
Bridge "test1"
Port "test1"
Interface "test1"
type: internal
Port "test-veth0"
Interface "test-veth0"
type: patch
options: {peer="test-veth1"}
Bridge "test2"
Port "test2"
Interface "test2"
type: internal
Port "test-veth1"
Interface "test-veth1"
type: patch
options: {peer="test-veth0"}
ovs_version: "2.0.2"
root@testyk:~#

原文地址:https://www.cnblogs.com/yk0625/p/14096712.html