如何在Linux上安装和配置OpenStack Client

OpenStack客户端是OpenStack的命令行工具,它将计算,身份,映像,对象存储和块存储API的命令集组合到单个shell中,并提供了统一的命令结构。 OpenStack客户端允许您通过API调用通过网络与OpenStack服务进行交互。

此设置的前提条件是运行的OpenStack Cloud平台。有关文章说明,请参见《 OpenStack指南》。如果您是开发人员并且想贡献力量,那么您的代码将托管在OpenStack的Git服务器上。

步骤1:安装Python Pip工具

某些Linux发行版包含OpenStack命令行客户端的软件包版本,可以直接安装,但可以从Pip安装。从系统的软件包管理器中安装pip。

------------ Install pip on Debian / Ubuntu ----------
$ sudo apt-get -y update
$ sudo apt-get -y install python-dev python-pip
$ sudo pip install --upgrade pip

------------ Install pip on CentOS / RHEL ----------
$ sudo yum -y install python-devel python-pip
$ sudo pip install --upgrade pip

------------ Install pip on Arch / Manjaro ----------
$ sudo pacman -Syy
$ sudo pacman -S python-pip
$ sudo pip install --upgrade pip

--------- Install pip on macOS ----------------
$ sudo easy_install pip

检查已安装的pip版本。

$ pip --version
pip 19.1.1 from /usr/lib/python3.7/site-packages/pip (python 3.7)

步骤2:在Linux上安装OpenStack Client

安装Pip之后,请继续安装OpenStack命令行客户端。

sudo pip install python-openstackclient

显示有关已安装的Openstack命令行客户端的详细信息。

$ pip show python-openstackclient
Name: python-openstackclient
Version: 3.19.0
Summary: OpenStack Command-line Client
Home-page: https://docs.openstack.org/python-openstackclient/latest/
Author: OpenStack
Author-email: [email protected]
License: UNKNOWN
Location: /usr/lib/python3.7/site-packages
Requires: python-cinderclient, cliff, python-keystoneclient, keystoneauth1, python-novaclient, six, openstacksdk, oslo.i18n, python-glanceclient, osc-lib, pbr, Babel, oslo.utils
Required-by: 

一个必须为你 开栈 PATH命令。

$ which openstack
/usr/bin/openstack

步骤3:在Linux上配置OpenStack Client

从OpenStack Director获取OpenStack配置文件,或者如果您具有正确的访问凭据,则创建它。

$ nano ~/.keystonerc
unset OS_SERVICE_TOKEN
    export OS_USERNAME='admin'
    export OS_PASSWORD='adminpassword'
    export OS_AUTH_URL=http://192.168.100.10:5000/v3
    export PS1='[[email protected]h W(keystone_admin)]$ '
    
export OS_PROJECT_NAME=admin
export OS_USER_DOMAIN_NAME=Default
export OS_PROJECT_DOMAIN_NAME=Default
export OS_IDENTITY_API_VERSION=3

根据OpenStack环境更新变量。完成后,使用OpenStack命令行工具获取文件以管理OpenStack Cloud。

$ source ~/.keystonerc

Shell提示符更改为:

[[email protected]h W(keystone_admin)]$ 

运行openstack命令以验证其是否有效。

[[email protected]h W(keystone_admin)]$ openstack network list
+--------------------------------------+---------------------------+----------------------------------------------------------------------------+
| ID                                   | Name                      | Subnets                                                                    |
+--------------------------------------+---------------------------+----------------------------------------------------------------------------+
| 900b1ede-3e62-4d73-88d3-b28c129a6bb6 | public                    | c1770934-54bb-4252-928a-c7a41c6e114a                                       |
| da22131e-0b50-46e7-8d35-b18bbb161f1b | mycluster-lww6p-openshift | 6770ab86-2481-46e6-8d29-ab3c6a82b6cc, ec91b5c4-37fd-453f-be02-9ee8327654c2 |
| e406e76f-e89d-42a2-bab1-9c883b2e49aa | private                   | 76ff61dd-0438-4848-a611-f4b4de070164                                       |
+--------------------------------------+---------------------------+----------------------------------------------------------------------------+

$ openstack image list
+--------------------------------------+---------------------+--------+
| ID                                   | Name                | Status |
+--------------------------------------+---------------------+--------+
| 0850ee38-1bdf-4379-9c69-0cf73e8b7c65 | Arch-Linux-x86_64   | active |
| e98445b6-f14f-488c-a18a-1f66c6de15c7 | CentOS-7-x86_64     | active |
| 7b4b616e-71f3-4419-9777-7aee66fad62c | Cirros-0.4.0-x86_64 | active |
| 8514fea0-3d55-4248-a79f-5c0183f95898 | CoreOS-x86_64       | active |
| 98bbd9e6-abbc-45fa-ac95-b91b7b18ba0a | Debian-9-amd64      | active |
| 113b90b6-4e1e-4715-b9ab-456c191a82b3 | Fedora-30-x86_64    | active |
| 06c17e8a-0d4c-428a-89b5-b0eb2489f403 | Ubuntu-16.04-x86_64 | active |
| 2ba79fa6-2434-4dc6-ad86-0baf29d44c79 | rhcos               | active |
| c3bb11c7-81af-49fe-a26c-a60e9b14585c | rhcos-kvm           | active |
+--------------------------------------+---------------------+--------+

步骤4:启用OpenStack Bash完成

使用openstack complete命令生成bash完成脚本。

openstack complete | sudo tee /etc/bash_completion.d/osc.bash_completion > /dev/null

登出

$ logout
or
$ exit

然后再次登录并享受OpenStack bash的完成。

$ openstack network 
agent     create    flavor    log       meter     rbac      service   show      trunk     
auto      delete    list      loggable  qos       segment   set       subport   unset    

您学习了如何在Linux系统上安装和配置OpenStack客户端。

其他有趣的文章:

顶级开源云平台和解决方案

适用于初学者和专业人士的最佳Linux书籍

使用OpenStack命令行将图像添加到Glance

Sidebar