[ English | 日本語 | Deutsch | Indonesia ]

Lay of the Land

本章节帮助您设置您的工作环境并使用它来了解您的云环境。

使用 OpenStack Dashboard 进行管理

作为云管理用户,您可以使用 OpenStack dashboard 来创建和管理项目、用户、镜像和规格。用户允许在指定项目内创建和管理镜像,并根据镜像服务的配置共享镜像。通常,策略配置仅允许管理员设置配额以及创建和管理服务。dashboard 提供一个 Admin 选项卡,其中包含 System Panel 和一个 Identity 选项卡。这些界面让您可以访问系统信息和使用情况,以及配置终端用户可以执行的操作的设置。有关作为管理员使用 dashboard 的详细操作信息,请参阅 Horizon Administration Guide

命令行工具

我们建议使用 OpenStack 命令行界面 (CLI) 工具和 OpenStack dashboard 的组合来进行管理。一些具有其他云技术背景的用户可能正在使用 EC2 兼容性 API,该 API 使用与原生 API 略有不同的命名约定。

pip 工具用于管理从 PyPI 档案中安装软件包,并且在大多数 Linux 发行版中的 python-pip 软件包中可用。虽然每个 OpenStack 项目都有自己的客户端,但它们正在被弃用,以支持通用的 OpenStack 客户端。通常建议安装 OpenStack 客户端。

安装 OpenStack 命令行客户端

有关安装、升级或删除命令行客户端的说明,请参阅 Install the OpenStack command-line client

注意

如果您的云支持 EC2 API,您还应该安装 euca2ools 软件包或其他 EC2 API 工具,以便您可以获得与您的用户相同的视图。使用基于 EC2 API 的工具超出了本指南的范围,尽管我们讨论了获取用于使用的凭据。

管理命令行工具

还有几个 *-manage 命令行工具。这些工具与云控制器的项目服务一起安装,无需单独安装

  • nova-manage

  • glance-manage

  • keystone-manage

  • cinder-manage

与上述 CLI 工具不同,*-manage 工具必须以 root 用户身份从云控制器运行,因为它们需要读取访问权限才能访问配置文件,例如 /etc/nova/nova.conf,并且需要直接对数据库进行查询,而不是对 OpenStack API endpoints 进行查询。

警告

存在 *-manage 工具是一个遗留问题。OpenStack 项目的目标是最终将 *-manage 工具中剩余的所有功能迁移到基于 API 的工具中。在此之前,您需要 SSH 到 cloud controller node 以执行需要其中一个 *-manage 工具的某些维护操作。

获取凭据

如果您想使用命令行工具对您的 OpenStack 云进行查询,您必须拥有适当的凭据。迄今为止,获得 authentication 凭据以与命令行客户端一起使用的最简单方法是使用 OpenStack dashboard。选择 Project,单击 Project 选项卡,然后单击 Compute 类别中的 Access & Security。在 Access & Security 页面上,单击 API Access 选项卡以显示两个按钮,Download OpenStack RC FileDownload EC2 Credentials,它们让您可以生成可以在 shell 中使用的文件,以填充命令行工具需要知道的服务端点和身份验证信息的环境变量。您登录到 dashboard 的用户决定 openrc 文件的文件名,例如 demo-openrc.sh。以管理员身份登录时,文件名为 admin-openrc.sh

生成的文件如下所示

#!/usr/bin/env bash

# To use an OpenStack cloud you need to authenticate against the Identity
# service named keystone, which returns a **Token** and **Service Catalog**.
# The catalog contains the endpoints for all services the user/tenant has
# access to - such as Compute, Image Service, Identity, Object Storage, Block
# Storage, and Networking (code-named nova, glance, keystone, swift,
# cinder, and neutron).
#
# *NOTE*: Using the 3 *Identity API* does not necessarily mean any other
# OpenStack API is version 3. For example, your cloud provider may implement
# Image API v1.1, Block Storage API v2, and Compute API v2.0. OS_AUTH_URL is
# only for the Identity API served through keystone.
export OS_AUTH_URL=http://203.0.113.10:5000/v3

# With the addition of Keystone we have standardized on the term **project**
# as the entity that owns the resources.
export OS_PROJECT_ID=98333aba48e756fa8f629c83a818ad57
export OS_PROJECT_NAME="test-project"
export OS_USER_DOMAIN_NAME="default"
if [ -z "$OS_USER_DOMAIN_NAME" ]; then unset OS_USER_DOMAIN_NAME; fi

# In addition to the owning entity (tenant), OpenStack stores the entity
# performing the action as the **user**.
export OS_USERNAME="demo"

# With Keystone you pass the keystone password.
echo "Please enter your OpenStack Password for project $OS_PROJECT_NAME as user $OS_USERNAME: "
read -sr OS_PASSWORD_INPUT
export OS_PASSWORD=$OS_PASSWORD_INPUT

# If your configuration has multiple regions, we set that information here.
# OS_REGION_NAME is optional and only valid in certain environments.
export OS_REGION_NAME="RegionOne"
# Don't leave a blank variable, unset it if it was empty
if [ -z "$OS_REGION_NAME" ]; then unset OS_REGION_NAME; fi

export OS_INTERFACE=public
export OS_IDENTITY_API_VERSION=3

警告

这不会以明文保存您的密码,这是一件好事。但是,当您 source 或运行脚本时,它会提示您输入密码,然后将您的响应存储在环境变量 OS_PASSWORD 中。重要的是要注意,这需要交互。如果您需要非交互式操作,可以将值直接存储在脚本中,但您需要格外小心此文件的安全性和权限。

可以通过选择 Project,然后 Compute,然后 Access & Security,然后 API Access 来显示 Download EC2 Credentials 按钮来下载 EC2 兼容性凭据。单击该按钮以生成包含服务器 x509 证书和 shell 脚本片段的 ZIP 文件。在安全的位置创建一个新目录,因为这些是实时凭据,包含访问您的云身份所需的所有身份验证信息,与默认的 user-openrc 不同。在此处提取 ZIP 文件。您应该有 cacert.pemcert.pemec2rc.shpk.pemec2rc.sh 类似于以下内容

#!/bin/bash

NOVARC=$(readlink -f "${BASH_SOURCE:-${0}}" 2>/dev/null) ||\
NOVARC=$(python -c 'import os,sys; \
print os.path.abspath(os.path.realpath(sys.argv[1]))' "${BASH_SOURCE:-${0}}")
NOVA_KEY_DIR=${NOVARC%/*}
export EC2_ACCESS_KEY=df7f93ec47e84ef8a347bbb3d598449a
export EC2_SECRET_KEY=ead2fff9f8a344e489956deacd47e818
export EC2_URL=http://203.0.113.10:8773/services/Cloud
export EC2_USER_ID=42 # nova does not use user id, but bundling requires it
export EC2_PRIVATE_KEY=${NOVA_KEY_DIR}/pk.pem
export EC2_CERT=${NOVA_KEY_DIR}/cert.pem
export NOVA_CERT=${NOVA_KEY_DIR}/cacert.pem
export EUCALYPTUS_CERT=${NOVA_CERT} # euca-bundle-image seems to require this

alias ec2-bundle-image="ec2-bundle-image --cert $EC2_CERT --privatekey \
$EC2_PRIVATE_KEY --user 42 --ec2cert $NOVA_CERT"
alias ec2-upload-bundle="ec2-upload-bundle -a $EC2_ACCESS_KEY -s \
$EC2_SECRET_KEY --url $S3_URL --ec2cert $NOVA_CERT"

要将 EC2 凭据放入您的环境中,请 source ec2rc.sh 文件。

检查 API 调用

可以通过将 --debug 标志传递给它们来使命令行工具显示它们发出的 OpenStack API 调用。例如

# openstack --debug server list

此示例显示来自客户端的 HTTP 请求和来自端点的响应,这对于创建使用 OpenStack API 的自定义工具很有帮助。

使用 cURL 进行进一步检查

在命令行工具的使用背后是 OpenStack API,它是一个通过 HTTP 运行的 RESTful API。在某些情况下,您可能想直接与 API 交互,或者由于其中一个 CLI 工具中的 suspected 错误而需要使用它。最好的方法是使用 cURL 和另一个工具(例如 jq)的组合来解析响应中的 JSON。

首先,您必须使用您的凭据对云进行身份验证才能获取 authentication token

您的凭据是用户名、密码和租户(项目)的组合。您可以从上述 openrc.sh 中提取这些值。令牌允许您在无需为每个请求重新进行身份验证的情况下与您的其他服务端点交互。令牌通常有效 24 小时,并且当令牌过期时,您会收到 401(Unauthorized)响应,并且可以请求另一个令牌。

  1. 查看您的 OpenStack 服务 catalog

    $ curl -s -X POST http://203.0.113.10:35357/v2.0/tokens \
      -d '{"auth": {"passwordCredentials": {"username":"test-user", "password":"test-password"}, "tenantName":"test-project"}}' \
      -H "Content-type: application/json" | jq .
    
  2. 通读 JSON 响应,以了解目录的布局方式。

    为了使后续请求的工作更容易,请将令牌存储在环境变量中

    $ TOKEN=`curl -s -X POST http://203.0.113.10:35357/v2.0/tokens \
      -d '{"auth": {"passwordCredentials": {"username":"test-user", "password":"test-password"}, "tenantName":"test-project"}}' \
      -H "Content-type: application/json" |  jq -r .access.token.id`
    

    现在,您可以在命令行中将您的令牌引用为 $TOKEN

  3. 从您的服务目录中选择一个服务端点,例如 compute。尝试一个请求,例如列出实例(服务器)

    $ curl -s \
      -H "X-Auth-Token: $TOKEN" \
      http://203.0.113.10:8774/v2.0/98333aba48e756fa8f629c83a818ad57/servers | jq .
    

要了解 API 请求应该如何构建,请阅读 OpenStack API Reference。要使用 jq 处理响应,请参阅 jq Manual

在上面的 cURL 命令中使用的 -s flag 用于防止显示进度条。如果您在运行 cURL 命令时遇到问题,您需要删除它。同样,为了帮助您排除 cURL 命令的故障,您可以包含 -v 标志以向您显示详细输出。cURL 中还有许多其他非常有用的功能;请参阅 man 页面以获取所有选项。

服务器和服务

作为管理员,您可以通过使用 OpenStack 可用的工具来发现您的 OpenStack 云的外观。本节向您介绍如何获取云的概述、其形状、大小和当前状态。

首先,您可以通过运行以下命令来发现属于您的 OpenStack 云的服务器

# openstack compute service list --long

输出如下所示

+----+------------------+-------------------+------+---------+-------+----------------------------+-----------------+
| Id | Binary           | Host              | Zone | Status  | State | Updated_at                 | Disabled Reason |
+----+------------------+-------------------+------+---------+-------+----------------------------+-----------------+
| 1  | nova-cert        | cloud.example.com | nova | enabled | up    | 2016-01-05T17:20:38.000000 | -               |
| 2  | nova-compute     | c01.example.com   | nova | enabled | up    | 2016-01-05T17:20:38.000000 | -               |
| 3  | nova-compute     | c01.example.com.  | nova | enabled | up    | 2016-01-05T17:20:38.000000 | -               |
| 4  | nova-compute     | c01.example.com   | nova | enabled | up    | 2016-01-05T17:20:38.000000 | -               |
| 5  | nova-compute     | c01.example.com   | nova | enabled | up    | 2016-01-05T17:20:38.000000 | -               |
| 6  | nova-compute     | c01.example.com   | nova | enabled | up    | 2016-01-05T17:20:38.000000 | -               |
| 7  | nova-conductor   | cloud.example.com | nova | enabled | up    | 2016-01-05T17:20:38.000000 | -               |
| 8  | nova-cert        | cloud.example.com | nova | enabled | up    | 2016-01-05T17:20:42.000000 | -               |
| 9  | nova-scheduler   | cloud.example.com | nova | enabled | up    | 2016-01-05T17:20:38.000000 | -               |
| 10 | nova-consoleauth | cloud.example.com | nova | enabled | up    | 2016-01-05T17:20:35.000000 | -               |
+----+------------------+-------------------+------+---------+-------+----------------------------+-----------------+

输出显示有五个计算节点和一个云控制器。您看到所有服务都处于 up 状态,这表明服务正在运行。如果服务处于 down 状态,则它不再可用。这是您应该排除服务停止运行原因的指示。

如果您正在使用 cinder,请运行以下命令以查看类似的列表

# cinder-manage host list | sort
host              zone
c01.example.com   nova
c02.example.com   nova
c03.example.com   nova
c04.example.com   nova
c05.example.com   nova
cloud.example.com nova

有了这两个表,您现在就可以很好地了解构成您的云的服务器和服务。

您还可以使用 Identity 服务 (keystone) 查看您的云中可用的服务以及为这些服务配置的端点。

以下命令要求您将 shell 环境配置为正确的管理变量

$ openstack catalog list
+----------+------------+---------------------------------------------------------------------------------+
| Name     | Type       | Endpoints                                                                       |
+----------+------------+---------------------------------------------------------------------------------+
| nova     | compute    | RegionOne                                                                       |
|          |            |   public: http://192.168.122.10:8774/v2/9faa845768224258808fc17a1bb27e5e        |
|          |            | RegionOne                                                                       |
|          |            |   internal: http://192.168.122.10:8774/v2/9faa845768224258808fc17a1bb27e5e      |
|          |            | RegionOne                                                                       |
|          |            |   admin: http://192.168.122.10:8774/v2/9faa845768224258808fc17a1bb27e5e         |
|          |            |                                                                                 |
| cinderv2 | volumev2   | RegionOne                                                                       |
|          |            |   public: http://192.168.122.10:8776/v2/9faa845768224258808fc17a1bb27e5e        |
|          |            | RegionOne                                                                       |
|          |            |   internal: http://192.168.122.10:8776/v2/9faa845768224258808fc17a1bb27e5e      |
|          |            | RegionOne                                                                       |
|          |            |   admin: http://192.168.122.10:8776/v2/9faa845768224258808fc17a1bb27e5e         |
|          |            |                                                                                 |

前面的输出已被截断以仅显示两个服务。您将为您的云提供的每个服务看到一个服务条目。请注意,端点域可能因端点类型而异。不同类型的端点域不是必需的,但可以出于各种原因进行操作,例如端点隐私或网络流量隔离。

您可以使用 OpenStack 命令行客户端找到 Compute 安装的版本

# openstack --version

诊断您的计算节点

您可以通过使用服务器 ID 运行 nova diagnostics 命令来获取有关正在运行的虚拟机的额外信息——它们的 CPU 使用率、内存、磁盘 I/O 或网络 I/O。

$ nova diagnostics <serverID>

此命令的输出因超visor 而异,因为超visor 支持不同的属性。以下演示了两种最流行的超visor 之间的差异。以下是当超visor 为 Xen 时的示例输出

+----------------+-----------------+
|    Property    |      Value      |
+----------------+-----------------+
| cpu0           | 4.3627          |
| memory         | 1171088064.0000 |
| memory_target  | 1171088064.0000 |
| vbd_xvda_read  | 0.0             |
| vbd_xvda_write | 0.0             |
| vif_0_rx       | 3223.6870       |
| vif_0_tx       | 0.0             |
| vif_1_rx       | 104.4955        |
| vif_1_tx       | 0.0             |
+----------------+-----------------+

虽然该命令应适用于通过 libvirt(KVM、QEMU 或 LXC)控制的任何超visor,但它仅使用 KVM 进行测试。以下是当超visor 为 KVM 时的示例输出

+------------------+------------+
| Property         | Value      |
+------------------+------------+
| cpu0_time        | 2870000000 |
| memory           | 524288     |
| vda_errors       | -1         |
| vda_read         | 262144     |
| vda_read_req     | 112        |
| vda_write        | 5606400    |
| vda_write_req    | 376        |
| vnet0_rx         | 63343      |
| vnet0_rx_drop    | 0          |
| vnet0_rx_errors  | 0          |
| vnet0_rx_packets | 431        |
| vnet0_tx         | 4905       |
| vnet0_tx_drop    | 0          |
| vnet0_tx_errors  | 0          |
| vnet0_tx_packets | 45         |
+------------------+------------+

网络检查

要查看您的云中配置的固定 IP 网络,您可以使用 openstack 命令行客户端来获取 IP 范围

$ openstack subnet list
+--------------------------------------+----------------+--------------------------------------+-----------------+
| ID                                   | Name           | Network                              | Subnet          |
+--------------------------------------+----------------+--------------------------------------+-----------------+
| 346806ee-a53e-44fd-968a-ddb2bcd2ba96 | public_subnet  | 0bf90de6-fc0f-4dba-b80d-96670dfb331a | 172.24.4.224/28 |
| f939a1e4-3dc3-4540-a9f6-053e6f04918f | private_subnet | 1f7f429e-c38e-47ba-8acf-c44e3f5e8d71 | 10.0.0.0/24     |
+--------------------------------------+----------------+--------------------------------------+-----------------+

OpenStack 命令行客户端可以提供一些其他详细信息

# openstack compute service list
+----+------------------+------------+----------+---------+-------+----------------------------+
| Id | Binary           | Host       | Zone     | Status  | State | Updated At                 |
+----+------------------+------------+----------+---------+-------+----------------------------+
|  1 | nova-consoleauth | controller | internal | enabled | up    | 2016-08-18T12:16:53.000000 |
|  2 | nova-scheduler   | controller | internal | enabled | up    | 2016-08-18T12:16:59.000000 |
|  3 | nova-conductor   | controller | internal | enabled | up    | 2016-08-18T12:16:52.000000 |
|  7 | nova-compute     | controller | nova     | enabled | up    | 2016-08-18T12:16:58.000000 |
+----+------------------+------------+----------+---------+-------+----------------------------+

此输出显示配置了两个网络,每个网络包含 255 个 IP(/24 子网)。第一个网络已分配给某个项目,而第二个网络仍然开放分配。您可以手动分配此网络;否则,它会在项目启动其第一个实例时自动分配。

要确定您的云中是否有可用的浮动 IP,请运行

# openstack floating ip list
+--------------------------------------+---------------------+------------------+--------------------------------------+
| ID                                   | Floating IP Address | Fixed IP Address | Port                                 |
+--------------------------------------+---------------------+------------------+--------------------------------------+
| 340cb36d-6a52-4091-b256-97b6e61cbb20 | 172.24.4.227        | 10.2.1.8         | 1fec8fb8-7a8c-44c2-acd8-f10e2e6cd326 |
| 8b1bfc0c-7a91-4da0-b3cc-4acae26cbdec | 172.24.4.228        | None             | None                                 |
+--------------------------------------+---------------------+------------------+--------------------------------------+

这里有两个浮动 IP 可用。第一个已分配给某个项目,而另一个未分配。

用户和项目

要查看添加到云中的项目列表,请运行

$ openstack project list
+----------------------------------+--------------------+
| ID                               | Name               |
+----------------------------------+--------------------+
| 422c17c0b26f4fbe9449f37a5621a5e6 | alt_demo           |
| 5dc65773519248f3a580cfe28ba7fa3f | demo               |
| 9faa845768224258808fc17a1bb27e5e | admin              |
| a733070a420c4b509784d7ea8f6884f7 | invisible_to_admin |
| aeb3e976e7794f3f89e4a7965db46c1e | service            |
+----------------------------------+--------------------+

要查看用户列表,请运行

$ openstack user list
+----------------------------------+----------+
| ID                               | Name     |
+----------------------------------+----------+
| 5837063598694771aedd66aa4cddf0b8 | demo     |
| 58efd9d852b74b87acc6efafaf31b30e | cinder   |
| 6845d995a57a441f890abc8f55da8dfb | glance   |
| ac2d15a1205f46d4837d5336cd4c5f5a | alt_demo |
| d8f593c3ae2b47289221f17a776a218b | admin    |
| d959ec0a99e24df0b7cb106ff940df20 | nova     |
+----------------------------------+----------+

注意

有时用户和组之间存在一对一映射。当标准系统帐户(例如 cinder、glance、nova 和 swift)或只有一名用户是组成员时,会发生这种情况。

正在运行的实例

要查看正在运行的实例列表,请运行

$ openstack server list --all-projects
+--------------------------------------+------+--------+---------------------+------------+
| ID                                   | Name | Status | Networks            | Image Name |
+--------------------------------------+------+--------+---------------------+------------+
| 495b4f5e-0b12-4c5a-b4e0-4326dee17a5a | vm1  | ACTIVE | public=172.24.4.232 | cirros     |
| e83686f9-16e8-45e6-911d-48f75cb8c0fb | vm2  | ACTIVE | private=10.0.0.7    | cirros     |
+--------------------------------------+------+--------+---------------------+------------+

不幸的是,此命令无法告诉您有关正在运行的实例的各种详细信息,例如实例运行的计算节点、实例使用的规格等。您可以使用以下命令查看单个实例的详细信息

$ openstack server show <uuid>

例如

# openstack server show 81db556b-8aa5-427d-a95c-2a9a6972f630
+--------------------------------------+----------------------------------------------------------+
| Field                                | Value                                                    |
+--------------------------------------+----------------------------------------------------------+
| OS-DCF:diskConfig                    | AUTO                                                     |
| OS-EXT-AZ:availability_zone          | nova                                                     |
| OS-EXT-SRV-ATTR:host                 | c02.example.com                                          |
| OS-EXT-SRV-ATTR:hypervisor_hostname  | c02.example.com                                          |
| OS-EXT-SRV-ATTR:instance_name        | instance-00000001                                        |
| OS-EXT-STS:power_state               | Running                                                  |
| OS-EXT-STS:task_state                | None                                                     |
| OS-EXT-STS:vm_state                  | active                                                   |
| OS-SRV-USG:launched_at               | 2016-10-19T15:18:09.000000                               |
| OS-SRV-USG:terminated_at             | None                                                     |
| accessIPv4                           |                                                          |
| accessIPv6                           |                                                          |
| addresses                            | private=10.0.0.7                                         |
| config_drive                         |                                                          |
| created                              | 2016-10-19T15:17:46Z                                     |
| flavor                               | m1.tiny (1)                                              |
| hostId                               | 2b57e2b7a839508337fb55695b8f6e65aa881460a20449a76352040b |
| id                                   | e83686f9-16e8-45e6-911d-48f75cb8c0fb                     |
| image                                | cirros (9fef3b2d-c35d-4b61-bea8-09cc6dc41829)            |
| key_name                             | None                                                     |
| name                                 | test                                                     |
| os-extended-volumes:volumes_attached | []                                                       |
| progress                             | 0                                                        |
| project_id                           | 1eaaf6ede7a24e78859591444abf314a                         |
| properties                           |                                                          |
| security_groups                      | [{u'name': u'default'}]                                  |
| status                               | ACTIVE                                                   |
| updated                              | 2016-10-19T15:18:58Z                                     |
| user_id                              | 7aaa9b5573ce441b98dae857a82ecc68                         |
+--------------------------------------+----------------------------------------------------------+

此输出显示名为 instance-00000001 的实例是从 cirros 镜像使用 m1.small 规格创建的,并托管在计算节点 c02.example.com 上。

摘要

我们希望您喜欢对您的工作环境的快速游览,包括如何与您的云交互以及提取有用的信息。从这里,您可以将 OpenStack Administrator Guide 作为您云中所有命令行功能的参考。