在Openstack 实际的应用中,经常会被客户或者Boss问到,我创建的虚拟机在后端众多物理机上是怎么分配的。
 
这时你最好不要答“你不用考虑后面分配的细节,我们的云会自动处理”。
 
或者这样的:我后端的计算节点,有一批机器是新机器,特别好,一些是旧机器,性能不好,我想把关键应用放到新机器上,普通应用到放到旧机器上。
 
上面的场景通过Openstack的aggregate即可以解决.
 
在未应用aggregate之间,我们用nova-manage service list 来查看平台服务:
 
 
复制代码
root@AuthServer:~# nova-manage service list
Binary           Host                                 Zone             Status     State Updated_At
nova-consoleauth AuthServer                           internal         enabled    :-)   2013-04-24 02:35:39
nova-cert        AuthServer                           internal         enabled    :-)   2013-04-24 02:35:38
nova-conductor   AuthServer                           internal         enabled    :-)   2013-04-24 02:35:38
nova-scheduler   AuthServer                           internal         enabled    :-)   2013-04-24 02:35:39
nova-compute     AuthServer                           nova           enabled    :-)   2013-04-24 02:35:35
nova-compute     KVMCompute                           nova           enabled    :-)   2013-04-24 02:35:30
nova-compute     VmWareCompute                        nova           enabled    :-)   2013-04-24 02:35:34
nova-scheduler   VmWareCompute                        internal         enabled    :-)   2013-04-24 02:35:26
nova-scheduler   KVMCompute                           internal         enabled    :-)   2013-04-24 02:35:27
复制代码

他们全部默认在nova Zone中(如果你没有配置node_avalibility_zone的话),

 
在通过aggregate 配置好主机集合后,service list变成了.
 
复制代码
root@AuthServer:~# nova-manage service list
Binary           Host                                 Zone             Status     State Updated_At
nova-consoleauth AuthServer                           internal         enabled    :-)   2013-04-24 02:35:39
nova-cert        AuthServer                           internal         enabled    :-)   2013-04-24 02:35:38
nova-conductor   AuthServer                           internal         enabled    :-)   2013-04-24 02:35:38
nova-scheduler   AuthServer                           internal         enabled    :-)   2013-04-24 02:35:39
nova-compute     AuthServer                           zone52           enabled    :-)   2013-04-24 02:35:35
nova-compute     KVMCompute                           zone51           enabled    :-)   2013-04-24 02:35:30
nova-compute     VmWareCompute                        zone53           enabled    :-)   2013-04-24 02:35:34
nova-scheduler   VmWareCompute                        internal         enabled    :-)   2013-04-24 02:35:26
nova-scheduler   KVMCompute                           internal         enabled    :-)   2013-04-24 02:35:27
复制代码

 

 
这样,我们可以用过Openstack的api ,创建虚拟机,直接指定avalibility_zone,让虚拟机指定创建到某个主机组中。
 
复制代码
{
    "server":{
        "name":"server-1",
        "availability_zone":"zone52",
        "imageRef":"87589e22-fc26-4ab0-8b15-948823b00a5e",
        "flavorRef":"1"
    }
}
复制代码

主机组支持一对多,可以灵活配置,具体配置可参考nova -help内容.

还可以,直接指定到某个zone中的某台主机:

 

复制代码
{
    "server":{
        "name":"server-1",
        "imageRef":"87589e22-fc26-4ab0-8b15-948823b00a5e",
        "availability_zone" : "zone5153:VmWareCompute",
        "flavorRef":"1"
    }
}
复制代码

 

 

 

下面是我的配置:
共创建了三个主机组,每个一台机器方便测试:
复制代码
root@AuthServer:~# nova aggregate-list
+----+------+-------------------+
| Id | Name | Availability Zone |
+----+------+-------------------+
| 4  | agg1 | zone51            |
| 5  | agg2 | zone52            |
| 6  | agg3 | zone53            |
+----+------+-------------------+

root@AuthServer:~# nova aggregate-details 4
+----+------+-------------------+-----------------+-----------------------------------+
| Id | Name | Availability Zone | Hosts           | Metadata                          |
+----+------+-------------------+-----------------+-----------------------------------+
| 4  | agg1 | zone51            | [u'KVMCompute'] | {u'availability_zone': u'zone51'} |
+----+------+-------------------+-----------------+-----------------------------------+

root@AuthServer:~# nova aggregate-details 5
+----+------+-------------------+-----------------+-----------------------------------+
| Id | Name | Availability Zone | Hosts           | Metadata                          |
+----+------+-------------------+-----------------+-----------------------------------+
| 5  | agg2 | zone52            | [u'AuthServer'] | {u'availability_zone': u'zone52'} |
+----+------+-------------------+-----------------+-----------------------------------+

root@AuthServer:~# nova aggregate-details 6
+----+------+-------------------+--------------------+-----------------------------------+
| Id | Name | Availability Zone | Hosts              | Metadata                          |
+----+------+-------------------+--------------------+-----------------------------------+
| 6  | agg3 | zone53            | [u'VmWareCompute'] | {u'availability_zone': u'zone53'} |
+----+------+-------------------+--------------------+-----------------------------------+
复制代码

 

最后提一下,如果主机数量比较少,不需要使用aggregate,直接使用默认的zone nova即可:
--availability-zone <availibility-zone>:<compute-host>
 
#nova boot --image aee1d242-730f-431f-88c1-87630c0f07ba --flavor 1 --availability-zone nova:nova-1 testhost

 

 
 
本文为原创内容,转载请注明出自 梁小白博客(http://biangbiang.cnblogs.com)
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐