openstack之devstack

DevStack可以用来快速搭建 OpenStack 的运行和开发环境,特别适合在自己的笔记本上搭建一个开发环境出来。

参考:http://docs.openstack.org/developer/devstack/

环境说明

官方文档目前只有Ubuntu 14.04 (Trusty), Fedora 21 (or Fedora 22) 和 CentOS/RHEL 7的,不过 OpenSUSE 和 Debian也支持。我选择最小化安装的CentOS 7系统。

主机环境

Devstack VM:
Name: devstack
vCPU:4
Memory :4G
Disk:30G
Networks: ens160,ens192

网络环境

ens160:
Purpose: management network
IP block: 192.168.56.101/24
DHCP: disable
Linux device: eth0

ens192:
Purpose: public network
DHCP: disable
IP block: 192.168.199.223/24
Linux device: eth1

OpenStack组件
默认情况下会安装一下组件

cinder
glance
horizon
keystone
nova
swift

可以对local.conf进行扩展,安装其他相应组件。

ceilometer
neutron
heat
horizon
sahara
trove

相关设置

主机名设置

#
hostnamectl set-hostname devstack

hosts设置

#
echo "
192.168.56.101 devstack">>/etc/hosts

关闭selinux

#
/usr/sbin/sestatus -v
/usr/sbin/setenforce 0
sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config

关闭防火墙、网络管理

#
systemctl stop NetworkManager
systemctl disable NetworkManager
systemctl stop firewalld.service
systemctl disable firewalld.service
systemctl stop iptables.service
systemctl disable iptables.service

安装相关软件包

#
yum install -y open-vm-tools
yum install -y git

安装

devstack 官网地址:https://git.openstack.org/cgit/openstack-dev/devstack/

克隆devstack仓库

#
cd /opt
git clone git://git.openstack.org/openstack-dev/devstack
#或者
git clone https://git.openstack.org/openstack-dev/devstack

使用提供的脚本创建stack用户

#
cd devstack
./tools/create-stack-user.sh
chown -R stack:stack /opt/devstack
chmod 777 /opt/devstack -R
su - stack

进行安装

$
cd /opt/devstack
./stack.sh

整个过程需要的时间视各地网络速度而定,特别是你如果没有梯子,为你默哀。安装过程中可以研究一下这个脚本 。最后出现类似如下输出,说明安装完成。

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

打开浏览器输入http://10.20.0.210/ 登录Dashboard

默认Devstack创建 admin和demo两个用户,通过设置环境变量可以进行操作。
admin 用户

$
source openrc admin admin

demo 用户

$
source openrc demo demo

local.conf文件参考

echo "">local.conf

一些问题

##stack.sh中的执行顺序:

禁止使用root运行
读取local.conf
检查stackrc文件是否存在
检查Devstack是不是已经在运行。如果在运行,则退出
配置目标安装目录,包括创建目录,设置权限
配置hostname,logging等
读取各组件的安装和启动script
如果没有配置密码,则需要用户输入各密码
配置数据库
配置Keystone
安装各pre-condition包
安装client包
安装和配置keystone,swift,glance,cinder,neutron,nova,horizon,ceilometer,heat,CA
配置数据库
配置screen
创建个组件使用的账号
初始化和启动horizon
启动swift,glance,
安装images
启动swift,nova_api,neutron,nova,cinder,ceilometer,heat

重新安装

安装失败时,可以再次执行安装命令。

$
./unstack.sh --all && ./stack.sh

设置代理

可能需要配置一下代理,不然部分资源无法下载。

#
export http_proxy=http://192.178.102.30:1080
export https_proxy=http://192.178.102.30:1080
#排除不需要代理的IP地址(可选)
export no_proxy="127.0.0.1,192.178.102.249"

更换系统源

修改Base、epel源为阿里的,我自己的网络,使用阿里源基本能满速。

#
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
curl http://mirrors.aliyun.com/repo/Centos-7.repo -o /etc/yum.repos.d/CentOS-Base.repo
curl http://mirrors.aliyun.com/repo/epel-7.repo -o /etc/yum.repos.d/epel.repo
yum clean all && yum makecache

更换pip源

同样修改pip源为阿里的。

#
mkdir ~/.pip
cat << EOF > ~/.pip/pip.conf
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
trusted-host = mirrors.aliyun.com
EOF

更换git源

在执行devstack的过程中,要去clone官方的源码,默认用的是git://协议,如果你配置了https的代理,可以更换为https://协议。

#
sed -i '/git:/s/git:/https:/' stackrc

在Devstack中提供了另外一个脚本叫做rejoin-stack.sh,原理很简单就是把所有的进程重新组合进screen,所以我们借助这个脚本完全可以不重新执行stack.sh,快速恢复环境。但是当虚拟机重启后,cinder使用的卷组并不会自动重建,所以在运行rejoin之前,需要将恢复卷组的工作,放入开机启动的脚本中。

/etc/init.d/cinder-setup-backing-file

losetup /dev/loop1 /opt/stack/data/stack-volumes-default-backing-file
losetup /dev/loop2 /opt/stack/data/stack-volumes-lvmdriver-1-backing-file
exit 0
#
chmod 755 /etc/init.d/cinder-setup-backing-file
ln -s /etc/init.d/cinder-setup-backing-file /etc/rc2.d/S10cinder-setup-backing-file
$
cd $HOME/devstack
./rejoin-stack.sh

执行完rejoin_stack.sh后,需要使用screen语法来控制openstack的进程。
帮助 ctrl+a+?
查看screen导航 ctrl+a+” 注需要使用shift键
退出screen,有两种方法:
方法1:attach screen ctrl+a+d
方法2:exit screen ctrl+a+K
查看下一个screen ctrl+a+n
查看上一个screen ctrl+a+p
保存screen的日志到文件 ctrl+a+H,再按一次停止保存。
查看screen

#
screen -ls

缺少相关的包

在安装过程中会提示缺少zookeeper的依赖包,CentOS 7下已经无法直接yum安装zookeeper,我们可以先注释掉。这个问题今天已经修复了。

Complete!
++ die 1251 'Missing packages detected'
++ local exitcode=1
++ set +o xtrace
[Call Trace]
./stack.sh:708:source
/opt/devstack/tools/install_prereqs.sh:72:install_package
/opt/devstack/functions-common:1195:real_install_package
/opt/devstack/functions-common:1183:yum_install
/opt/devstack/functions-common:1251:die
[ERROR] /opt/devstack/functions-common:1251 Missing packages detected
Error on exit
World dumping... see /opt/stack/logs/worlddump-2015-11-13-141036.txt for details

No package zookeeper available.
Nothing to do
++ die 1251 'Missing packages detected'
++ local exitcode=1
++ set +o xtrace
[Call Trace]
./stack.sh:708:source
/opt/devstack/tools/install_prereqs.sh:72:install_package
/opt/devstack/functions-common:1195:real_install_package
/opt/devstack/functions-common:1183:yum_install
/opt/devstack/functions-common:1251:die
[ERROR] /opt/devstack/functions-common:1251 Missing packages detected
Error on exit
World dumping... see /opt/stack/logs/worlddump-2015-11-13-141445.txt for details

解决办法:
暂时注释stackrc文件的zookeeper。

ENABLED_SERVICES+=,rabbit,tempest,mysql,dstat,zookeeper

AttributeError: ‘module’ object has no attribute ‘PY2’错误

+ local xtrace
++ set +o
++ grep xtrace
+ xtrace='set -o xtrace'
+ set +o xtrace
+ sudo chown -R stack /opt/stack/horizon/horizon.egg-info
+ cd /opt/stack/horizon
+ ./run_tests.sh -N --compilemessages
Traceback (most recent call last):
File "/opt/stack/horizon/manage.py", line 23, in <module>
execute_from_command_line(sys.argv)
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
utility.execute()
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 303, in execute
settings.INSTALLED_APPS
File "/usr/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/usr/lib/python2.7/site-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/usr/lib/python2.7/site-packages/django/conf/__init__.py", line 92, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/opt/stack/horizon/openstack_dashboard/settings.py", line 27, in <module>
from openstack_dashboard import exceptions
File "/opt/stack/horizon/openstack_dashboard/exceptions.py", line 20, in <module>
from glanceclient.common import exceptions as glanceclient
File "/usr/lib/python2.7/site-packages/glanceclient/__init__.py", line 18, in <module>
import glanceclient.client
File "/usr/lib/python2.7/site-packages/glanceclient/client.py", line 18, in <module>
from glanceclient.common import utils
File "/usr/lib/python2.7/site-packages/glanceclient/common/utils.py", line 36, in <module>
from oslo_utils import strutils
File "/usr/lib/python2.7/site-packages/oslo_utils/strutils.py", line 26, in <module>
from oslo_utils._i18n import _
File "/usr/lib/python2.7/site-packages/oslo_utils/_i18n.py", line 21, in <module>
import oslo_i18n
File "/usr/lib/python2.7/site-packages/oslo_i18n/__init__.py", line 13, in <module>
from ._factory import *
File "/usr/lib/python2.7/site-packages/oslo_i18n/_factory.py", line 26, in <module>
from oslo_i18n import _message
File "/usr/lib/python2.7/site-packages/oslo_i18n/_message.py", line 38, in <module>
class Message(six.text_type):
File "/usr/lib/python2.7/site-packages/oslo_i18n/_message.py", line 232, in Message
if six.PY2:
AttributeError: 'module' object has no attribute 'PY2'
+ exit_trap
+ local r=1
++ jobs -p
+ jobs=
+ [[ -n '' ]]
+ kill_spinner
+ '[' '!' -z '' ']'
+ [[ 1 -ne 0 ]]
+ echo 'Error on exit'
Error on exit
+ [[ -z /opt/stack/logs ]]
+ /opt/devstack/tools/worlddump.py -d /opt/stack/logs
World dumping... see /opt/stack/logs/worlddump-2015-11-14-104018.txt for details
+ exit 1
[stack@localhost devstack]$

解决方法:
重复安装一些即可。

yum reinstall python-six