Ubuntu 20.04 上学习Open vSwitch :VxLAN
创始人
2024-03-01 13:24:42
0

参考
OpenvSwitch完全使用手册
云计算底层技术-使用openvswitch
Open vSwitch 概述;OVS支持的功能;ovs的模块介绍(ovs-vswitchd、ovsdb-server等等

学习环境

学习 OpenStack

2 个 Hyper-V 虚拟机

  1. Ubuntu 20.04
    203.0.113.101 /24 ( 网关:203.0.113.1 )

  2. Ubuntu 20.04
    203.0.113.103 /24 ( 网关:203.0.113.1 )

连接示意图
在这里插入图片描述

安装 openvswitch-switch

  1. 先看 OpenStacj 文档
    OVN Manual install & Configuration

摘录 Ubuntu 相关部分:

Ubuntu/Debian includes ovn-central, ovn-host, ovn-docker, and ovn-common packages that pull in the appropriate Open vSwitch dependencies as needed.

  1. 再看 Open vSwaitch 文档

Distributions packaging Open vSwitch

摘录 Ubuntu 相关部分:
Debian and Ubuntu has openvswitch-switch and openvswitch-common packages that includes the core userspace components of the switch

  1. apt 安装
    apt install openvswitch-switch

    apt install python3-pip

    pip3 install networking-ovn==4.0.4

    apt install ovn-central ovn-common ovn-host

    查询确认一下:
    dpkg -l |grep openvswitch

     	ii  openvswitch-common                    2.13.8-0ubuntu1                       amd64        Open vSwitch common componentsii  openvswitch-switch                    2.13.8-0ubuntu1                       amd64        Open vSwitch switch implementationsii  python3-openvswitch                   2.13.8-0ubuntu1                       all          Python 3 bindings for Open vSwitch
    

    pip3 list |grep ovn

     networking-ovn         4.0.4   
    

如果需要使用 ifconfig 和 route 命令,先安装 apt install net-tools
如果很熟悉 ip 指令,可以不必安装

建立 Provider networks

一个网桥(bridge)就是一个交换机

2 个虚拟机各建立一个 bridge,就相当于各自接入一个交换机
如果这 2 个交换机被分配到同一个网段,就可以直接互相访问彼此
将这个 bridge 上一个端口 (port )连接到物理网卡 (例如: eth1),他就可以通过这个物理网卡和外部网络互相访问 (即:连接到公网)

在 OpenStack 里面,相当于给所有节点提供一个公网 (Provider networks)

在 203.0.113.101 上

ovs-vsctl del-br br1
ovs-vsctl add-br br1ovs-vsctl add-port br1 eth1
ifconfig eth1 0 up
ifconfig br1 203.0.113.101 up

在 203.0.113.103 上

ovs-vsctl del-br br1
ovs-vsctl add-br br1ovs-vsctl add-port br1 eth1
ifconfig eth1 0 up
ifconfig br1 203.0.113.103 up

测试连通性

在 203.0.113.101 上 ping 203.0.113.103
在 203.0.113.103 上 ping 203.0.113.101

同网段 Self-service networks

2 个虚拟机各建立一个bridge,就相当于各自接入一个交换机
如果这 2 个交换机被分配到不同网段,就无法直接互相访问彼此
在 OpenStack 里面,相当于给所有节点提供一个私有网络 (Self-service networks)

必须通过某些技术配置后才可以访问:这里是 VxLAN 隧道

  1. 在 203.0.113.101 上创建 br0

     ovs-vsctl del-br br0ovs-vsctl add-br br0ifconfig br0 1.2.3.101/24 upovs-vsctl add-port br0 vx1 -- set interface vx1 type=vxlan options:remote_ip=203.0.113.101
    
  2. 检查一下 br0
    root@ubuntu2004-101:/home/dhbm# ovs-vsctl show

     57af7789-d775-440a-a204-e663b3c75b3eBridge br0Port vx1Interface vx1type: vxlanoptions: {remote_ip="203.0.113.101"}Port br0Interface br0type: internalBridge br1Port eth1Interface eth1Port br1Interface br1type: internalBridge br-intfail_mode: securePort br-intInterface br-inttype: internalovs_version: "2.13.8"
    
  3. 检查路由
    ip route list

     确认存在: default via 203.0.113.1 dev br1
    
  4. 在 203.0.113.103 上上创建 br0

     ovs-vsctl del-br br0ovs-vsctl add-br br0ifconfig br0 1.2.3.103/24 upovs-vsctl add-port br0 vx1 -- set interface vx1 type=vxlan options:remote_ip=203.0.113.103
    
  5. 检查一下 br0
    root@ubuntu2004-103:/home/dhbm# ovs-vsctl show

     a762a8e4-e153-4895-b87a-c7f7bc3ce3c3Bridge br0Port vx1Interface vx1type: vxlanoptions: {remote_ip="203.0.113.103"}Port br0Interface br0type: internalBridge br1Port br1Interface br1type: internalPort eth1Interface eth1Bridge br-intfail_mode: securePort br-intInterface br-inttype: internalovs_version: "2.13.8"
    
  6. 检查路由
    ip route list

     确认存在: default via 203.0.113.1 dev br1
    
  7. 连通性测试

    在 203.0.113.101 上 (Self-service networks : 1.2.3.101)
    ping 1.2.3.103

    在 203.0.113.103 上 (Self-service networks : 1.2.3.103)
    ping 1.2.3.101

不同网段 Self-service networks

步骤 1.2 (在 203.0.113.101 上)可以跳过,直接沿用上一部分的配置

  1. 在 203.0.113.101 上创建 br0

     ovs-vsctl del-br br0ovs-vsctl add-br br0ifconfig br0 1.2.3.101/24 upovs-vsctl add-port br0 vx1 -- set interface vx1 type=vxlan options:remote_ip=203.0.113.101
    
  2. 检查一下 br0
    ovs-vsctl show

     57af7789-d775-440a-a204-e663b3c75b3eBridge br0Port vx1Interface vx1type: vxlanoptions: {remote_ip="203.0.113.101"}Port br0Interface br0type: internalBridge br1Port eth1Interface eth1Port br1Interface br1type: internalBridge br-intfail_mode: securePort br-intInterface br-inttype: internalovs_version: "2.13.8"
    
  3. 在 203.0.113.103 上 上创建 br0

     ovs-vsctl del-br br0ovs-vsctl add-br br0ifconfig br0 5.6.7.103/24 upovs-vsctl add-port br0 vx1 -- set interface vx1 type=vxlan options:remote_ip=203.0.113.103
    
  4. 检查一下 br0
    ovs-vsctl show

     a762a8e4-e153-4895-b87a-c7f7bc3ce3c3Bridge br0Port vx1Interface vx1type: vxlanoptions: {remote_ip="203.0.113.103"}Port br0Interface br0type: internalBridge br1Port br1Interface br1type: internalPort eth1Interface eth1Bridge br-intfail_mode: securePort br-intInterface br-inttype: internalovs_version: "2.13.8"
    
  5. 连通性测试

    在 203.0.113.101 上 (Self-service networks : 1.2.3.101)
    ping 5.6.7.103
    不通
    在 203.0.113.103 上 (Self-service networks : 5.6.7.103)
    ping 1.2.3.101
    不通

  6. 在 203.0.113.101 上 增加路由

     route add -net 5.6.7.0 netmask 255.255.255.0 gw 1.2.3.101 dev br0
    
  7. 检查路由
    route -n

     Kernel IP routing tableDestination     Gateway         Genmask         Flags Metric Ref    Use Iface0.0.0.0         203.0.113.1     0.0.0.0         UG    0      0        0 br10.0.0.0         192.168.0.81    0.0.0.0         UG    0      0        0 eth01.2.3.0         0.0.0.0         255.255.255.0   U     0      0        0 br05.6.7.0         1.2.3.101       255.255.255.0   UG    0      0        0 br05.6.7.0         1.2.3.1         255.255.255.0   UG    0      0        0 br0192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0203.0.113.0     0.0.0.0         255.255.255.0   U     0      0        0 br1
    
  8. 在 203.0.113.103 上创建 br0

    route add -net 1.2.3.0 netmask 255.255.255.0 gw 5.6.7.103 dev br0

  9. 检查路由
    route -n

     Kernel IP routing tableDestination     Gateway         Genmask         Flags Metric Ref    Use Iface0.0.0.0         203.0.113.1     0.0.0.0         UG    0      0        0 br10.0.0.0         192.168.0.81    0.0.0.0         UG    0      0        0 eth01.2.3.0         5.6.7.103       255.255.255.0   UG    0      0        0 br01.2.3.0         5.6.7.1         255.255.255.0   UG    0      0        0 br05.6.7.0         0.0.0.0         255.255.255.0   U     0      0        0 br0192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0203.0.113.0     0.0.0.0         255.255.255.0   U     0      0        0 br1
    
  10. 再次连通性测试

    在 203.0.113.101 上 (Self-service networks : 1.2.3.101)
    ping 5.6.7.103

    OK

    在 203.0.113.103 上 (Self-service networks : 5.6.7.103)
    ping 1.2.3.101
    OK

相关内容

热门资讯

预付款“打了水漂”?孝义市法院... 在商场办了预付卡,再去消费时却发现店铺已人去楼空,查询后更发现商家已注销登记。卡里的余额该找谁要?是...
祥源文旅:实际控制人俞发祥因涉... 每经AI快讯,12月22日,祥源文旅(600576.SH)公告称,公司实际控制人俞发祥因涉嫌犯罪被绍...
【重磅速递 | 邀请函】《增值... 2025年12月19日,国务院召开常务会议,审议通过《中华人民共和国增值税法实施条例(草案)》,指出...
山东探索建立国有企业总审计师制... 齐鲁晚报·齐鲁壹点记者 杨璐 12月22日,山东省人民政府新闻办公室举行新闻发布会,介绍“十四五”时...
交建股份最新公告:实际控制人俞... 交建股份(603815.SH)公告称,公司实际控制人俞发祥因涉嫌犯罪被绍兴市公安局采取刑事强制措施,...
行政调解丨用药过量致七十亩豆苗... 齐鲁晚报·齐鲁壹点记者 李文璇 栾海明 一通通求助电话接连涌入市民热线,指向同一片受灾的豆田。20...
涉嫌犯罪,交建股份实控人俞发祥... 北京商报讯(记者 马换换 王蔓蕾)12月22日晚间,交建股份(603815)披露公告称,公司于当日收...
中化岩土起诉甘肃地质勘察院 追... 12月22日,中化岩土(002542)发布公告,近日公司与甘肃水文地质工程地质勘察院有限责任公司之间...
人民调解丨树木承包起纷争,三步... 齐鲁晚报·齐鲁壹点记者 鹿青松 “都是一个村的老邻居,咋就为了几棵树闹到脸红脖子粗?”在乡村治理中,...