- A+
在OpenStack术语中,可用区(AZ)被定义为计算(nova),块存储(cinder)和网络服务(neutron)的逻辑分区。可用区域需要隔离生产和非生产等环境的工作负载,让我详细说明这一说法。
假设我们在OpenStack中有一个租户想要在生产和非生产中部署他们的VM,那么要在openstack中创建这种类型的设置,首先我们必须确定哪些计算将被视为生产和非生产然后我们有创建主机聚合组,我们将计算添加到主机聚合组,然后我们将主机聚合组映射到可用区。
在本教程中,我们将演示如何通过命令行在openstack中创建和使用计算可用区。
创建计算可用区域
无论何时部署OpenStack,Nova都是自动创建的默认可用区(AZ),并且所有计算节点都属于Nova AZ。从控制器节点运行以下openstack命令以列出可用区域,
〜#source openrc
~# source openrc ~# openstack availability zone list +-----------+-------------+ | Zone Name | Zone Status | +-----------+-------------+ | internal | available | | nova | available | | nova | available | | nova | available | +-----------+-------------+ ~#
要仅列出compute的可用区域,请运行下面的openstack命令,
~# openstack availability zone list --compute +-----------+-------------+ | Zone Name | Zone Status | +-----------+-------------+ | internal | available | | nova | available | +-----------+-------------+ ~#
要列出映射到nova可用区的所有计算主机,请执行以下命令,
~# openstack host list | grep -E "Zone|nova" | Host Name | Service | Zone | | compute-0-1 | compute | nova | | compute-0-2 | compute | nova | | compute-0-4 | compute | nova | | compute-0-3 | compute | nova | | compute-0-8 | compute | nova | | compute-0-6 | compute | nova | | compute-0-9 | compute | nova | | compute-0-5 | compute | nova | | compute-0-7 | compute | nova | ~#
让我们创建一个具有名称生成和非生产的两个主机聚合组,将compute-4,5和6添加到生产主机聚合组,将compute-7,8和9添加到非生产主机聚合组。
使用以下OpenStack命令创建生产和非生产主机聚合,
~# openstack aggregate create production +-------------------+----------------------------+ | Field | Value | +-------------------+----------------------------+ | availability_zone | None | | created_at | 2019-08-17T03:02:41.561259 | | deleted | False | | deleted_at | None | | id | 7 | | name | production | | updated_at | None | +-------------------+----------------------------+ ~# openstack aggregate create non-production +-------------------+----------------------------+ | Field | Value | +-------------------+----------------------------+ | availability_zone | None | | created_at | 2019-08-17T03:02:53.806713 | | deleted | False | | deleted_at | None | | id | 10 | | name | non-production | | updated_at | None | +-------------------+----------------------------+ ~#
现在创建可用区域并将其与其各自的主机聚合组相关联
句法:
#openstack aggregate set -zone <az_name> <host_aggregate_name>
~# openstack aggregate set --zone production-az production ~# openstack aggregate set --zone non-production-az non-production
最后将计算主机添加到其主机聚合组
句法:
#openstack aggregate add host <host_aggregate_name> <compute_host>
~# openstack aggregate add host production compute-0-4 ~# openstack aggregate add host production compute-0-5 ~# openstack aggregate add host production compute-0-6
同样将计算主机添加到非生产主机聚合组,
~# openstack aggregate add host non-production compute-0-7 ~# openstack aggregate add host non-production compute-0-8 ~# openstack aggregate add host non-production compute-0-9
执行下面的openstack命令以验证主机聚合组及其可用区域
~# openstack aggregate list +----+----------------+-------------------+ | ID | Name | Availability Zone | +----+----------------+-------------------+ | 7 | production | production-az | | 10 | non-production | non-production-az | +----+----------------+-------------------+ ~#
运行以下命令以列出与AZ和主机聚合组关联的计算
~# openstack aggregate show production +-------------------+--------------------------------------------+ | Field | Value | +-------------------+--------------------------------------------+ | availability_zone | production-az | | created_at | 2019-08-17T03:02:42.000000 | | deleted | False | | deleted_at | None | | hosts | [u'compute-0-4', u'compute-0-5', u'compute-0-6'] | | id | 7 | | name | production | | properties | | | updated_at | None | +-------------------+--------------------------------------------+ ~# openstack aggregate show non-production +-------------------+---------------------------------------------+ | Field | Value | +-------------------+---------------------------------------------+ | availability_zone | non-production-az | | created_at | 2019-08-17T03:02:54.000000 | | deleted | False | | deleted_at | None | | hosts | [u'compute-0-7', u'compute-0-8', u'compute-0-9'] | | id | 10 | | name | non-production | | properties | | | updated_at | None | +-------------------+---------------------------------------------+ ~#
以上命令的输出确认我们已成功创建主机聚合组和可用区。
在可用区中启动虚拟机
现在让我们在这两个可用区中创建几个虚拟机,在命令下使用特定可用区创建一个虚拟机,
句法:
#openstack server create -flavor <flavor-name> -image <Image-Name-Or-Image-ID> -nic net-id = <Network-ID> -security-group <Security-Group-ID> -key-name <Keypair-Name> -availability-zone <AZ-Name> <VM-Name>
示例如下所示:
~# openstack server create --flavor m1.small --image Cirros --nic net-id=37b9ab9a-f198-4db1-a5d6-5789b05bfb4c --security-group f8dda7c3-f7c3-423b-923a-2b21fe0bbf3c --key-name mykey --availability-zone production-az test-vm-prod-az
运行以下命令以验证虚拟机详细信息:
~# openstack server show test-vm-prod-az
要在可用区域下的特定计算节点中创建虚拟机,请使用以下命令,
句法:
#openstack server create -flavor <flavor-name> -image <Image-Name-Or-Image-ID> -nic net-id = <Network-ID> -security-group <Security-Group-ID> -key-name {Keypair-Name} -availability-zone <AZ-Name>:<Compute-Host> <VM-Name>
假设我们想在特定计算(compute-0-6)上的生产AZ下旋转vm,那么为了实现这一点,运行below命令,
~# openstack server create --flavor m1.small --image Cirros --nic net-id=37b9ab9a-f198-4db1-a5d6-5789b05bfb4c --security-group f8dda7c3-f7c3-423b-923a-2b21fe0bbf3c --key-name mykey --availability-zone production-az:compute-0-6 test-vm-prod-az-host
执行以下命令以验证VM详细信息:
~# openstack server show test-vm-prod-az-host
上面的命令输出如下所示:
同样,我们可以在非生产AZ中创建虚拟机,示例如下所示
~# openstack server create --flavor m1.small --image Cirros --nic net-id=37b9ab9a-f198-4db1-a5d6-5789b05bfb4c --security-group f8dda7c3-f7c3-423b-923a-2b21fe0bbf3c --key-name mykey --availability-zone non-production-az vm-nonprod-az
使用以下命令验证VM详细信息,
~# openstack server show vm-nonprod-az
上面命令的输出如下所示,
删除主机聚合组和可用区
假设我们要删除/删除上面创建的主机聚合组和可用区域,首先我们必须从主机聚合组中删除主机,使用下面的命令,
~# openstack aggregate show production
上面的命令将给出添加到生产主机聚合组的计算主机列表。
使用以下命令从主机聚合组中删除主机
句法:
#openstack aggregate remove host <host-aggregate-name> <compute-name>
~# openstack aggregate remove host production compute-0-4 ~# openstack aggregate remove host production compute-0-5 ~# openstack aggregate remove host production compute-0-6
从组中删除所有主机后,重新运行以下命令,
~# openstack aggregate show production +-------------------+----------------------------+ | Field | Value | +-------------------+----------------------------+ | availability_zone | production-az | | created_at | 2019-08-17T03:02:42.000000 | | deleted | False | | deleted_at | None | | hosts | [] | | id | 7 | | name | production | | properties | | | updated_at | None | +-------------------+----------------------------+ ~#
正如我们在上面的输出中看到的那样,没有与生产主机聚合组关联的计算主机,现在我们可以删除该组
使用以下命令删除主机聚合组及其关联的可用区
~# openstack aggregate delete production
运行以下命令以检查可用区是否已被删除,
~# openstack availability zone list | grep -i production-az ~#
同样,您可以参考上述步骤来删除或删除非生产主机聚合及其可用区。
- 安卓客户端下载
- 微信扫一扫
- 微信公众号
- 微信公众号扫一扫