1. 背景说明

   openstack设计时的宗旨是能够为企业提供大规模的云计算服务,包括计算,存储,网络等资源,以服务的形式交付给用户,在一个非常大的环境中,需要将openstack的资源划分,openstack nova支持三种划分的方式:Region区域,Zone空间和Aggregate分组,其中Region是指一个地区或者地域,如可以将中国划分为:华南地区,华中地区,东北地区,西南地区;Zone则可以按照机房的形式来划分,如北京兆维机房为一个Zone,北京鲁谷机房为另外一个Zone;Aggreate粒度则更细,如按照同个机房中的不同机柜来划分。

概念说明

1. Region,更像是一个地理上的概念,每个region有自己独立的endpoint,regions之间完全隔离,但是多个regions之间共享同一个keystone和dashboard,region的设计更多侧重地理位置的概念,用户可以选择离自己更近的region来部署自己的服务。

2. Zone,即 Availability Zone,AZ可以简单理解为一组节点的集合,这组节点具有独立的电力供应设备,比如一个个独立供电的机房,一个个独立供电的机架都可以被划分成AZ。所以,AZ主要是通过冗余来解决可用性问题,Zone的目的主要是,保障用户在创建instance的时候可以选择创建到哪些AZ中,以保证instance的可用性。

3. Host Aggregate AZ是一个面向用户的概念和能力,而host aggregate是管理员用来根据硬件资源的某一属性来对硬件进行划分的功能,只对管理员可见,主要用来给nova-scheduler通过某一属性来进行instance的调度。其主要功能就是实现根据某一属性来划分物理机,比如按照地理位置,使用固态硬盘的机器,内存超过32G的机器,根据这些指标来构成一个host group。

2. 具体实现

   因为规模的因素和设计的因素,此处只演示同个机房的Aggreate的划分,其中Aggreate需要配合Zone一起使用,否则没法实现

1. 创建Zone和Aggreate

[root@controller ~]# nova aggregate-create HappyLabZone1 HappyAggreate1
+----+---------------+-------------------+-------+------------------------------------+
| Id | Name          | Availability Zone | Hosts | Metadata                           |
+----+---------------+-------------------+-------+------------------------------------+
| 11 | HappyLabZone1 | HappyAggreate1    |       | 'availability_zone=HappyAggreate1' |
+----+---------------+-------------------+-------+------------------------------------+

2. 查看aggreate列表

[root@controller ~]# nova aggregate-list
+----+-------------------+-------------------+
| Id | Name              | Availability Zone |
+----+-------------------+-------------------+
| 5  | ChuangYiYuanZone1 | ChuangYiYuanZone1 |
| 11 | HappyLabZone1     | HappyAggreate1    |        #Zone和Aggreate关联一起了
+----+-------------------+-------------------+

3. 将compute节点加入到Aggreate内

[root@controller ~]# nova aggregate-add-host HappyLabZone1 ChuangYiYuan_10_16_2_19        #添加一台compute节点
Host ChuangYiYuan_10_16_2_19 has been successfully added for aggregate 11 
+----+---------------+-------------------+---------------------------+------------------------------------+
| Id | Name          | Availability Zone | Hosts                     | Metadata                           |
+----+---------------+-------------------+---------------------------+------------------------------------+
| 11 | HappyLabZone1 | HappyAggreate1    | 'ChuangYiYuan_10_16_2_19' | 'availability_zone=HappyAggreate1' |
+----+---------------+-------------------+---------------------------+------------------------------------+
[root@controller ~]# nova aggregate-add-host HappyLabZone1 ChuangYiYuan_10_16_2_20        #添加另外一台compute节点
Host ChuangYiYuan_10_16_2_20 has been successfully added for aggregate 11 
+----+---------------+-------------------+------------------------------------------------------+------------------------------------+
| Id | Name          | Availability Zone | Hosts                                                | Metadata                           |
+----+---------------+-------------------+------------------------------------------------------+------------------------------------+
| 11 | HappyLabZone1 | HappyAggreate1    | 'ChuangYiYuan_10_16_2_19', 'ChuangYiYuan_10_16_2_20' | 'availability_zone=HappyAggreate1' |
+----+---------------+-------------------+------------------------------------------------------+------------------------------------+
[root@controller ~]# nova aggregate-add-host HappyLabZone1 ChuangYiYuan_10_16_2_21        #添加另外一台compute节点
Host ChuangYiYuan_10_16_2_21 has been successfully added for aggregate 11 
+----+---------------+-------------------+---------------------------------------------------------------------------------+------------------------------------+
| Id | Name          | Availability Zone | Hosts                                                                           | Metadata                           |
+----+---------------+-------------------+---------------------------------------------------------------------------------+------------------------------------+
| 11 | HappyLabZone1 | HappyAggreate1    | 'ChuangYiYuan_10_16_2_19', 'ChuangYiYuan_10_16_2_20', 'ChuangYiYuan_10_16_2_21' | 'availability_zone=HappyAggreate1' |
+----+---------------+-------------------+---------------------------------------------------------------------------------+------------------------------------+

4. 查看aggreate的详细信息

[root@controller ~]# nova aggregate-details HappyLabZone1
+----+---------------+-------------------+---------------------------------------------------------------------------------+------------------------------------+
| Id | Name          | Availability Zone | Hosts                                                                           | Metadata                           |
+----+---------------+-------------------+---------------------------------------------------------------------------------+------------------------------------+
| 11 | HappyLabZone1 | HappyAggreate1    | 'ChuangYiYuan_10_16_2_19', 'ChuangYiYuan_10_16_2_20', 'ChuangYiYuan_10_16_2_21' | 'availability_zone=HappyAggreate1' |
+----+---------------+-------------------+---------------------------------------------------------------------------------+------------------------------------+
#已经添加了3台compute节点,在dashboard中,也能够正常显示

5.nova list查看划分情况

[root@controller ~]# nova service-list
+------------------+-------------------------+-------------------+---------+-------+----------------------------+-----------------+
| Binary           | Host                    | Zone              | Status  | State | Updated_at                 | Disabled Reason |
+------------------+-------------------------+-------------------+---------+-------+----------------------------+-----------------+
| nova-conductor   | ChuangYiYuan_10_16_2_8  | internal          | enabled | up    | 2016-01-27T06:06:05.000000 | -               |
| nova-cert        | ChuangYiYuan_10_16_2_8  | internal          | enabled | up    | 2016-01-27T06:06:10.000000 | -               |
| nova-consoleauth | ChuangYiYuan_10_16_2_8  | internal          | enabled | up    | 2016-01-27T06:06:06.000000 | -               |
| nova-scheduler   | ChuangYiYuan_10_16_2_8  | internal          | enabled | up    | 2016-01-27T06:06:09.000000 | -               |
| nova-compute     | ChuangYiYuan_10_16_2_11 | ChuangYiYuanZone1 | enabled | up    | 2016-01-27T06:06:11.000000 | -               |
| nova-compute     | ChuangYiYuan_10_16_2_14 | ChuangYiYuanZone1 | enabled | up    | 2016-01-27T06:06:12.000000 | -               |
| nova-compute     | ChuangYiYuan_10_16_2_13 | ChuangYiYuanZone1 | enabled | up    | 2016-01-27T06:06:13.000000 | -               |
| nova-compute     | ChuangYiYuan_10_16_2_12 | ChuangYiYuanZone1 | enabled | up    | 2016-01-27T06:06:05.000000 | -               | #新添加的aggregate组
| nova-compute     | ChuangYiYuan_10_16_2_19 | HappyAggreate1    | enabled | up    | 2016-01-27T06:06:05.000000 | -               |
| nova-compute     | ChuangYiYuan_10_16_2_20 | HappyAggreate1    | enabled | up    | 2016-01-27T06:06:04.000000 | -               |
| nova-compute     | ChuangYiYuan_10_16_2_21 | HappyAggreate1    | enabled | up    | 2016-01-27T06:06:08.000000 | -               |
+------------------+-------------------------+-------------------+---------+-------+----------------------------+-----------------+
#至此,host aggregate配置完毕,后续扩容时,可以根据批次配置在不通的zone

3. 带来的好处

   aggregate的分组带来的好处是,nova支持availablily zone级别的调度,即创建vm的时候,能够指定zone,指定zone之后,instance将会在指定的zone中选择合适的compute nodes来启动虚拟机,openstack默认安装完之后,只有一个nova的zone。效果如下:

[root@controller ~]# nova boot --name  --flavor 1 --p_w_picpath db5fbfb7-bb14-4691-96dc-ba25531f4442 --key-name KEY  --availability-zone  HappyLabZone1 --security-groups  404af9b8-faa2-43df-aba8-24f17b40c17e  --nic net-id=182d2632-4373-47ff-b3a6-d50f116b76a7 vm_test_for_zone_and_aggregate

页面效果:

openstack运维实战系列(十二)之nova aggregate资源分组_第1张图片

创建VM的时候可以选择:

openstack运维实战系列(十二)之nova aggregate资源分组_第2张图片

4.aggreate的删除

[root@controller ~]# nova aggregate-list            #获取aggregate的ID号码
+----+-------------------+-------------------+
| Id | Name              | Availability Zone |
+----+-------------------+-------------------+
| 5  | ChuangYiYuanZone1 | ChuangYiYuanZone1 |
| 11 | HappyLabZone1     | HappyAggreate1    |      #id号是11
+----+-------------------+-------------------+

[root@controller ~]# nova aggregate-remove-host 11  ChuangYiYuan_10_16_2_21       #将主机从aggregate中删除,其他的compute节点,相同的方法执行         
Host ChuangYiYuan_10_16_2_21 has been successfully removed from aggregate 11 
+----+---------------+-------------------+------------------------------------------------------+------------------------------------+
| Id | Name          | Availability Zone | Hosts                                                | Metadata                           |
+----+---------------+-------------------+------------------------------------------------------+------------------------------------+
| 11 | HappyLabZone1 | HappyAggreate1    | 'ChuangYiYuan_10_16_2_19', 'ChuangYiYuan_10_16_2_20' | 'availability_zone=HappyAggreate1' |
+----+---------------+-------------------+------------------------------------------------------+------------------------------------+

查看详情:
[root@controller ~]# nova aggregate-details  11   
+----+---------------+-------------------+-------+------------------------------------+
| Id | Name          | Availability Zone | Hosts | Metadata                           |
+----+---------------+-------------------+-------+------------------------------------+
| 11 | HappyLabZone1 | HappyAggreate1    |       | 'availability_zone=HappyAggreate1' |    #已经没有compute节点
+----+---------------+-------------------+-------+------------------------------------+

将aggregate删除
[root@controller ~]# nova aggregate-delete HappyLabZone1
Aggregate 11 has been successfully deleted.


5. 总结

  openstack中的region,zone,host aggregate的实现里,其中region相对比较复杂,所有的的资源共享一个dashboard和keystone。关于具体实现,参考官方文档。


6. 附录

  nova aggregate实现的几个命令

[root@controller ~]# nova -h |grep aggregate
    aggregate-add-host  Add the host to the specified aggregate.           #添加主机         
    aggregate-create    Create a new aggregate with the specified details.   #创建分组
    aggregate-delete    Delete the aggregate.                                #删除分组
    aggregate-details   Show details of the specified aggregate.              #查看分组详情
    aggregate-list      Print a list of all aggregates.                     #查看分组列表
    aggregate-remove-host  aggregate.                                          #从主机从分组删除       
    aggregate-set-metadata Update the metadata associated with the aggregate.  #设置分组元数据信息
    aggregate-update    Update the aggregate's name and optionally           #修改分组名字