最近在学习openstack,因为人懒不想跟着官方文档一步步敲命令行部署,我最终是使用devstack来部署openstack的,由于脸黑,我用了2天时间才成功在虚拟机中部署成功。所以在这里分享一下怎么使用devstack来完成all-in-one的openstack部署。
准备
虚拟机
因为采用的all-in-one的部署方式,所以需要准备一台虚拟机作为openstack部署的主体,将所有的openstack服务都安装在一台虚拟机中。
我使用的虚拟机软件是VMware,操作系统版本为Ubuntu 16.04。这里需要提一下,由于版本更新,devstack目前只支持Ubuntu 16,且openstack的pike、queens中很多默认库的版本与Ubuntu 14.04不匹配,在安装时会产生极大的麻烦(虽然16.04也很麻烦)。所以建议使用Ubuntu 16.04作为操作系统来安装虚拟机。
这里提供一下Ubuntu 16.04的ISO下载链接:link。
至于虚拟机的配置,这里建议8G内存+50G磁,实在不行也要保证4G以上的内存。
换sources.list源
先安装一下vim:
sudo apt install vim
编辑sources.list文件:
sudo vim /etc/apt/sources.list
这一步很重要,openstack部署失败最大一部分原因就是资源在国外,下载时因为网络不稳定而出现time out,直接退出部署。我在这里提供一下我选择的源:source.list配置,也可以直接复制:
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security multiverse
在修改完成后,更新一下源:
sudo apt-get update
安装git
因为devstack的项目是在公开github上的,所以我们安装git:
sudo apt-get install git
安装pip并修改源
因为devstack部署openstack时有很多需要使用pip下载的python库,所以我们先下载python-pip:
apt-get install python-pip
我们选择把pip的源修改为国内的,这样安装的成功率会提升很多:
mkdir ~/.pip && vim ~/.pip/pip.conf
提供一下我的配置:pip源配置,也可以直接复制:
[global]
trusted-host=mirrors.aliyun.com
index-url=http://mirrors.aliyun.com/pypi/simple
这里还有最后一步,就是更新一下pip的版本,以免pip的版本过低而下载不了devstack需要的python库:
pip install --upgrade pip
下载devstack
这一步我们下载从github上下载一个稳定的版本,毕竟不是做开发要求,还是尽量避过最新版,选择一个稳定的devstack版本即可:
git clone https://git.openstack.org/openstack-dev/devstack
cd devstack
git checkout remotes/origin/stable/queens
git checkout -b queens
或:
git clone https://git.openstack.org/openstack-dev/devstack -b stable/queens
创建stack用户并赋予权限
这一步我们需要创建一个stack用户,这是因为devstack在部署openstack时需要系统权限,但又不能以root的身份去执行devstack的脚本,所以我们创建一个stack用户,并赋予它root权限
而在我们下载的devstack中就直接有创建stack用户的脚本,我们可以直接拿来:
sudo devstack/tools/create-stack-user.sh
然后是赋予stack用户权限:
echo "stack ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/stack
这一步可能会出问题,所以最保险的方法还是进入/etc/sudoers, 在 root ALL=(ALL:ALL) ALL
后添加 stack ALL=(ALL:ALL) ALL
, 然后保存。
最后切换到stack用户:
sudo -i
su stack
修改devstack文件夹权限
这里我们需要修改devstack文件夹的权限,使其可以被stack用户操作:
chown -R stack:stack /home/devstack
chmod 777 /dev/pts/0
修改devstack配置文件local.conf
这一步通过下面的方法生成local.conf,local.conf是devstack的安装参数:
cp samples/local.conf ./
sudo vim local.conf
这个配置文件网络上有很多版本,我来来回回试了很多个都失败了,最后找了一个配置成功了。我提供一下我配置的local.conf:
[[local|localrc]]
HOST_IP=127.0.0.1
# Minimal Contents
# ----------------
# While ``stack.sh`` is happy to run without ``localrc``, devlife is better when
# there are a few minimal variables set:
# If the ``*_PASSWORD`` variables are not set here you will be prompted to enter
# values for them by ``stack.sh``and they will be added to ``local.conf``.
ADMIN_PASSWORD=nomoresecret
DATABASE_PASSWORD=stackdb
RABBIT_PASSWORD=stackqueue
SERVICE_PASSWORD=$ADMIN_PASSWORD
# ``HOST_IP`` and ``HOST_IPV6`` should be set manually for best results if
# the NIC configuration of the host is unusual, i.e. ``eth1`` has the default
# route but ``eth0`` is the public interface. They are auto-detected in
# ``stack.sh`` but often is indeterminate on later runs due to the IP moving
# from an Ethernet interface to a bridge on the host. Setting it here also
# makes it available for ``openrc`` to include when setting ``OS_AUTH_URL``.
# Neither is set by default.
#HOST_IPV6=2001:db8::7
# Logging
# -------
# By default ``stack.sh`` output only goes to the terminal where it runs. It can
# be configured to additionally log to a file by setting ``LOGFILE`` to the full
# path of the destination log file. A timestamp will be appended to the given name.
LOGFILE=$DEST/logs/stack.sh.log
# Old log files are automatically removed after 7 days to keep things neat. Change
# the number of days by setting ``LOGDAYS``.
LOGDAYS=2
# Nova logs will be colorized if ``SYSLOG`` is not set; turn this off by setting
# ``LOG_COLOR`` false.
#LOG_COLOR=False
# Using milestone-proposed branches
# ---------------------------------
# Uncomment these to grab the milestone-proposed branches from the
# repos:
#CINDER_BRANCH=milestone-proposed
#GLANCE_BRANCH=milestone-proposed
#HORIZON_BRANCH=milestone-proposed
#KEYSTONE_BRANCH=milestone-proposed
#KEYSTONECLIENT_BRANCH=milestone-proposed
#NOVA_BRANCH=milestone-proposed
#NOVACLIENT_BRANCH=milestone-proposed
#NEUTRON_BRANCH=milestone-proposed
#SWIFT_BRANCH=milestone-proposed
# Using git versions of clients
# -----------------------------
# By default clients are installed from pip. See LIBS_FROM_GIT in
# stackrc for details on getting clients from specific branches or
# revisions. e.g.
# LIBS_FROM_GIT="python-ironicclient"
# IRONICCLIENT_BRANCH=refs/changes/44/2.../1
# Swift
# -----
# Swift is now used as the back-end for the S3-like object store. Setting the
# hash value is required and you will be prompted for it if Swift is enabled
# so just set it to something already:
SWIFT_HASH=66a3d6b56c1f479c8b4e70ab5c2000f5
# For development purposes the default of 3 replicas is usually not required.
# Set this to 1 to save some resources:
SWIFT_REPLICAS=1
# The data for Swift is stored by default in (``$DEST/data/swift``),
# or (``$DATA_DIR/swift``) if ``DATA_DIR`` has been set, and can be
# moved by setting ``SWIFT_DATA_DIR``. The directory will be created
# if it does not exist.
SWIFT_DATA_DIR=$DEST/data
API_WORKERS=1
GIT_BASE=http://git.trystack.cn
NOVNC_REPO=http://git.trystack.cn/kanaka/noVNC.git
SPICE_REPO=http://git.trystack.cn/git/spice/spice-html5.git
disable_service tempest heat cinder
保存虚拟机快照
这一步十分十分十分十分关键!!完成了上面所有步骤,接下来我们就要开始直接安装了,我们可能会失败好几次,所以保存现在我们做好的环境十分重要。不然devstack部署openstack彻底失败后,你也不想彻底失败后从头再来配置一遍环境吧?
开始安装
完成了上面所有的步骤,那就开始安装吧,朋友们,万里长征开始了。(建议下载一部电影,因为部署过程很漫长,大概要40多分钟,而且中途任何一个过程都可能失败而退出安装)
执行:
./stack.sh
安装的开头要求你输入几次密码,然后就自己开始跑脚本。
问题
在部署的过程中,我遇到了好几次问题,来来回回大概部署7到8次才最后成功。如果你按照我上面的步骤进行,遇到的问题大概有下面几种。
pip无法安装指定版本库
这个问题还挺坑的,脚本会提示你pip版本太低,无法下载指定版本的python库,并提示你先更新pip版本。当时我按提示更新pip版本到最新,重新部署后它又提示我pip版本太低…后来发现,是因为我在部署前没有更新pip,版本的缓存被devstack记录下来了,所以每次部署又会回退到上一个版本。
如果你按照我上面的步骤,提前更新了pip版本,应该不会遇到这个问题。如果遇到了,用以下方法解决:看看出错时的安装库和指定版本,在新一次部署前先把这个库下载安装了:
pip install scipy == 0.15.1
这样部署时检测到这个库的版本已经安装了,就会跳过检测,继续往下部署,就不会出问题了。
time out
这个估计是最常见的问题,因为部署在虚拟机中,很可能出现网络不稳定的情况,一段时间无法下载后就会报time out的错,然后退出安装。这个问题有可能是你本身网络的问题,也有可能是对方源的问题,这很常见,很多人今天安装失败了,然后第二天就安装成功了。所以,这个问题的解决方法:重复安装,然后看脸。
如果你按照我上面的步骤部署,遇到time out的几率会低很多,我部署时只在开始时遇到过一次time out,后面基本上没遇到。
其他问题
其实部署的过程中还遇到了很多奇奇怪怪的问题,一般在google上能直接搜到解决方案,学会利用搜索引擎也是一项十分重要的技能。如果到后来,你试了很多解决方案导致系统环境变得很奇怪时,尝试卸载部署环境并且重新开始部署:
./unstack.sh
./clean.sh
然后再次安装:
./stack.sh
如果连卸载都处理不了,整个虚拟机环境都很奇怪时,直接还原快照(所以前面提醒了好多次做快照)。
后记
其实到最后,我的devstack还是显示部署失败了。
stack.sh failed: full log in /opt/stack/logs/stack.sh.log
Error on exit
然而我访问openstack网页端时却发现其实已经部署成功了。我在网上查了这个问题,很多人也遇到了,但是并没有解决的,因为其实已经部署完成了,可能有一些小问题,但是并不影响使用,所以就没有理他。而在后面测试openstack的时候,发现了无法分配浮动ip的问题,不知道这是不是部署失败的后遗症:
Error: Failed to perform requested operation on instance "vm1", the instance has an error status: Please try again later [Error: Host 'ccrfox105' is not mapped to any cell].
对于这点我还是找到了解决方案:
cd devstack
source openrc voidking project
source openrc admin admin
nova-manage cell_v2 discover_hosts
之后还遇到了网络不通的情况,查过资料后采用创建安全组的方式解决。所以感觉最后的部署失败虽然不影响openstack的使用,但还是留下了不少隐患,不过对我们体验openstack来说,还是没什么问题的。