openstack-基于智能网卡的热迁移实现

最近在调研智能网卡,对于使用智能网卡的环境下,如何实现虚拟机的热迁移呢,这里分享一下。

热迁移的过程分以下几步完成:

发起热迁移后,在目的物理机上会启动一个VM,命令参数等同于源物理机上正在运行的VM的启动参数。
标记RAM中所有需要迁移的page为dirty。
发送标记为dirty的page到目的机的VM中,重复多次,直到dirty的page数量减少到某个临界值,或者是达到其他可以触发本阶段结束的条件。
停止源物理机上VM中Guest的运行,并将剩余dirty pages和设备状态发送到目的物理机上的VM中。
目的物理机上VM中Guest开始运行,源物理机上的VM退出。

openstack-基于packer自动化build镜像

Packer是一个从单一的模板文件来创建多平台一致性镜像的轻量级开源工具,它能够运行在常用的主流操作系统如Windows、Linux和Mac os上,能够高效的并行创建多平台例如AWS、Azure和Alicloud/OpenStack 的镜像,它的目的并不是取代Puppet/Chef等配置管理工具,实际上,当制作镜像的时候,Packer可以使用Chef或者Puppet,ansible 等工具来安装镜像所需要的软件。通过Packer自动化的创建各种平台的镜像是非常容易的。

安装packer

1
2
3
4
#wget https://releases.hashicorp.com/packer/1.7.10/packer_1.7.10_linux_amd64.zip
#unzip packer_1.7.10_linux_amd64.zip
#mv packer /usr/local/bin/
#/usr/local/bin/packer --help

定义packer模板

1
2
#touch openstack.json
#vim openstack.json

Read More

openstack-兼容海光hygon服务器

背景:

海光处理器采用了与AMD EPYC 类似的体系结构,为了便于 QEMU 虚拟化处理器提供更好的兼容模式,需要对 QEMU-KVM进行CPU Vendor ID进行替换,进而支持 QEMU 虚拟机虚拟化 ;

QEMU在使用KVM虚拟化的时候只支持使用主机的CPU Vendor ID,目前海光处理器还不在此KVM虚拟化版本支持列表中,如果不配置就直接使用 QEMU/KVM,那么虚拟出来的虚拟机也为海光的 CPU VendorID,这将会导致某些OS虚拟机无法正常启动(例如Windows);

Libvirt调用QEMU创建虚拟机进程,在配置Libvirt XML文件的时候需要指定CPU Model和VendorID,把这些参数传递给QEMU,虚拟机才能正常启动。

Openstack NOVA组件调用Libvirt接口控制虚拟机的生命周期,创建虚拟机的时候生成XML文件,原版的Openstack不会传递CPU的VendorID,需要做一些修改,传递相关的CPU参数才能生成正确的XML文件。

解决

1
2
3
4
5
6
7
主要修改如下文件
nova/objects/image_meta.py
nova/objects/virt_cpu_topology.py
nova/virt/hardware.py
nova/virt/libvirt/config.py
nova/virt/libvirt/driver.py
具体可以参考 https://hlyani.github.io/notes/openstack/openstack_hygon_patch.html

虚拟化-OVS-DPDK在CentOS7上的部署调试

OVS-DPDK部署

基于CentOS 7.9 x86_64 物理机,网卡 mlx cx5
初始化系统环境

1
2
3
4
5
6
7
8
9
10
11
yum makecache
yum -y update
yum install -y epel-release
yum install -y net-tools tcpdump telnet wget zip unzip vim
yum install -y gcc gcc-c++ kernel-devel kernel-headers kernel.x86_64 net-tools
yum install -y numactl-devel.x86_64 numactl-libs.x86_64
yum install -y libpcap.x86_64 libpcap-devel.x86_64 libcap-ng-devel
yum install -y pciutils
yum install -y autoconf automake libtool

#reboot (内核有可能升级最好重启一下)

安装麦乐思OFED驱动(非mlx步骤请忽略)

1
2
3
4
yum install tcl tk
/mnt/mlnxofedinstall --dpdk --upstream-libs
cat /proc/cpuinfo | grep pdpe1gb
reboot

源码安装DPDK

1
2
3
4
5
6
wget http://fast.dpdk.org/rel/dpdk-19.11.7.tar.xz
tar -xvf dpdk-19.11.7.tar.xz
cd dpdk-stable-19.11.7/
mkdir -p /usr/src/dpdk
make config T=x86_64-native-linuxapp-gcc

1
2
3
修改支持MLX CX4/CX5
sed -i 's/\(CONFIG_RTE_LIBRTE_MLX5_PMD=\)n/\1y/g' config/common_base
sed -i 's/\(CONFIG_RTE_LIBRTE_MLX5_DLOPEN_DEPS=\)n/\1y/g' config/common_base
1
2
make install T=x86_64-native-linuxapp-gcc DESTDIR=/usr/src/dpdk
make install T=x86_64-native-linuxapp-gcc DESTDIR=/usr
1
2
拷贝共享库到/usr/lib64下
~~cp x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5_glue* /usr/lib64/~~

源码安装ovs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
wget https://www.openvswitch.org/releases/openvswitch-2.13.1.tar.gz
yum -y install python3 python3-devel python36-six
# 解压编译
tar -zxvf openvswitch-2.13.1.tar.gz
cd openvswitch-2.13.1/
./boot.sh
./configure \
--with-dpdk=/usr/src/dpdk \
--prefix=/usr \
--exec-prefix=/usr \
--sysconfdir=/etc \
--localstatedir=/var
make
make install

网卡绑定

  1. 系统设置
    系统BIOS需要打开VT-d,并且通过grub配置iommu和intel_iommu参数来支持VFIO驱动,修改/boot/grub2/grub.cfg,找到引导的相应内核参数,在后面添加:
    iommu=pt intel_iommu=on,例如,
    1
    linux16 /vmlinuz-3.10.0-327.36.2.el7.x86_64 root=/dev/mapper/centos_dell-root ro crashkernel=auto rd.lvm.lv=centos_dell/root rd.lvm.lv=centos_dell/swap nomodeset rhgb quiet
    可在系统启动后使用如下命令查看:
    1
    cat /proc/cmdline
  2. 设置dpdk驱动
    1
    modprobe vfio-pci
  3. 网卡绑定到dpdk
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    ifdown ens33
    dpdk-devbind --bind=vfio-pci ens33


    Network devices using DPDK-compatible driver
    ============================================
    0000:02:01.0 '82545EM Gigabit Ethernet Controller (Copper) 100f' drv=vfio-pci unused=e1000

    Network devices using kernel driver
    ===================================
    0000:02:02.0 '82545EM Gigabit Ethernet Controller (Copper) 100f' if=ens34 drv=e1000 unused=vfio-pci *Active*
    0000:02:03.0 '82545EM Gigabit Ethernet Controller (Copper) 100f' if=ens35 drv=e1000 unused=vfio-pci

    No 'Baseband' devices detected
    ==============================

    No 'Crypto' devices detected
    ============================

    No 'Eventdev' devices detected
    ==============================

    No 'Mempool' devices detected
    =============================

    No 'Compress' devices detected
    ==============================

    No 'Misc (rawdev)' devices detected
    ===================================

    配置大页内存

  4. 查看大页内存配置
    1
    grep HugePages_ /proc/meminfo
  5. 修改hugepage的页数为1024
    1
    2
    echo 1024 > /proc/sys/vm/nr_hugepages
    echo 'vm.nr_hugepages=2048' > /etc/sysctl.d/hugepages.conf
    1
    mount -t hugetlbfs  none /dev/hugepages
  6. 配置开机启动
    1
    2
    3
    chmod 755 /etc/rc.d/rc.local
    echo '/usr/sbin/modprobe vfio-pci' >> /etc/rc.d/rc.local
    echo 'mount -t hugetlbfs none /dev/hugepages' >> /etc/rc.d/rc.local

    启动ovs-db-server

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    mkdir -p /etc/openvswitch
    mkdir -p /var/run/openvswitch
    mkdir -p /var/log/openvswitch
    #ovsdb-tool create /etc/openvswitch/conf.db /usr/share/openvswitch/vswitch.ovsschema
    # ovsdb-server --remote=punix:/var/run/openvswitch/db.sock --remote=db:Open_vSwitch,Open_vSwitch,manager_options --pidfile --detach --monitor

    # 增加 dpdk 相关配置参数
    # ovs-vsctl --no-wait set Open_vSwitch . other_config:dpdk-init=true
    # ovs-vsctl --no-wait set Open_vSwitch . other_config:vhost-iommu-support=true (vhostuser支持 vhostuserclient )
    # ovs-vsctl --no-wait set Open_vSwitch . other_config:dpdk-socket-mem="1024,1024"
    #ovs-vsctl --no-wait set Open_vSwitch . other_config:pmd-cpu-mask=0xe

    启动 ovs-vswitchd

    1
    2
    3
    4
    export DB_SOCK=/var/run/openvswitch/db.sock
    /usr/share/openvswitch/scripts/ovs-ctl --no-ovsdb-server --db-sock="$DB_SOCK" start
    ps axu|grep ovs
    ovs-vsctl list open_vswitch 查看dpdk是否被初始化

    创建ovs网桥和端口

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    # ovs-vsctl add-br br-int -- set bridge br-int datapath_type=netdev    # 使用 ovs-dpdk 必须指定datapath_type类型为netdev
    # ovs-vsctl add-br br1 -- set bridge br1 datapath_type=netdev
    # ovs-vsctl add-port br-int dpdkvhostuserclient0 -- set Interface dpdkvhostuserclient0 type=dpdkvhostuserclient options:vhost-server-path=/tmp/vhostuserclient0.sock
    # ovs-vsctl add-port br1 dpdkvhostuserclient1 -- set Interface dpdkvhostuserclient1 type=dpdkvhostuserclient options:vhost-server-path=/tmp/vhostuserclient1.sock
    # ovs-vsctl add-port br0 dpdk0 -- set interface dpdk0 type=dpdk options:dpdk-devargs=0000:02:01.0
    # ovs-vsctl add-port br1 dpdk1 -- set interface dpdk1 type=dpdk options:dpdk-devargs=0000:02:01.0
    # ovs-vsctl set Interface dpdkvhostuserclient0 options:n_rxq=2
    # ovs-vsctl set Interface dpdkvhostuserclient1 options:n_rxq=2
    # vs-vsctl set Interface dpdk0 options:n_rxq=2
    # vs-vsctl set Interface dpdk1 options:n_rxq=2


    ovs-vsctl add-port br0 dpdk0 -- set Interface dpdk0 type=dpdk options:dpdk-devargs=0000:07:00.0,n_rxq_desc=1024,n_txq_desc=1024,n_rxq=1,pmd-rxq-affinity="0:1" ofport_request=1


    server201配置

    1
    2
    3
    4
    5
    ovs-vsctl add-br br-tun -- set bridge br-tun datapath_type=netdev
    ovs-vsctl add-port br-tun vxlan-1 -- set interface vxlan-1 type=vxlan ofport_request=100 options:remote_ip=192.168.100.202
    ovs-vsctl add-br br-int -- set bridge br-int datapath_type=netdev
    ovs-vsctl add-port br-int dpdkvhostuserclient0 -- set Interface dpdkvhostuserclient0 type=dpdkvhostuserclient options:vhost-server-path=/tmp/vhostuserclient0.sock
    ovs-vsctl set Interface dpdkvhostuserclient0 options:n_rxq=2

    server202配置

    1
    2
    3
    4
    5
    ovs-vsctl add-br br-tun -- set bridge br-tun datapath_type=netdev
    ovs-vsctl add-port br-tun vxlan-1 -- set interface vxlan-1 type=vxlan ofport_request=100 options:remote_ip=192.168.100.201
    ovs-vsctl add-br br-int -- set bridge br-int datapath_type=netdev
    ovs-vsctl add-port br-int dpdkvhostuserclient0 -- set Interface dpdkvhostuserclient0 type=dpdkvhostuserclient options:vhost-server-path=/tmp/vhostuserclient0.sock
    ovs-vsctl set Interface dpdkvhostuserclient0 options:n_rxq=2

troubleshooting

1
2
3
4
#dpdk-devbind --bind=vfio-pci ens34 报错
Warning: routing table indicates that interface 0000:02:01.0 is active. Not modifying
解决:
#ifdown ens33

虚拟机测试

1
qemu-system-x86_64 -enable-kvm -m 1024 -smp 2-chardev socket,id=char0,path=/var/run/openvswitch/vhost-user-1-netdev type=vhost-user,id=mynet1,chardev=char0,vhostforce -devicevirtio-net-pci,netdev=mynet1,mac=52:54:00:02:d9:05 -objectmemory-backend-file,id=mem,size=1024M,mem-path=/dev/hugepages,share=on -numanode,memdev=mem -mem-prealloc -net user, -net nic /home/CentOS7.qcow2 -vn c0.0.0.0:30

参考:

https://docs.nvidia.com/networking/pages/releaseview.action?pageId=15053908

虚拟化-ovn入门到精通(五)

OVN-L3 网关连接外部网络

1. 网关联通

参考网上,TOPO是这么个意思~

正如上面所看到的,我们添加了以下新组件:

  • OVN边界网关路由器(edge1)
  • 逻辑交换机(transit),用于连接edge1和tenant1路由器
  • 逻辑交换机(outside),用于将edge1连接到实验室网络

我们要做的是让VPC内的虚拟机能联通underlay物理网络,打通三层, NAT出去~

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

| enp6s0f1 | Physical Network
----------
|
____|_____
| bridge | br-ex
----------
| mapping
outside(sw)
|
| <192.168.0.250/24>
edge1(gr) <10.10.100.1/24>
|
|
transit(join sw)
|
| <10.10.100.2/24>
router-tenant1(dr) <172.16.250.1/24,172.16.251.1/24>
/ \
ls01(sw) ls02(sw)
/ | / \
vm1 vm2 vm11 vm12

创建逻辑边界路由器,gateway router位于一个特定的chassis中。为了完成绑定,我们需要确定 central节点的chassis id(我理解这里是VTEP网关的意思,需要固定到哪一台上,相当于是集中式的网络节点吧,这里依旧使用central节点作为集中式网关)

1
#ovn-sbctl show

1
#ovn-nbctl create Logical_Router name=edge1 options:classis=5e959521-218c-4dd3-bf25-ef29a522234b

创建逻辑中转交换机用于连接edge1和tenant1 , 作用: 连接两个路由器,因为网关路由器仅可以经由逻辑交换机连接到其他路由器, 没准将来这块社区能够优化掉~

1
#ovn-nbctl ls-add transit

联通路由器edge1和逻辑交换机transit上

1
2
3
4
5
#ovn-nbctl lrp-add edge1 edge1-transit 02:d4:1d:8c:d7:ae 10.10.100.1/24
#ovn-nbctl lsp-add transit transit-edge1
#ovn-nbctl lsp-set-type transit-edge1 router
#ovn-nbctl lsp-set-addresses transit-edge1 02:d4:1d:8c:d7:ae
#ovn-nbctl lsp-set-options transit-edge1 router-port=edge1-transit

联通路由器tenant1到逻辑交换机transit上

1
2
3
4
5
#ovn-nbctl lrp-add router-tenant1 tenant1-transit 02:d4:1d:8c:d9:af 10.10.100.2/24
#ovn-nbctl lsp-add transit transit-tenant1
#ovn-nbctl lsp-set-type transit-tenant1 router
#ovn-nbctl lsp-set-addresses transit-tenant1 02:d4:1d:8c:d9:af
#ovn-nbctl lsp-set-options transit-tenant1 router-port=tenant1-transit

添加静态路由

1
2
3
4
5
#ovn-nbctl lr-route-add edge1 "172.16.250.0/24" 10.10.100.2
#ovn-nbctl lr-route-add edge1 "172.16.251.0/24" 10.10.100.2
#ovn-nbctl lr-route-add router-tenant1 "0.0.0.0/0" 10.10.100.1
#ovn-nbctl lr-route-list edge1
#ovn-nbctl lr-route-list router-tenant1

测试连通性

1
2
#ip netns exec ns1 ping -c 2 10.10.100.1
#ip netns exec ns11 ping -c 2 10.10.100.1

至此, vm 到edge1路由器的网络已经联通~

2. SNAT联通物理underlay网络

我们接下去将使用central节点的ens35作为edge1 router和”data” network的连接点。为了完成这个任务,我们需要设置OVN使其通过一个专用的OVS bridge来使用ens35。这种类型的连接在OVN中被称为”localnet”。

2.1 central节点
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#在路由器 'edge1'创建新的端口,用于连接outside交换机
ovn-nbctl lrp-add edge1 edge1-outside 02:0a:7f:00:01:29 192.168.0.250/24
# set gateway chassis
ovn-nbctl lrp-set-gateway-chassis edge1-outside 5e959521-218c-4dd3-bf25-ef29a522234b
# 新建逻辑交换机,并将它连接到edge1
ovn-nbctl ls-add outside
ovn-nbctl lsp-add outside outside-edge1
ovn-nbctl lsp-set-type outside-edge1 router
ovn-nbctl lsp-set-addresses outside-edge1 02:0a:7f:00:01:29
ovn-nbctl lsp-set-options outside-edge1 nat-addresses=router router-port=edge1-outside

#在 'outside'交换机创建localnet端口。把网络名称设置为"physnet1"
ovn-nbctl lsp-add outside outside-localnet
ovn-nbctl lsp-set-addresses outside-localnet unknown
ovn-nbctl lsp-set-type outside-localnet localnet
ovn-nbctl lsp-set-options outside-localnet network_name=physnet1

依旧使用
# 为 eth1新建OVS网桥
ovs-vsctl add-br br-ex
# 为 eth1创建网桥映射: 把 "physnet1" 映射到 br-ex
ovs-vsctl add-port br-ex eth0
ovs-vsctl set Open_vSwitch . external-ids:ovn-bridge-mappings=physnet1:br-ex

#给 br-ex配置ip地址 192.168.0.201/24
ip addr add 192.168.0.201/24 dev br-ex
ip link set br-ex up

测试联通

虚机可以联通 192.168.0.250, 无法联通 192.168.0.201-203

1
2
3
4
5
6
7
8
9
10
11
12
[root@q15439v ~]# ip netns exec ns1 ping 192.168.0.250
PING 192.168.0.250 (192.168.0.250) 56(84) bytes of data.
64 bytes from 192.168.0.250: icmp_seq=1 ttl=253 time=0.260 ms
^C
--- 192.168.0.250 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.260/0.260/0.260/0.000 ms
[root@q15439v ~]# ip netns exec ns1 ping 192.168.0.201
PING 192.168.0.201 (192.168.0.201) 56(84) bytes of data.
^C
--- 192.168.0.201 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms


1
2
3
# create snat rule which will nat to the edge1-outside interface
ovn-nbctl -- --id=@nat create nat type="snat" logical_ip=172.16.250.0/24 external_ip=192.168.0.250 -- add logical_router edge1 nat @nat
#ovn-nbctl -- --id=@nat create nat type="dnat_and_snat" logical_ip=172.16.250.11 external_ip=192.168.0.199 -- add logical_router edge1 nat @nat

1
2
3
4
5
6
7
8
9
清理nat
ovn-nbctl lr-nat-del edge1 dnat_and_snat 192.168.0.199
ovn-nbctl lr-nat-del edge1 snat 172.16.250.0/24
ovn-nbctl ls-del outside
ovn-nbctl lrp-del edge1-outside

#
ovs-vsctl del-br br-ex

TRACE排查

1
2
ovn-trace --detail 交换机id inport = 虚机port, eth.src= 虚机mac,eth.dst=网关mac
ovn-trace --detail 0cd46441-6af4-45db-b201-16cd8342c519 'inport == "e69f6f79-7e62-4616-b1b8-be61cf9eac79" && eth.src == fa:16:3e:e9:52:50 && ip4.src == 192.168.99.131 && eth.dst == fa:16:3e:ee:d9:3e && ip4.dst == 8.8.8.8 && ip.ttl == 32'

虚拟化-ovn入门到精通(五)-1

OVN-L3 网关连接外部网络

1. 网关联通

参考网上,TOPO是这么个意思~

正如上面所看到的,我们添加了以下新组件:

  • 逻辑交换机(outside),用于将edge1连接到实验室网络

我们要做的是让VPC内的虚拟机能联通underlay物理网络,打通三层, NAT出去~

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

| eth1 | Physical Network
----------
|
____|_____
| bridge | br-ex 192.168.0.100
----------
| mapping
outside(sw)
| port: tenant1-outside <192.168.0.101/24>
router-tenant1(dr) port: tenant1-localnet <172.16.250.1/24,172.16.251.1/24>
/ \
ls01(sw) ls02(sw)
/ | / \
vm1 vm2 vm11 vm12

创建逻辑边界路由器,gateway router位于一个特定的chassis中。为了完成绑定,我们需要确定 central节点的chassis id(我理解这里是VTEP网关的意思,需要固定到哪一台上,相当于是集中式的网络节点吧)

1
#ovn-sbctl show

1
#ovn-nbctl create Logical_Router name=edge1 options:classis=32209610-88c9-495e-ab88-134923afea59

创建outside交换机用于连接外网和tenant1 , 作用: 连接两个路由器,因为网关路由器仅可以经由逻辑交换机连接到其他路由器

  1. 联通路由器tenant1到逻辑交换机outside上
1
2
#ovn-sbctl show

1
2
3
4
5
6
7
8
9
10
11
12
13

# create new port on router 'tenant1'
ovn-nbctl lrp-add router-tenant1 tenant1-outside 02:0a:7f:18:01:02 192.168.0.101/24
# set gateway chassis(通过ovn-sbctl show 选取central节点作为vtep网关节点)
ovn-nbctl lrp-set-gateway-chassis tenant1-outside fda80787-897d-40af-811c-2c9f7caedb3b

# create new logical switch and connect it to 'router0'
ovn-nbctl ls-add outside
ovn-nbctl lsp-add outside outside-tenant1
ovn-nbctl lsp-set-type outside-tenant1 router
ovn-nbctl lsp-set-addresses outside-tenant1 02:0a:7f:18:01:02
ovn-nbctl lsp-set-options outside-tenant1 router-port=tenant1-outside
# ovn-nbctl lsp-set-options outside-tenant1 nat-addresses=router router-port=tenant1-outside
  1. 创建ovs网桥br-ex,并关联逻辑交换机outside
1
2
3
4
5
# create localnet port on 'outside'. set the network name to "phynet"
ovn-nbctl lsp-add outside outside-localnet
ovn-nbctl lsp-set-addresses outside-localnet unknown
ovn-nbctl lsp-set-type outside-localnet localnet
ovn-nbctl lsp-set-options outside-localnet network_name=phynet1
  1. 在central节点上创建ovs网桥br-ex,然后将eth1挂到ovs网桥上
    1
    2
    3
    4
    5
    6
    # create a bridge , then mapping outside port
    ovs-vsctl add-br br-ex
    ovs-vsctl set Open_vSwitch . external-ids:ovn-bridge-mappings=phynet1:br-ex

    # add nic eth1
    ovs-vsctl add-port br-ex eth1
    给 central节点br-ex 配置ip测试联通
    1
    2
    #ifconfig br-ex 192.168.0.100/24
    #ip link set br-ex up
1
2
3
#ip netns exec ns1 ping -c 2 192.168.0.101
#ip netns exec ns1 ping -c 2 192.168.0.100
结果发现 虚机能联通 192.168.0.101,确不能联通192.168.0.100
  1. 通过snat实现访问外网。通过dnat_and_snat实现fip
    1
    2
    3
    4
    # snat 连外网
    ovn-nbctl -- --id=@nat create nat type="snat" logical_ip=172.16.250.0/24 external_ip=192.168.0.101 -- add logical_router router-tenant1 nat @nat
    # fip
    ovn-nbctl -- --id=@nat create nat type="dnat_and_snat" logical_ip=172.16.250.11 external_ip=192.168.0.102 -- add logical_router router-tenant1 nat @nat

虚拟化-ovn入门到精通(四)

OVN-L3 路由

前面我们已经将ovn二层网络打通,下面测试一下三层网关路由功能。

拓扑图如下

central

创建租户路由器

1
#ovn-nbctl lr-add router-tenant1

联通路由器router-tenant1到logicswitch_01

1
2
3
4
5
6
7
8
9
10
给路由器新增连接logicswitch_01的端口 router-ls01,对应的路由器端口IP地址是 172.16.250.1
#ovn-nbctl lrp-add router-tenant1 router-ls01 02:d4:1d:8b:d9:8a 172.16.250.1/24
给交换机logicswitch_01新增连接路由器 router_tenant1的端口 logicswitch_01-router
#ovn-nbctl lsp-add logicswitch_01 logicswitch_01-router
设置 端口logicswitch_01-router 类型是路由器
#ovn-nbctl lsp-set-type logicswitch_01-router router
设置 端口logicswitch_01-router 的mac是02:d5:1d:8b:d9:8a
#ovn-nbctl lsp-set-addresses logicswitch_01-router 02:d4:1d:8b:d9:8a

#ovn-nbctl lsp-set-options logicswitch_01-router router-port=router-ls01

联通路由器router-tenant1到logicswitch_02

1
2
3
4
5
6
7
8
9
10
给路由器新增连接logicswitch_01的端口 router-ls02,对应的路由器端口IP地址是 172.16.251.1
#ovn-nbctl lrp-add router-tenant1 router-ls02 02:d4:1d:8a:d9:8b 172.16.251.1/24
给交换机logicswitch_02新增连接路由器 router_tenant1的端口 logicswitch_02-router
#ovn-nbctl lsp-add logicswitch_02 logicswitch_02-router
设置 端口logicswitch_02-router 类型是路由器
#ovn-nbctl lsp-set-type logicswitch_02-router router
设置 端口logicswitch_02-router 的mac是02:d3:1d:8a:d9:8b
#ovn-nbctl lsp-set-addresses logicswitch_02-router 02:d4:1d:8a:d9:8b

#ovn-nbctl lsp-set-options logicswitch_02-router router-port=router-ls02

VPC 之间的路由已经联通~

接下来测试打通172.16.250.0/24 和 172.16.251.0/24

node

1
2
3
4
5
#ip netns exec ns1 route add default gw 172.16.250.1
#ip netns exec ns11 route add default gw 172.16.251.1

#ip netns exec ns2 route add default gw 172.16.250.1
#ip netns exec ns12 route add default gw 172.16.251.1

至此,已通过逻辑路由器,打通两个逻辑交换机下的两个VPC网络~

虚拟化-ovn入门到精通(三)

OVN-L2测试

前面我们已经将ovn集群部署完成,下面测试一下二层网络的联通性

定义逻辑网络:创建一个逻辑交换机,然后添加两个交换机端口,并为端口设置IP地址,测试二层联通性

1
2
3
4
5
6
7
8
9
#export vm1_mac=02:d4:1d:8c:d9:8f
#export vm2_mac=02:d4:1d:8c:d9:8e
#export vm1_ip=172.16.250.11
#export vm2_ip=172.16.250.12
------------------------------------------------------
#export vm11_mac=02:d4:1d:8c:d8:8f
#export vm12_mac=02:d4:1d:8c:d8:8e
#export vm11_ip=172.16.251.11
#export vm12_ip=172.16.251.12

central节点

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
交换机 01
#ovn-nbctl ls-add logicswitch_01
#ovn-nbctl lsp-add logicswitch_01 ls1-vm1
#ovn-nbctl lsp-set-addresses ls1-vm1 $vm1_mac
#ovn-nbctl lsp-set-port-security ls1-vm1 $vm1_mac
#ovn-nbctl lsp-add logicswitch_01 ls1-vm2
#ovn-nbctl lsp-set-addresses ls1-vm2 $vm2_mac
#ovn-nbctl lsp-set-port-security ls1-vm2 $vm2_mac
---------------------------------------------------------------------------------------
交换机 02
#ovn-nbctl ls-add logicswitch_02
#ovn-nbctl lsp-add logicswitch_02 ls2-vm11
#ovn-nbctl lsp-set-addresses ls2-vm11 $vm11_mac
#ovn-nbctl lsp-set-port-security ls2-vm11 $vm11_mac
#ovn-nbctl lsp-add logicswitch_02 ls2-vm12
#ovn-nbctl lsp-set-addresses ls2-vm12 $vm12_mac
#ovn-nbctl lsp-set-port-security ls2-vm12 $vm12_mac

伪造虚拟机: 通过创建网络命名空间,并在br-int上添加端口,然后将端口添加到命名空间,最后通过设置端口的MAC地址和网卡名完成和交换机端口的映射

node1节点(vm1)
1
2
3
4
5
6
7
8
9
交换机01
#ip netns add ns1
#ovs-vsctl add-port br-int vm1 -- set interface vm1 type=internal
#ip link set vm1 netns ns1
#ip netns exec ns1 ip link set vm1 address $vm1_mac
#ip netns exec ns1 ip addr add $vm1_ip/24 dev vm1
#ip netns exec ns1 ip link set vm1 up
#ovs-vsctl set Interface vm1 external_ids:iface-id=ls1-vm1
#ip netns exec ns1 ip addr show
1
2
3
4
5
6
7
8
9
交换机02
#ip netns add ns11
#ovs-vsctl add-port br-int vm11 -- set interface vm11 type=internal
#ip link set vm11 netns ns11
#ip netns exec ns11 ip link set vm11 address $vm11_mac
#ip netns exec ns11 ip addr add $vm11_ip/24 dev vm11
#ip netns exec ns11 ip link set vm11 up
#ovs-vsctl set Interface vm11 external_ids:iface-id=ls2-vm11
#ip netns exec ns11 ip addr show

node2节点(vm2)
1
2
3
4
5
6
7
8
9
交换机01
#ip netns add ns2
#ovs-vsctl add-port br-int vm2 -- set interface vm2 type=internal
#ip link set vm2 netns ns2
#ip netns exec ns2 ip link set vm2 address $vm2_mac
#ip netns exec ns2 ip addr add $vm2_ip/24 dev vm2
#ip netns exec ns2 ip link set vm2 up
#ovs-vsctl set Interface vm2 external_ids:iface-id=ls1-vm2
#ip netns exec ns2 ip addr show
1
2
3
4
5
6
7
8
9
交换机02
#ip netns add ns12
#ovs-vsctl add-port br-int vm12 -- set interface vm12 type=internal
#ip link set vm12 netns ns12
#ip netns exec ns12 ip link set vm12 address $vm12_mac
#ip netns exec ns12 ip addr add $vm12_ip/24 dev vm12
#ip netns exec ns12 ip link set vm12 up
#ovs-vsctl set Interface vm12 external_ids:iface-id=ls2-vm12
#ip netns exec ns12 ip addr show

交换机01喝交换机02下的二层网络已经连通 ~

虚拟化-ovn入门到精通(二)

OVN安装部署

基于CentOS 7 x86_64

主机 角色 网卡 备注
10.175.160.66 Central eth0/eth1 目前仅支持单节点
10.175.160.59 Node1 eth0/eth1 vm1/vm11
10.175.160.60 Node2 eth0/eth1 vm2/vm12

一、 系统初始化

1
2
3
4
5
6
7
8
9
10
11
12
配置repo源,ovn/ovs版本2.11.0
#vim /etc/yum.repos.d/stein.repo
[openstack-stein]
name=OpenStack Stein Repository
#baseurl=http://mirror.centos.org/centos/7/cloud/$basearch/openstack-stein/
mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=cloud-openstack-stein
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-Cloud
关闭防火墙/selinux
#systemctl stop firewalld
#systemctl disable firewalld

二、部署服务

Central 节点

# yum install -y openvswitch-ovn-central.x86_64 openvswitch-ovn-host.x86_64

#yum install libibverbs -y

# systemctl enable ovn-northd openvswitch ovn-controller

# systemctl start ovn-northd ovn-controller

Node节点

# yum install -y openvswitch.x86_64 openvswitch-ovn-host.x86_64

#yum install libibverbs -y

#systemctl enable openvswitch ovn-controller

#systemctl start ovn-controller

三、 配置OVN

配置ovs与ovn相连接

central节点
1
2
3
4
#export Centralip=10.175.160.66
#ovn-nbctl set-connection ptcp:6641:$Centralip
#ovn-sbctl set-connection ptcp:6642:$Centralip
#netstat -ntlp

1
2
3
4
#ovs-vsctl set open . external-ids:ovn-remote=tcp:$Centralip:6642
overlay网络使用geneve,当然支持geneve,vxlan,gre等
#ovs-vsctl set open . external-ids:ovn-encap-type=geneve
#ovs-vsctl set open . external-ids:ovn-encap-ip=$Centralip
node 1 节点
1
2
3
4
5
#export Centralip=10.175.160.66
#export NodeIP=10.175.160.59
#ovs-vsctl set open . external-ids:ovn-remote=tcp:$Centralip:6642
#ovs-vsctl set open . external-ids:ovn-encap-type=geneve
#ovs-vsctl set open . external-ids:ovn-encap-ip=$NodeIP
node2 节点
1
2
3
4
5
#export Centralip=10.175.160.66
#export NodeIP=10.175.160.60
#ovs-vsctl set open . external-ids:ovn-remote=tcp:$Centralip:6642
#ovs-vsctl set open . external-ids:ovn-encap-type=geneve
#ovs-vsctl set open . external-ids:ovn-encap-ip=$NodeIP

所有服务器重启一下

#reboot

至此安装完成~

排错

1
2
3
4
5
6
1. 
net_mlx5: cannot load glue library: libibverbs.so.1: cannot open shared object file: No such file or directory
net_mlx5: cannot initialize PMD due to missing run-time dependency on rdma-core libraries (libibverbs, libmlx5)
PMD: net_mlx4: cannot load glue library: libibverbs.so.1: cannot open shared object file: No such file or directory
PMD: net_mlx4: cannot initialize PMD due to missing run-time dependency on rdma-core libraries (libibverbs, libmlx4)
解决:#yum install libibverbs -y