侧边栏壁纸
博主头像
AI研究僧

hycj89@163.com

  • 累计撰写 1,899 篇文章
  • 累计创建 179 个标签
  • 累计收到 1 条评论
标签搜索

目 录CONTENT

文章目录

使用devstack在单机上安装openstack(stein版本)和zun的踩坑之路

AI研究僧
2022-06-07 / 0 评论 / 0 点赞 / 662 阅读 / 1,930 字

需求

公司已有环境是openstack分布式版本,调试有些麻烦,因此想在单机上安装openstack,即devstack,并安装组件zun及zun-ui,以便对zun组件进行调试开发

环境版本

openstack: stable/stein(公司已有版本为该版本)

zun: stable/stein

操作系统:vmware安装的 ubuntu18.04(stein版本不要用16.04,stein版本的bug会的导致使用python3.5报错),也不要用centos7

python:ubuntu18自带python3.6及自行安装python2.7(apt install python)

apt源及必要软件安装(root用户操作)

更改apt源为国内源

cd /etc/apt
mv sources.list sources.list.bak
vi /etc/apt/sources.list

添加163源如下所示

deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable
# deb-src [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable

安装必要工具

apt-get install git python-pip
pip install --upgrade pip
apt install vim

更换pip为国内源

注:更换为国内源后速度会大幅提升,但是有可能会遇到错误如下:

Could not install packages due to an EnvironmentError: ("Connection broken: error(104, 'Connection reset by peer')", error(104, 'Connection reset by peer'))

该错误困扰本人很久,后在该文 https://www.oukohou.wang/2019/04/21/reocrds_of_installation_errors_and_operations 看到解释,简单说就是下载太快导致服务端关闭了连接,后将国内源删掉后不再报错

cd ~             
mkdir .pip      
vim .pip/pip.conf

添加内容如下:

# pip 清华源
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn

devstack安装

下载devstack

# root用户
cd /opt
# 注意从国内镜像下载,从github下载太慢,且不要下载zip和tar包来使用
git clone http://git.trystack.cn/openstack/devstack.git -b stable/stein  # 指定stein版本

如果下载zip或tar包,会报错如下:

Exception: Versioning for this project requires either an sdist tarball, or access to an upstream git repository. It's also possible that there is a mismatch between the package name in setup.cfg and the argument given to pbr.version.VersionInfo. Project name zun was given, but was not able to be found.
error in setup command: Error parsing /opt/stack/zun/setup.cfg: Exception: Versioning for this project requires either an sdist tarball, or access to an upstream git repository. It's also possible that there is a mismatch between the package name in setup.cfg and the argument given to pbr.version.VersionInfo. Project name zun was given, but was not able to be found.

此问题困扰很久,后在 http://omeranson.github.io/blog/2017/02/22/Installing-with-pip-without-a-version 中最后发现作者提到不要直接下载zip文件,本来我是下载的tar包解压来执行的,因为git clone太慢,结果就是一直报这个错。

创建stack用户

cd /devstack/tools
./create-stack-user.sh

创建的stack用户家目录在 /opt/stack

将devstack目录移动到 /opt/stack 中,并设置权限

mv /opt/devstack /opt/stack
chown -R stack:stack /opt/stack/devstack

切换至stack用户直至安装完成

su stack

创建配置文件

# stack用户
cd ~/devstack
vim local.conf

添加如下内容

# 本文内容基于 https://docs.openstack.org/zun/latest/contributor/quickstart.html 中生成的local.conf修改而来
[[local|localrc]]
# 本机ip
HOST_IP=192.168.221.129
DATABASE_PASSWORD=admin
RABBIT_PASSWORD=admin
SERVICE_TOKEN=admin
SERVICE_PASSWORD=admin
ADMIN_PASSWORD=admin
# 下载插件版本
TARGET_BRANCH=stable/stein
# 该包指定版本,原因见后边
TEMPEST_BRANCH=20.0.0


# 定义在 DevStack 构建过程中自动下载的镜像,地址失效了,因此注释掉,会自动从默认位置下载
# DOWNLOAD_DEFAULT_IMAGES=False
# IMAGE_URLS="http://images.trystack.cn/cirros/cirros-0.3.4-x86_64-disk.img"

# use TryStack git mirror 使用国内镜像源
GIT_BASE=http://git.trystack.cn
NOVNC_REPO=http://git.trystack.cn/kanaka/noVNC.git
SPICE_REPO=http://git.trystack.cn/git/spice/sice-html5.git
# 需要加载的插件,默认会安装nova、cinder、horizon、neutron、keystone等组件,如果需要安装其他组件,则以插件形式安装。注意地址全是国内源
enable_plugin zun http://git.trystack.cn/openstack/zun $TARGET_BRANCH
# zun-tempest-plugin该组件无分支
enable_plugin zun-tempest-plugin http://git.trystack.cn/openstack/zun-tempest-plugin

#This below plugin enables installation of container engine on Devstack.
#The default container engine is Docker
enable_plugin devstack-plugin-container http://git.trystack.cn/openstack/devstack-plugin-container $TARGET_BRANCH

# In Kuryr, KURYR_CAPABILITY_SCOPE is `local` by default,
# but we must change it to `global` in the multinode scenario.
KURYR_CAPABILITY_SCOPE=global
KURYR_PROCESS_EXTERNAL_CONNECTIVITY=False
# 该组件要指定tag,stein分支已经不存在,3.0.0版本对应的是stein。不指定会报错
enable_plugin kuryr-libnetwork http://git.trystack.cn/openstack/kuryr-libnetwork 3.0.0

# install python-zunclient from git 此组件会下载最新版本,最新版要求python>=3.6,暂时无用,因此注释掉
# LIBS_FROM_GIT="python-zunclient"

# Optional:  uncomment to enable the Zun UI plugin in Horizon
enable_plugin zun-ui http://git.trystack.cn/openstack/zun-ui $TARGET_BRANCH

# Optional:  uncomment to enable the Heat plugin for container orchestration
# enable_plugin heat http://git.trystack.cn/openstack/heat $TARGET_BRANCH

TEMPEST_BRANCH指定版本原因是默认情况下会下载最新版本,然后会出现类似如下错误

Obtaining file:///opt/stack/tempest
tempest requires Python '>=3.6' but the running Python is 3.5.2

因此指定版本后解决该问题

进入files目录先下载所需的文件

cd ~/devstack/files
wget -c https://github.com/coreos/etcd/releases/download/v3.1.10/etcd-v3.1.10-linux-amd64.tar.gz
wget -c https://github.com/coreos/etcd/releases/download/v3.1.7/etcd-v3.1.7-linux-amd64.tar.gz
wget -c https://github.com/coreos/etcd/releases/download/v3.3.12/etcd-v3.3.12-linux-amd64.tar.gz
wget https://bootstrap.pypa.io/pip/2.7/get-pip.py  # python2
mv get-pip.py get-pip.py-py27

wget https://bootstrap.pypa.io/get-pip.py # python3

以上内容如果下载太慢,可以在能下载下来的机器上下载完成后,拷贝到files目录中

安装

cd ~/devstack
./stack.sh

经过漫长等待后见到如下所示即成功:

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

WARNING: 
Using lib/neutron-legacy is deprecated, and it will be removed in the future


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

DevStack Version: stein
Change: c67e7d3bbd15522fc298ed14803c8eda37c Mark our source trees as safe for git to use as other users 2022-04-20 12:15:55 +0200
OS Version: Ubuntu 18.04 bionic

打开浏览器访问如上所示地址并输入用户名密码即可登录成功。
见到如下页面时多日阴霾一扫而空,看似简单的过程,实则安装中的各种问题令人头大,建议想要尝试openstack的直接上最新版本,不要用旧版本
Snipaste_2022-06-07_14-47-12

如果遇到了其他问题,欢迎讨论

如果要使用命令行执行openstack命令,还要执行source /opt/stack/devstack/openrc admin admin激活环境变量

卸载

cd ~/devstack
./unstack.sh
./clean.sh
pip freeze | grep -v '^\-e' | xargs sudo pip uninstall -y

最后删掉/opt/stack目录下除devstack外的所有内容

之后可以重新安装

参考链接

http://omeranson.github.io/blog/2017/02/22/Installing-with-pip-without-a-version
http://git.trystack.cn/cgit
https://docs.openstack.org/devstack/stein/
https://www.infoq.cn/article/v35tdykox*vow5y9vsge
https://blog.csdn.net/qq_41773806/article/details/116561060
https://www.jianshu.com/p/654e05034427
https://docs.openstack.org/zun/latest/contributor/quickstart.html
https://www.oukohou.wang/2019/04/21/reocrds_of_installation_errors_and_operations

博主关闭了所有页面的评论