虛擬化軟件交換機-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:~#
