• Ubuntu20.04 单节点 microstack 重设外网卡10.20.20.0/24


    官方安装文档

    Single node OpenStack on your workstation

    重要参考文章
    变通方式重设外网卡10.20.20.0/24

    我的环境

     虚拟机 2 CPU , 16 G RAM
     网卡 eth0: 192.168.0.121
     网卡 eth1: 不设 IP
     Ubuntu 20.04
    
    • 1
    • 2
    • 3
    • 4

    安装

    1. snap 安装

       sudo snap install microstack --beta
      
      • 1

      或者

       sudo snap install microstack --devmode --beta
      
      • 1

      可以 snap list 确认一下

    2. 初始化

       sudo microstack init --auto --control
      
      • 1

      这一步会完成这些服务:
      Glance (Image service),
      Horizon (Dashboard),
      Keystone (Security),
      Neutron (Network)
      Nova (Compute).

      暂时不要执行 3. Launch an instance
      执行也没有关系,后续操作会先删除

    3. 获取 dashboard 登录密码

       sudo snap get microstack config.credentials.keystone-password
      
      • 1

      得到 admin 登录密码
      sq2UB6aIXK28QJXBcz0azgnCFBy09Xa5

    4. 设置 CLI 命令别名
      openstack 命令:

       sudo snap alias microstack.openstack openstack
      
      • 1

      网络命令 ovs-vsctl:

       sudo snap alias microstack.ovs-vsctl ovs-vsctl
      
      • 1
    5. 获取外网物理设备名称(dashboard 设置 flat 外网时用)

       sudo ovs-vsctl get open . external_ids:ovn-bridge-mappings | awk -F: '{gsub("\"","");; print $1}'
      
      • 1

      一般都是 : physnet1

    重设 br-ex

    据说是 10.20.20.1 写死了,咱也找一下
    
    root@ubuntu2004-121:/snap# cat ./microstack/245/bin/set-default-config.py
    	
    	./microstack/245/bin/set-default-config.py:        'config.network.ext-gateway': '10.20.20.1',
    	./microstack/245/bin/set-default-config.py:        'config.network.control-ip': '10.20.20.1',
    	./microstack/245/bin/set-default-config.py:        'config.network.compute-ip': '10.20.20.1',
    	./microstack/245/bin/set-default-config.py:        'config.network.ext-cidr': '10.20.20.1/24',
    	./microstack/245/lib/python3.8/site-packages/init/main.py:            'Falling back on 10.20.20.1')
    	./microstack/245/lib/python3.8/site-packages/openstackclient/tests/unit/network/v2/test_subnet.py:                                 'nexthop': '10.20.20.1'},
    	./microstack/245/lib/python3.8/site-packages/openstackclient/tests/unit/network/v2/test_subnet.py:                              'nexthop': '10.20.20.1'}],
    	./microstack/245/lib/python3.8/site-packages/openstackclient/tests/unit/network/v2/test_subnet.py:                              'nexthop': '10.20.20.1'}],
    	./microstack/245/lib/python3.8/site-packages/openstackclient/tests/unit/network/v2/test_subnet.py:                              'nexthop': '10.20.20.1'}],
    	./microstack/245/lib/python3.8/site-packages/openstackclient/tests/unit/network/v2/test_subnet.py:                              'nexthop': '10.20.20.1'},
    	./microstack/245/lib/python3.8/site-packages/openstackclient/tests/unit/network/v2/test_subnet.py:                "destination": "10.20.20.0/24", "nexthop": "10.20.20.1"}],
    	./microstack/245/templates/05_snap_tweaks.j2:OPENSTACK_HOST = "10.20.20.1"
    	./microstack/245/templates/05_snap_tweaks.j2:        'LOCATION': '10.20.20.1:11211',
    	./microstack/245/usr/share/mysql/charsets/hp8.xml: 10 20 20 10 10 10 10 10 10 10 10 10 10 10 10 10
    
     root@ubuntu2004-121:/snap# cat ./microstack/245/bin/set-default-config.py
    	 
    	#!/usr/bin/env python3
    	
    	import os
    	import socket
    	
    	from init import shell
    	from init import credentials
    	
    	
    	def _get_default_config():
    	    snap_common = os.getenv('SNAP_COMMON')
    	    return {
    	        'config.is-clustered': False,
    	
    	        'config.cluster.tls-cert-path':
    	        f'{snap_common}/etc/cluster/tls/cert.pem',
    	        'config.cluster.tls-key-path':
    	        f'{snap_common}/etc/cluster/tls/key.pem',
    	
    	        'config.cluster.fingerprint': 'null',
    	        'config.cluster.hostname': 'null',
    	        'config.cluster.credential-id': 'null',
    	        'config.cluster.credential-secret': 'null',
    	
    	        'config.post-setup': True,
    	        'config.keystone.region-name': 'microstack',
    	        'config.credentials.key-pair': '/home/{USER}/snap/{SNAP_NAME}'
    	                                       '/common/.ssh/id_microstack',
    	        'config.network.node-fqdn': socket.getfqdn(),
    	        'config.network.dns-servers': '1.1.1.1',
    	        'config.network.dns-domain': 'microstack.example.',
    	        'config.network.ext-gateway': '10.20.20.1',
    	        'config.network.control-ip': '10.20.20.1',
    	        'config.network.compute-ip': '10.20.20.1',
    	        'config.network.ext-cidr': '10.20.20.1/24',
    	
    			......
    
    • 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
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    1. 按照 变通方式重设外网卡10.20.20.0/24 操作,删除前面安装时常见的 test 虚拟机、external 网卡和 test 网卡

    2. eth0 连接到 br-ex

      sudo ovs-vsctl add-port br-ex eth0
      
      • 1

      这两步最好在一行命令完成

      sudo ip addr flush dev eth0
      sudo ip addr add 192.168.0.121/24 dev br-ex
      
      • 1
      • 2

      合并后:

      sudo ip addr flush dev eth0 && sudo ip addr add 192.168.0.121/24 dev br-ex
      
      • 1

      br-ex 已经存在并启动,这一步不需要

      sudo ip link set br-ex up
      
      • 1
    3. 查看当前 IP
      $ ip a

      ......
      2: eth0:  mtu 1500 qdisc mq master ovs-system state UP group default qlen 1000
          link/ether 00:15:5d:5a:a6:60 brd ff:ff:ff:ff:ff:ff
      3: eth1:  mtu 1500 qdisc noop state DOWN group default qlen 1000
          link/ether 00:15:5d:5a:a6:61 brd ff:ff:ff:ff:ff:ff
      4: ovs-system:  mtu 1500 qdisc noop state DOWN group default qlen 1000
          link/ether f6:77:a1:b8:f3:d9 brd ff:ff:ff:ff:ff:ff
      5: br-ex:  mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
          link/ether 00:15:5d:5a:a6:60 brd ff:ff:ff:ff:ff:ff
          inet 10.20.20.1/24 scope global br-ex
             valid_lft forever preferred_lft forever
          inet 192.168.0.121/24 scope global br-ex
             valid_lft forever preferred_lft forever
          inet6 fe80::ac6b:41ff:fe3e:964c/64 scope link 
             valid_lft forever preferred_lft forever
      6: br-int:  mtu 1500 qdisc noop state DOWN group default qlen 1000
          link/ether a2:81:9b:cb:7b:40 brd ff:ff:ff:ff:ff:ff
          ......
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14
      • 15
      • 16
      • 17
      • 18

      现在 br-ex 链接了 2 个网卡
      00:15:5d:5a:a6:60 对应刚刚增加的 eth0

    4. dashboard 重新设置网卡和路由

      创建外网
      在这里插入图片描述
      外网子网
      在这里插入图片描述

      IP分配范围
      在这里插入图片描述

    5. 创建内网和路由
      创建过程(略)

      创建路由结果
      在这里插入图片描述

    测试一下
    microstack 安装已经设置了 ICMP 和 SSH 安全策略,无需再设置
    如果这个路由器 ping 不通,那就是外网不对,请重新尝试!

    $ ping 192.168.0.25

    PING 192.168.0.25 (192.168.0.25) 56(84) bytes of data.
    64 bytes from 192.168.0.25: icmp_seq=1 ttl=254 time=1.01 ms
    64 bytes from 192.168.0.25: icmp_seq=2 ttl=254 time=1.20 ms
    ......
    
    • 1
    • 2
    • 3
    • 4
    1. 新建一个虚拟机

    开始我这里一直报错,害得我重复好多次

    Error: Failed to perform requested operation on instance "test-vm", the instance has an error status: Please try again later [Error: Build of instance 431c5dee-8f7c-48e0-81d0-e1c8d92ed76f aborted: Invalid input received: Invalid image identifier or unable to access requested image. (HTTP 400) (Request-ID: req-98871a6d-7795-4bfb-9828-a75cb130b8bc)]. 
    
    • 1

    仔细阅读官方操作 Launch instances through the OpenStack dashboard

    注意: Create New Volume - Choose No
    在这里插入图片描述
    其他步骤(略)

    重启之后

    1. 按照 变通方式重设外网卡10.20.20.0/24 中加入一个 service 的方法,经过几次测试,总是不成功!

    2. 按照他的文章建立 microstack-br-workaround 和 microstack-br-workaround.service 文件
      抄录一下

      编写服务脚本
      $ cat /usr/local/bin/microstack-br-workaround

       #!/bin/bash
       #
       # Workaround to enable physical network access to MicroStack
       #
       # Adds the server physical ip address to br-ex.
       
       
       physicalcidr=192.168.0.121/24
       # gateway=192.168.1.1
       #
       # ovs-vsctl add-port br-ex eth0
       # ip addr flush dev eth0
       # ip address add $physicalcidr dev br-ex
       #
       # Add IP address to br-ex
       ip address add $physicalcidr dev br-ex || :
       ip link set br-ex up || :
       # ip route add default via $gateway dev br-ex || :
       #
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14
      • 15
      • 16
      • 17
      • 18
      • 19

      加入到 service

      $ cd /etc/systemd/system
      $ cat microstack-br-workaround.service

       [Unit]
       Description=Service for adding physical ip to microstack bridge
       Requires=snap.microstack.external-bridge.service
       After=snap.microstack.external-bridge.service
       
       [Service]
       ExecStart=/usr/local/bin/microstack-br-workaround
       SyslogIdentifier=microstack-br-workaround
       Restart=no
       WorkingDirectory=/usr/local/bin
       TimeoutStopSec=30
       Type=oneshot
       
       [Install]
       WantedBy=multi-user.target
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14
      • 15

      设置为 enable

      systemctl daemon-reload
      systemctl enable microstack-br-workaround.service

    3. 查看失败原因
      $ sudo systemctl status microstack-br-workaround.service

       ● microstack-br-workaround.service - Service for adding physical ip to microstack bridge
            Loaded: loaded (/etc/systemd/system/microstack-br-workaround.service; enabled; vendor preset: enabled)
            Active: failed (Result: exit-code) since Sun 2022-10-23 15:09:00 CST; 55s ago
           Process: 2266 ExecStart=/usr/local/bin/microstack-br-workaround (code=exited, status=203/EXEC)
          Main PID: 2266 (code=exited, status=203/EXEC)
       
       Oct 23 15:09:00 ubuntu2004-121 systemd[1]: Starting Service for adding physical ip to microstack bridge...
       Oct 23 15:09:00 ubuntu2004-121 systemd[1]: microstack-br-workaround.service: Main process exited, code=exited, status=203/EXEC
       Oct 23 15:09:00 ubuntu2004-121 systemd[1]: microstack-br-workaround.service: Failed with result 'exit-code'.
       Oct 23 15:09:00 ubuntu2004-121 systemd[1]: Failed to start Service for adding physical ip to microstack bridge.
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10

      暂时找不到好办法!

    4. 只好再次执行

      sudo ip addr flush dev eth0 && sudo ip addr add 192.168.0.121/24 dev br-ex

    5. 测试一下
      $ ping 192.168.0.25

       PING 192.168.0.25 (192.168.0.25) 56(84) bytes of data.
       64 bytes from 192.168.0.25: icmp_seq=1 ttl=254 time=5.29 ms
       64 bytes from 192.168.0.25: icmp_seq=2 ttl=254 time=0.989 ms
       ......
      
      • 1
      • 2
      • 3
      • 4

    后记

    另外找一个单网卡的虚拟机进行测试
    虽然 microstack-br-workaround 服务总是有错,但是,只是 ovs-vsctl del-port br-ex eth0 ,重启之后,还是可以继续

    $ sudo vim /usr/local/bin/microstack-br-workaround

     #!/bin/bash
     #
     # Workaround to enable physical network access to MicroStack
     #
     # Adds the server physical ip address to br-ex.
    
    
     physicalcidr=192.168.0.128/24
     ovs-vsctl del-port br-ex eth0
     #
     # gateway=192.168.1.81
     #
     #  ovs-vsctl add-port br-ex eth0
     # ip addr flush dev eth0 || :
     # ip address add $physicalcidr dev br-ex || :
     # ip link set br-ex up || :
     # ip route add default via $gateway dev br-ex || :
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
  • 相关阅读:
    深度学习微调
    字典树、AC自动机、后缀数组
    js笔试题(5)
    自定义注解以及注解在反射中的应用
    【蓝桥杯真题练习】STEMA科技素养练习题库 答案版010 持续更新中~
    网络安全从业人员能力图谱
    kubernetes 高可用集群
    【Java基础】自增自减、关系、逻辑及三元<运算符
    『亚马逊云科技产品测评』活动征文|Amazon EC2 的讲解及相关服务
    维度转换的艺术:Kylin Cube设计的自定义魔法
  • 原文地址:https://blog.csdn.net/u010953609/article/details/127464014