设为首页 收藏本站
查看: 1334|回复: 1

[经验分享] openstack运维实战系列(十)之nova指定compute节点和IP地址

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-1-25 09:31:46 | 显示全部楼层 |阅读模式
1. 背景需求
  在openstack中,nova负责openstack虚拟机的生命周期的管理,neutron则负责虚拟机的网络管理工作,默认情况下,创建一台虚拟机,nova会根据nova-scheduler调度算法,选择一台最合适的compute节点,同时会从neutron的地址池中分配一个ip地址给虚拟机,从而完成虚拟机的创建过程。
  然而,在一些特殊的场景中,如相同业务的虚拟机,希望落在不通的compute节点上,为虚拟机分配原有的ip地址,此时通过nova内置的调度是难以实现的,或者在一些应用场景,基于企业的CMDB联动,让相同业务的虚拟机,散落在openstack nova中的不同节点,从而减小down机的几率,减少故障的发生。本文以在指定的compute节点创建instance,并为其分配一个固定的ip地址为例。


2. 获取创建instance的基本信息
  • 获取镜像image id

1
2
3
4
5
6
7
[iyunv@controller ~]# glance image-list
+--------------------------------------+--------------------------+-------------+------------------+-------------+--------+
| ID                                   | Name                     | Disk Format | Container Format | Size        | Status |
+--------------------------------------+--------------------------+-------------+------------------+-------------+--------+
| 37aaedc7-6fe6-4fc8-b110-408d166b8e51 | cirrors                  | qcow2       | bare             | 13200896    | active |    #需要创建instance的image id
| ff0f7d03-a553-4357-a819-c74e913d649f | win2k8                   | qcow2       | bare             | 3391881216  | active |
+--------------------------------------+--------------------------+-------------+------------------+-------------+--------+



2. 获取套餐flavor id
1
2
3
4
5
6
[iyunv@controller ~]# nova flavor-list
+--------------------------------------+------------------+-----------+------+-----------+------+-------+-------------+-----------+
| ID                                   | Name             | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public |
+--------------------------------------+------------------+-----------+------+-----------+------+-------+-------------+-----------+
| 1                                    | m1.large         | 8192      | 100  | 10        |      | 4     | 1.0         | True      |
| 10                                   | V.GF1            | 8192      | 10   | 0         |      | 4     | 1.0         | True      |    #需要创建的flavor id



3. 获取安全组id
1
2
3
4
5
6
[iyunv@controller ~]# nova secgroup-list
+--------------------------------------+---------+-------------+
| Id                                   | Name    | Description |
+--------------------------------------+---------+-------------+
| 663468d9-73b1-4b04-8d4c-dac1bf21a94d | default | default     |        #secgroup的id号码
+--------------------------------------+---------+-------------+



4. 获取keypair
1
2
3
4
5
6
[iyunv@controller ~]# nova keypair-list
+------+-------------------------------------------------+
| Name | Fingerprint                                     |
+------+-------------------------------------------------+
| KEY  | 15:63:f2:de:74:53:a1:03:eb:36:27:e6:d9:00:41:22 |        #keypair的名字
+------+-------------------------------------------------+



5. 获取neutron网络id号码
1
2
3
4
5
6
[iyunv@controller ~]# neutron net-list
+--------------------------------------+---------------+-------------------------------------------------------+
| id                                   | name          | subnets                                               |
+--------------------------------------+---------------+-------------------------------------------------------+
| 99c68a93-336a-4605-aa78-343d41ca1206 | vmTest        | 79cb82a1-eac1-4311-8e6d-badcabd22e44 192.168.100.0/24 |    #需要启动的网络id号
+--------------------------------------+---------------+-------------------------------------------------------+



6. 获取coompute的主机名和zone名称
1
2
3
4
5
6
7
8
9
10
[iyunv@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-23T04:54:58.000000 | -               |
| nova-cert        | ChuangYiYuan_10_16_2_8  | internal          | enabled | up    | 2016-01-23T04:54:52.000000 | -               |
| nova-consoleauth | ChuangYiYuan_10_16_2_8  | internal          | enabled | up    | 2016-01-23T04:54:57.000000 | -               |
| nova-scheduler   | ChuangYiYuan_10_16_2_8  | internal          | enabled | up    | 2016-01-23T04:54:57.000000 | -               |
| nova-compute     | ChuangYiYuan_10_16_2_11 | ChuangYiYuanZone1 | enabled | up    | 2016-01-23T04:54:56.000000 | -               |    #需要启动的compute节点
| nova-compute     | ChuangYiYuan_10_16_2_14 | ChuangYiYuanZone1 | enabled | up    | 2016-01-23T04:54:56.000000 | -               |



3. 在指定的compute节点启动虚拟机,并指定固定ip地址
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
[iyunv@controller ~]# nova boot --flavor 10  \            #flavor名字
--image 37aaedc7-6fe6-4fc8-b110-408d166b8e51 \            #镜像id   
--key-name  KEY  \                         #KEY名字
--availability-zone ChuangYiYuanZone1:ChuangYiYuan_10_16_2_11  \   #在制定的区域和主机名启动instance
--security-groups 663468d9-73b1-4b04-8d4c-dac1bf21a94d  \      #安全组
--nic net-id=99c68a93-336a-4605-aa78-343d41ca1206,v4-fixed-ip=192.168.100.200   www.iyunv.com  #指定网络和IP地址
+--------------------------------------+------------------------------------------------+
| Property                             | Value                                          |
+--------------------------------------+------------------------------------------------+
| OS-DCF:diskConfig                    | MANUAL                                         |
| OS-EXT-AZ:availability_zone          | nova                                           |
| OS-EXT-SRV-ATTR:host                 | -                                              |
| OS-EXT-SRV-ATTR:hypervisor_hostname  | -                                              |
| OS-EXT-SRV-ATTR:instance_name        | instance-000001f9                              |
| OS-EXT-STS:power_state               | 0                                              |
| OS-EXT-STS:task_state                | scheduling                                     |
| OS-EXT-STS:vm_state                  | building                                       |
| OS-SRV-USG:launched_at               | -                                              |
| OS-SRV-USG:terminated_at             | -                                              |
| accessIPv4                           |                                                |
| accessIPv6                           |                                                |
| adminPass                            | 4T3vpfaXPTZe                                   |
| config_drive                         |                                                |
| created                              | 2016-01-23T04:44:51Z                           |
| flavor                               | V.GF1 (10)                                     |
| hostId                               |                                                |
| id                                   | 3f694eaf-aa87-456a-99ce-90dd9f4e45ee           |
| image                                | cirrors (37aaedc7-6fe6-4fc8-b110-408d166b8e51) |
| key_name                             | KEY                                            |
| metadata                             | {}                                             |
| name                                 | www.iyunv.com                       |
| os-extended-volumes:volumes_attached | []                                             |
| progress                             | 0                                              |
| security_groups                      | 663468d9-73b1-4b04-8d4c-dac1bf21a94d           |
| status                               | BUILD                                          |
| tenant_id                            | 842ab3268a2c47e6a4b0d8774de805ae               |
| updated                              | 2016-01-23T04:44:52Z                           |
| user_id                              | bc5e46fc4204497185ae3ca6f8b7affb               |
+--------------------------------------+------------------------------------------------+



校验配置情况
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
[iyunv@controller ~]# nova list | grep 3f694eaf-aa87-456a-99ce-90dd9f4e45ee
| 3f694eaf-aa87-456a-99ce-90dd9f4e45ee | www.iyunv.com | ACTIVE | -          | Running     | vmTest=192.168.100.200   | ChuangYiYuan_10_16_2_11 |
[iyunv@controller ~]# nova show 3f694eaf-aa87-456a-99ce-90dd9f4e45ee      
+--------------------------------------+----------------------------------------------------------+
| Property                             | Value                                                    |
+--------------------------------------+----------------------------------------------------------+
| OS-DCF:diskConfig                    | MANUAL                                                   |
| OS-EXT-AZ:availability_zone          | ChuangYiYuanZone1                                        |
| OS-EXT-SRV-ATTR:host                 | ChuangYiYuan_10_16_2_11                                  |    #指定的compute节点
| OS-EXT-SRV-ATTR:hypervisor_hostname  | ChuangYiYuan_10_16_2_11                                  |
| OS-EXT-SRV-ATTR:instance_name        | instance-000001f9                                        |
| OS-EXT-STS:power_state               | 1                                                        |
| OS-EXT-STS:task_state                | -                                                        |
| OS-EXT-STS:vm_state                  | active                                                   |
| OS-SRV-USG:launched_at               | 2016-01-23T04:45:06.000000                               |
| OS-SRV-USG:terminated_at             | -                                                        |
| accessIPv4                           |                                                          |
| accessIPv6                           |                                                          |
| config_drive                         |                                                          |
| created                              | 2016-01-23T04:44:51Z                                     |
| flavor                               | V.GF1 (10)                                               |
| hostId                               | b3a37b586ae2847a0b18c58ff7693b41762fa0bf6a3cc363c862761a |
| id                                   | 3f694eaf-aa87-456a-99ce-90dd9f4e45ee                     |
| image                                | cirrors (37aaedc7-6fe6-4fc8-b110-408d166b8e51)           |
| key_name                             | KEY                                                      |
| metadata                             | {}                                                       |
| name                                 | www.iyunv.com                                 |
| os-extended-volumes:volumes_attached | []                                                       |
| progress                             | 0                                                        |
| security_groups                      | default                                                  |
| status                               | ACTIVE                                                   |
| tenant_id                            | 842ab3268a2c47e6a4b0d8774de805ae                         |
| updated                              | 2016-01-23T04:45:07Z                                     |
| user_id                              | bc5e46fc4204497185ae3ca6f8b7affb                         |
| vmTest network                       | 192.168.100.200                                          |    #指定的ip地址,good,完成
+--------------------------------------+----------------------------------------------------------+



4. 总结
   以上方法用于openstack的日常运维中,一般而言,不建议使用,建议使用nova内置的调度算法来完成。本人在实际的工作中,经常有指定compute机器和指定ip的需求。

5. 附录
  附录提供了nova boot用法相关的参数

[iyunv@controller ~]# nova help boot
usage: nova boot [--flavor <flavor>] [--image <image>]
                 [--image-with <key=value>] [--boot-volume <volume_id>]
                 [--snapshot <snapshot_id>] [--num-instances <number>]
                 [--meta <key=value>] [--file <dst-path=src-path>]
                 [--key-name <key-name>] [--user-data <user-data>]
                 [--availability-zone <availability-zone>]
                 [--security-groups <security-groups>]
                 [--block-device-mapping <dev-name=mapping>]
                 [--block-device key1=value1[,key2=value2...]]
                 [--swap <swap_size>]
                 [--ephemeral size=<size>[,format=<format>]]
                 [--hint <key=value>]
                 [--nic <net-id=net-uuid,v4-fixed-ip=ip-addr,port-id=port-uuid>]
                 [--config-drive <value>] [--poll]
                 <name>

Boot a new server.

Positional arguments:
  <name>                Name for the new server

Optional arguments:
  --flavor <flavor>     Name or ID of flavor (see 'nova flavor-list').
  --image <image>       Name or ID of image (see 'nova image-list').
  --image-with <key=value>
                        Image metadata property (see 'nova image-show').
  --boot-volume <volume_id>
                        Volume ID to boot from.
  --snapshot <snapshot_id>
                        Snapshot ID to boot from (will create a volume).
  --num-instances <number>
                        boot multiple servers at a time (limited by quota).
  --meta <key=value>    Record arbitrary key/value metadata to /meta.js on the
                        new server. Can be specified multiple times.
  --file <dst-path=src-path>
                        Store arbitrary files from <src-path> locally to <dst-
                        path> on the new server. You may store up to 5 files.
  --key-name <key-name>
                        Key name of keypair that should be created earlier
                        with the command keypair-add
  --user-data <user-data>
                        user data file to pass to be exposed by the metadata
                        server.
  --availability-zone <availability-zone>
                        The availability zone for server placement.
  --security-groups <security-groups>
                        Comma separated list of security group names.
  --block-device-mapping <dev-name=mapping>
                        Block device mapping in the format <dev-
                        name>=<id>:<type>:<size(GB)>:<delete-on-terminate>.
  --block-device key1=value1[,key2=value2...]
                        Block device mapping with the keys: id=image_id,
                        snapshot_id or volume_id, source=source type (image,
                        snapshot, volume or blank), dest=destination type of
                        the block device (volume or local), bus=device's bus,
                        device=name of the device (e.g. vda, xda, ...),
                        size=size of the block device in GB, format=device
                        will be formatted (e.g. swap, ext3, ntfs, ...),
                        bootindex=integer used for ordering the boot disks,
                        type=device type (e.g. disk, cdrom, ...) and
                        shutdown=shutdown behaviour (either preserve or
                        remove).
  --swap <swap_size>    Create and attach a local swap block device of
                        <swap_size> MB.
  --ephemeral size=<size>[,format=<format>]
                        Create and attach a local ephemeral block device of
                        <size> GB and format it to <format>.
  --hint <key=value>    Send arbitrary key/value pairs to the scheduler for
                        custom use.
  --nic <net-id=net-uuid,v4-fixed-ip=ip-addr,port-id=port-uuid>
                        Create a NIC on the server. Specify option multiple
                        times to create multiple NICs. net-id: attach NIC to
                        network with this UUID (required if no port-id), v4
                        -fixed-ip: IPv4 fixed address for NIC (optional),
                        port-id: attach NIC to port with this UUID (required
                        if no net-id)
  --config-drive <value>
                        Enable config drive
  --poll                Blocks while server builds so progress can be
                        reported.






运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-169111-1-1.html 上篇帖子: openstack运维实战系列(八)之glance镜像上传 下篇帖子: openstack运维实战系列(十一)之neutron替换instance的IP
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表