在 centos7 上安装 OpenStack 的 watcher服务,前排提醒,在使用 watcherclient 的时候有坑,已经踩坑了! 另外介绍背景,环境里有两台控制节点,hostname为 controller(ubuntu16.04) 和 controller1(centos7)
下面是安装步骤
Step 1 创建数据库
登录数据库
mysql -u root -p
创建watcher数据库
CREATE DATABASE senlin DEFAULT CHARACTER SET utf8;
授权(替换 WATCHER_DBPASS
为合适的密码)
GRANT ALL PRIVILEGES ON watcher.* TO 'watcher'@'localhost' \
IDENTIFIED BY 'WATCHER_DBPASS';
GRANT ALL PRIVILEGES ON watcher.* TO 'watcher'@'%' \
IDENTIFIED BY 'WATCHER_DBPASS';
退出
exit;
Step 2 创建 watcher 用户
导入环境变量
. admin-openrc
创建用户,需输入两次密码
openstack user create --domain default --password-prompt watcher
Step 3 设置管理员角色
openstack role add --project service --user watcher admin
Step 4 创建 watcher 服务
openstack service create --name watcher --description "Infrastructure Optimization" infra-optim
Step 5 创建 API 终端
替换 controller
为你控制节点 hostname 或 ip
openstack endpoint create --region RegionOne \
infra-optim public http://controller:9322
openstack endpoint create --region RegionOne \
infra-optim internal http://controller:9322
openstack endpoint create --region RegionOne \
infra-optim admin http://controller:9322
Step 6 安装 watcher 软件包
yum install openstack-watcher-api openstack-watcher-applier \
openstack-watcher-decision-engine
Step 7 修改配置文件
注意,这个版本的centos包下,watcher.conf文件是空,只有开头一个[DEFAULT],不要慌,按照配置走下去
vim /etc/watcher/watcher.conf
[DEFAULT]
control_exchange = watcher
transport_url = rabbit://openstack:RABBIT_PASS@controller
[database]
connection = mysql+pymysql://watcher:WATCHER_DBPASS@controller/watcher?charset=utf8
[keystone_authtoken]
www_authenticate_uri = http://controller:5000
auth_url = http://controller:5000
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = watcher
password = WATCHER_PASS
[watcher_clients_auth]
auth_type = password
auth_url = http://controller:5000
username = watcher
password = WATCHER_PASS
project_domain_name = default
user_domain_name = default
project_name = service
[api]
host = controller
[oslo_messaging_notifications]
driver = messagingv2
Step 8 同步数据库
su -s /bin/sh -c "watcher-db-manage --config-file /etc/watcher/watcher.conf upgrade"
Step 10 开启 watcher 服务
systemctl enable openstack-watcher-api.service \
openstack-watcher-decision-engine.service \
openstack-watcher-applier.service
systemctl start openstack-watcher-api.service \
openstack-watcher-decision-engine.service \
openstack-watcher-applier.service
Step 10 验证安装
. admin-openrc
注意这里的 admin-openrc
文件
需要有以下项
export OS_PROJECT_DOMAIN_NAME=Default
export OS_USER_DOMAIN_NAME=Default
export OS_PROJECT_NAME=admin
export OS_USERNAME=admin
export OS_PASSWORD=PASS
export OS_AUTH_URL=http://controller:35357/v3
export OS_IDENTITY_API_VERSION=3
export OS_IMAGE_API_VERSION=2
export OS_AUTH_TYPE=password
重点来了
运行以下语句,并没有预期的输出,而是
[root@controller1 ~]# openstack optimize service list
openstack: 'optimize service list' is not an openstack command. See 'openstack --help'.
Did you mean one of these?
container create
container delete
container list
container save
container set
container show
container unset
而在另一台 ubuntu 的控制节点上安装 watcher,是有预期输出的,这是怎么回事?
对比官网安装文档,发现 ubuntu 的安装文档上,在安装 watcher 软件包的时候,多了这么一句
yum install openstack-watcher-api openstack-watcher-applier \
openstack-watcher-decision-engine
apt install watcher-api watcher-decision-engine \
watcher-applier
apt install python-watcherclient
对,yum 命令下的软件包没有安装 python-watcherclient
, 而这个 python-watcherclient
正是本文的关键!
先说一下这个 client
是什么,client
是 OpenStack
提供的用来在命令行操作 OpenStack
服务的客户端,我们之前安装的 python-openstackclient
中就包含了 novaclient
、neutronclient
等核心组件的客户端,而有些新组件的客户端是需要独立安装的,比如这个 python-watcherclient
。
回顾一下 centos 中 watcher 的软件包安装,发现其中安装了很多别的 client
,唯独少了这个 python-watcherclient
yum install openstack-watcher-api openstack-watcher-applier \
openstack-watcher-decision-engine
......(省略一段)
Dependencies Resolved
===============================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================
Installing:
openstack-watcher-api noarch 1.4.1-1.el7 centos-openstack-pike 8.1 k
openstack-watcher-applier noarch 1.4.1-1.el7 centos-openstack-pike 8.2 k
openstack-watcher-decision-engine noarch 1.4.1-1.el7 centos-openstack-pike 8.3 k
Installing for dependencies:
openstack-watcher-common noarch 1.4.1-1.el7 centos-openstack-pike 9.1 k
python-watcher noarch 1.4.1-1.el7 centos-openstack-pike 465 k
python2-ceilometerclient noarch 2.9.0-1.el7 centos-openstack-pike 102 k
python2-gnocchiclient noarch 3.3.1-1.el7 centos-openstack-pike 67 k
python2-ironicclient noarch 1.17.0-1.el7 centos-openstack-pike 381 k
python2-monascaclient noarch 1.7.1-1.el7 centos-openstack-pike 56 k
Transaction Summary
===============================================================================================================================
Install 3 Packages (+6 Dependent packages)
前面说到,在我的另一台 ubuntu 的控制节点上,执行诸如 openstack optimize service list
的指令,是有预期输出的,是因为在 ubuntu 上安装了 python-watcherclient
。那么要在 centos 上让 watcher 的命令行起作用,就需要在 centos 上安装 python-watcherclient
。
可是,centos 的 yum 的软件包里并没有 python-watcherclient
[root@controller1 ~]# yum search python-watcherclient
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.nwsuaf.edu.cn
* centos-qemu-ev: mirrors.163.com
* epel: ftp.jaist.ac.jp
* extras: mirrors.nwsuaf.edu.cn
* updates: mirrors.nwsuaf.edu.cn
Warning: No matches found for: python-watcherclient
No matches found
只剩一个办法,用 pip
安装。
Step 11 安装 python-watcherclient
像打游戏一样,我们来到了 boss 关,成功安装 python-watcherclient
就通关了。
可是 boss 不会让我们轻易通关的,而且一不小心,我们就死在这关了(来自一个死过的闯关者的经验)
首先我们要明白,如果使用 pip install xxx
,不指定版本的话,会安装最新版本的 xxx 软件,而当 xxx 软件有某些依赖包不满足版本条件的话,pip 为了成功安装 xxx,会把系统里低版本的依赖包删除掉,自动为你安装最新版本的依赖包。
在 OpenStack
中,若直接执行 pip install python-watcherclient
,会安装最新版本的 python-wacherclient
,这时 pip 会把 python-wacherclient
的依赖包升级,若升级的依赖包和当前 OpenStack 中的包有很多代码改动,可能会导致你的 OpenStack
环境运行不起来,这时候再去对应各种包版本就麻烦大了!
所以,我们要找到对应 Pike
版本的 python-watcherclient
。
但是,我们如何知道 Pike
版本的 python-watcherclient
在 pypi 中是什么版本呢?
我灵机一动,ubuntu的控制节点中不是安装了 python-watcherclient
吗,看一看不就行了?
于是到 ubuntu 的控制节点中,执行如下语句
root@controller:~# pip list | grep watcher
python-watcher (1.4.1)
python-watcherclient (1.3.0)
清楚了,是 1.3.0 版本,于是在 centos 的控制节点中愉快地运行
pip install python-watcherclient==1.3.0
安装过程一切顺利,但过程中一些提示让我隐隐不安:
Requirement already satisfied: keystoneauth1>=3.0.1 in /usr/lib/python2.7/site-packages (from python-watcherclient==1.3.0) (3.1.0)
......(省略部分)
Collecting openstacksdk>=0.15.0 (from osc-lib>=1.7.0->python-watcherclient==1.3.0)
Using cached https://files.pythonhosted.org/packages/f4/e9/a6c5edd61a4a0b6c3bf99126f6a8e4f04c7d62a7166c3d715ac02a74c2b3/openstacksdk-0.26.0-py2.py3-none-any.whl
......(省略部分)
openstacksdk 0.26.0 has requirement keystoneauth1>=3.11.0, but you'll have keystoneauth1 3.1.0 which is incompatible.
osc-lib 1.12.1 has requirement keystoneauth1>=3.7.0, but you'll have keystoneauth1 3.1.0 which is incompatible.
Installing collected packages: python-watcherclient, openstacksdk
Found existing installation: openstacksdk 0.9.17
Uninstalling openstacksdk-0.9.17:
Successfully uninstalled openstacksdk-0.9.17
Successfully installed openstacksdk-0.26.0 python-watcherclient-1.3.0
解释一下,当提示 Requirement already satisfied
时,是万事大吉的,不会改动原来的包版本,但提示 Collecting
的时候,就要注意了,pip 告诉我们原来版本的包不满足条件,要为我们下载最新的包了!
就比如这个 openstacksdk
,它需要的版本是 >=0.15.0
,原来的版本是 0.9.17
,pip 直接给我们更新到了 0.26.0
了!更新后,OpenStack
环境可能就有危险了!
我随便试了一个命令,果然 gg 了:
[root@controller1 ~]# . admin-openrc
[root@controller1 ~]# openstack compute service list
Traceback (most recent call last):
File "/usr/bin/openstack", line 6, in
from openstackclient.shell import main
File "/usr/lib/python2.7/site-packages/openstackclient/shell.py", line 29, in
from openstackclient.common import clientmanager
File "/usr/lib/python2.7/site-packages/openstackclient/common/clientmanager.py", line 166, in
'openstack.cli.base',
File "/usr/lib/python2.7/site-packages/openstackclient/common/clientmanager.py", line 137, in get_plugin_modules
__import__(ep.module_name)
File "/usr/lib/python2.7/site-packages/openstackclient/network/client.py", line 17, in
from openstack import profile
ImportError: cannot import name profile
看样子,就是因为这个 openstacksdk
版本更到最新导致的问题。
这时候,不要慌,去看一下隔壁节点的 openstacksdk
是什么版本的,来到 ubuntu 的控制节点,看一下版本
root@controller:~# pip list | grep openstacksdk
openstacksdk (0.17.0)
好的,那么我们在 centos 的控制节点利用 pip 改变 openstacksdk
的版本
pip install openstacksdk==0.17.0
完成后,再次试验一下普通的指令
[root@controller1 ~]# . admin-openrc
[root@controller1 ~]# openstack compute service list
+----+------------------+-----------------------+----------+----------+-------+----------------------------+
| ID | Binary | Host | Zone | Status | State | Updated At |
+----+------------------+-----------------------+----------+----------+-------+----------------------------+
| 3 | nova-consoleauth | controller | internal | enabled | up | 2019-03-20T05:19:40.000000 |
| 4 | nova-scheduler | controller | internal | enabled | up | 2019-03-20T05:19:41.000000 |
| 5 | nova-conductor | controller | internal | enabled | up | 2019-03-20T05:19:44.000000 |
| 9 | nova-compute | compute1 | nova | enabled | up | 2019-03-20T05:19:44.000000 |
没有问题!
用一下 watcher 的指令
[root@controller1 ~]# openstack optimize service list
+----+-------------------------+-------------+--------+
| ID | Name | Host | Status |
+----+-------------------------+-------------+--------+
| 1 | watcher-applier | controller | ACTIVE |
| 2 | watcher-decision-engine | controller | ACTIVE |
| 3 | watcher-applier | controller1 | ACTIVE |
| 4 | watcher-decision-engine | controller1 | ACTIVE |
+----+-------------------------+-------------+--------+
通关了!可以舒口气了
参考链接:
https://docs.openstack.org/watcher/pike/install/install-rdo.html
https://docs.openstack.org/watcher/pike/install/install-ubuntu.html
https://pypi.org/project/python-watcherclient/