使用 Devstack 搭建 Openstack 开发环境

发布时间: 更新时间: 总字数:1317 阅读时间:3m 作者: 分享
专栏文章
  1. 使用 Devstack 搭建 Openstack 开发环境(当前)
  2. OpenStack 启动第一个云主机
  3. Neutron 基于 iptables 实现安全组功能
  4. cloudbase-init 安装使用与配置
  5. openstack中的metadata server
  6. OpenStack 介绍

本文介绍基于 devstack 搭建 OpenStack victoria 开发环境,已经处理安装过程的遇到的问题。

环境

  • 系统:Ubuntu 18.04 (Bionic Beaver)
  • 配置:4C4G20G
  • 网卡
    • ens33:192.168.179.9
    • ens39:172.20.0.9

安装

环境初始化

  • 安装部署过程中需要的软件包
apt install vim -y
  • 创建用户(安装使用)
$ sudo useradd -s /bin/bash -d /opt/stack -m stack
$ echo "stack ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/stack
$ sudo su - stack
  • 克隆 devstack 代码
$ git clone https://opendev.org/openstack/devstack
$ cd devstack
$ git checkout stable/victoria
  • 初始化配置文件

devstack 目录下创建 local.conf 文件,该文件初始化 OpenStack 的密码:

[[local|localrc]]
ADMIN_PASSWORD=xianbin
DATABASE_PASSWORD=$ADMIN_PASSWORD
RABBIT_PASSWORD=$ADMIN_PASSWORD
SERVICE_PASSWORD=$ADMIN_PASSWORD

配置代理

前期配置 git 代理:

git config --global http.proxy http://192.168.179.1:1082
git config --global https.proxy http://192.168.179.1:1082
git config --global --unset http.proxy
git config --global --unset https.proxy

后期根据实际情况配置全局代理

$ echo < EOF > ~/.bashrc
export http_proxy=http://192.168.179.1:1082
export https_proxy=http://192.168.179.1:1082
EOF
$ source ~/.bashrc  # 代理生效

安装

./stack.sh

安装过程的FAQ

安装过程中不可避免的遇到各种问题,采用对应的方法修复后,继续执行 ./stack.sh 即可。

  • ls: cannot open directory ‘/opt/stack/.cache/': Permission denied

修改权限:

sudo chown -R stack /opt/stack/.cache/
  • wget: unable to resolve host address ‘github.com’
sudo vim /etc/systemd/resolved.conf
cat /etc/systemd/resolved.conf |grep "^DNS"
DNS=223.5.5.5
cat /etc/resolv.conf |grep 223
nameserver 223.5.5.5
  • ERROR: Cannot uninstall ‘simplejson’. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

手工卸载 simplejson

sudo apt purge python3-simplejson

安装完成信息

  • 屏显
=========================
DevStack Component Timing
 (times are in seconds)
=========================
run_process           32
test_with_retry        3
apt-get-update        11
osc                  201
wait_for_service      28
git_timed            1974
dbsync                17
pip_install          300
apt-get               16
-------------------------
Unaccounted time     535
=========================
Total runtime        3117



This is your host IP address: 192.168.179.9
This is your host IPv6 address: ::1
Horizon is now available at http://192.168.179.9/dashboard
Keystone is serving at http://192.168.179.9/identity/
The default users are: admin and demo
The password: xianbin

Services are running under systemd unit files.
For more information see:
https://docs.openstack.org/devstack/latest/systemd.html

DevStack Version: victoria
Change: db54bd3f5169ec354e017d91911a6b9aa9c5a76c Merge "Add a variable to configure the Tempest venv upper constraints" into stable/victoria 2021-01-02 21:18:09 +0000
OS Version: Ubuntu 18.04 bionic
  • 服务信息

安装后,OpenStack 对应的服务都是以 devstack@ 开头,这样修改多个服务是可以批量的重启和查看信息

$ systemctl cat devstack@
devstack@c-api.service          devstack@n-api-meta.service     devstack@placement-api.service
devstack@c-sch.service          devstack@n-api.service          devstack@q-agt.service
devstack@c-vol.service          devstack@n-cond-cell1.service   devstack@q-dhcp.service
devstack@dstat.service          devstack@n-cpu.service          devstack@q-l3.service
devstack@etcd.service           devstack@n-novnc-cell1.service  devstack@q-meta.service
devstack@g-api.service          devstack@n-sch.service          devstack@q-svc.service
devstack@keystone.service       devstack@n-super-cond.service
  • 项目和网络信息

安装完成后,默认创建admindemoalt_demo的项目和对应的网络

$ openstack project list
+----------------------------------+--------------------+
| ID                               | Name               |
+----------------------------------+--------------------+
| 1ad8560222f14ffd88e7fb8d95668435 | invisible_to_admin |
| 45837e6267c44d7788a919d6e342e64c | admin              |
| 5f18ebee39d5466eaabce9cec2b365bc | demo               |
| d527f15283cf460ea88ac00f0269d86a | service            |
| f18f94eb59124f7891bded8f5c1bcfeb | alt_demo           |
+----------------------------------+--------------------+
$ openstack net list
+--------------------------------------+---------+----------------------------------------------------------------------------+
| ID                                   | Name    | Subnets                                                                    |
+--------------------------------------+---------+----------------------------------------------------------------------------+
| 51502180-beef-415b-b358-550de60035fa | shared  | 55e81845-8d0a-4f95-bff5-ffbc367398c1                                       |
| 63e18f24-29ca-410e-9553-f5fa59d691ea | private | 20a84bb8-8b2f-4c2e-8bcd-411b52b3c132, c16600b1-74e4-493b-8709-ef943ac9cf5c |
| ab23644e-5774-40b7-8502-9f5aaef265a6 | public  | 4bfffddc-c021-4647-9ec5-6174e427e0fd, 74784025-dd63-47f3-a239-4e1e5270f14d |
+--------------------------------------+---------+----------------------------------------------------------------------------+
  • OVS 信息
ovs-default-info
$ sudo ovs-vsctl show
0976470f-8041-45d1-ad1a-34cd061684d3
    Manager "ptcp:6640:127.0.0.1"
        is_connected: true
    Bridge br-ex
        Controller "tcp:127.0.0.1:6633"
            is_connected: true
        fail_mode: secure
        datapath_type: system
        Port br-ex
            Interface br-ex
                type: internal
        Port phy-br-ex
            Interface phy-br-ex
                type: patch
                options: {peer=int-br-ex}
    Bridge br-tun
        Controller "tcp:127.0.0.1:6633"
            is_connected: true
        fail_mode: secure
        datapath_type: system
        Port br-tun
            Interface br-tun
                type: internal
        Port patch-int
            Interface patch-int
                type: patch
                options: {peer=patch-tun}
    Bridge br-int
        Controller "tcp:127.0.0.1:6633"
            is_connected: true
        fail_mode: secure
        datapath_type: system
        Port qg-7ffce5e4-8b
            tag: 3
            Interface qg-7ffce5e4-8b
                type: internal
        Port tap126df190-98
            tag: 2
            Interface tap126df190-98
                type: internal
        Port tapb1055e4e-0e
            tag: 1
            Interface tapb1055e4e-0e
                type: internal
        Port qr-2d9b0c04-c8
            tag: 1
            Interface qr-2d9b0c04-c8
                type: internal
        Port br-int
            Interface br-int
                type: internal
        Port qr-0712d828-9e
            tag: 1
            Interface qr-0712d828-9e
                type: internal
        Port int-br-ex
            Interface int-br-ex
                type: patch
                options: {peer=phy-br-ex}
        Port patch-tun
            Interface patch-tun
                type: patch
                options: {peer=patch-int}
    ovs_version: "2.13.1"
  • 查看日志
sudo journalctl -f --unit devstack@n-*

修复 cinder vg 不存在的问题

错误信息

/etc/cinder/cinder.conf 中配置了 lvmdriver-1 默认采用名称为 stack-volumes-lvmdriver-1vg,该 vg 默认是不存在的。

stack@xiexianbin-vm:~/horizon$ journalctl -f --unit devstack@* |grep ERROR
Hint: You are currently not seeing messages from other users and the system.
      Users in groups 'adm', 'systemd-journal' can see all messages.
      Pass -q to turn off this notice.
Mar 22 15:44:53 xiexianbin-vm cinder-volume[1174]: ERROR cinder.service [-] Manager for service cinder-volume xiexianbin-vm@lvmdriver-1 is reporting problems, not sending heartbeat. Service will appear "down".

模拟创建vg

本示例采用 dd 模拟了一块磁盘设备,并把它给 cinder 使用,具体步骤如下:

$ mkdir ~/volumes
$ cd volumes/
$ dd if=/dev/zero of=~/volumes/stack-volumes-lvmdriver-1 bs=1M count=2024
$ losetup -f
$ sudo losetup /dev/loop16 ~/volumes/stack-volumes-lvmdriver-1
$ sudo pvcreate /dev/loop16
$ sudo vgcreate stack-volumes-lvmdriver-1 /dev/loop16
  Volume group "stack-volumes-lvmdriver-1" successfully created
$ sudo vgdisplay
  --- Volume group ---
  VG Name               stack-volumes-lvmdriver-1
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               1.97 GiB
  PE Size               4.00 MiB
  Total PE              505
  Alloc PE / Size       0 / 0
  Free  PE / Size       505 / 1.97 GiB
  VG UUID               nuwFvP-rxnN-6DOh-frM3-nfxD-Jw1A-CUU5Zt
  • 重启cinder服务:
sudo systemctl restart devstack@c-vol.service
  • 加载 openrc
source devstack/openrc admin admin
  • 创建 volume 成功
$ openstack volume create t-1 --size 1
$ openstack volume list
+--------------------------------------+------+-----------+------+-------------+
| ID                                   | Name | Status    | Size | Attached to |
+--------------------------------------+------+-----------+------+-------------+
| 7d8fdd3d-f3f5-46d6-866a-f485f5b36c78 | t-1  | available |    1 |             |
+--------------------------------------+------+-----------+------+-------------+

清理所有的网络

为方便后续对 OpenStack 的研究,本示例通过 dashboard,把所有自动创建的网络清理掉,清理后的 ovs 信息如下

ovs-new-info
$ sudo ovs-vsctl show
0976470f-8041-45d1-ad1a-34cd061684d3
    Manager "ptcp:6640:127.0.0.1"
        is_connected: true
    Bridge br-ex
        Controller "tcp:127.0.0.1:6633"
            is_connected: true
        fail_mode: secure
        datapath_type: system
        Port br-ex
            Interface br-ex
                type: internal
        Port phy-br-ex
            Interface phy-br-ex
                type: patch
                options: {peer=int-br-ex}
    Bridge br-tun
        Controller "tcp:127.0.0.1:6633"
            is_connected: true
        fail_mode: secure
        datapath_type: system
        Port br-tun
            Interface br-tun
                type: internal
        Port patch-int
            Interface patch-int
                type: patch
                options: {peer=patch-tun}
    Bridge br-int
        Controller "tcp:127.0.0.1:6633"
            is_connected: true
        fail_mode: secure
        datapath_type: system
        Port br-int
            Interface br-int
                type: internal
        Port int-br-ex
            Interface int-br-ex
                type: patch
                options: {peer=phy-br-ex}
        Port patch-tun
            Interface patch-tun
                type: patch
                options: {peer=patch-int}
    ovs_version: "2.13.1"

OVS 架构图

TODO:

专栏文章
  1. 使用 Devstack 搭建 Openstack 开发环境(当前)
  2. OpenStack 启动第一个云主机
  3. Neutron 基于 iptables 实现安全组功能
  4. cloudbase-init 安装使用与配置
  5. openstack中的metadata server
  6. OpenStack 介绍
最新评论
加载中...
Home Archives Categories Tags