1. 背景需求算法
在openstack中,nova負責openstack虛擬機的生命週期的管理,neutron則負責虛擬機的網絡管理工做,默認狀況下,建立一臺虛擬機,nova會根據nova-scheduler調度算法,選擇一臺最合適的compute節點,同時會從neutron的地址池中分配一個ip地址給虛擬機,從而完成虛擬機的建立過程。安全
然而,在一些特殊的場景中,如相同業務的虛擬機,但願落在不通的compute節點上,爲虛擬機分配原有的ip地址,此時經過nova內置的調度是難以實現的,或者在一些應用場景,基於企業的CMDB聯動,讓相同業務的虛擬機,散落在openstack nova中的不一樣節點,從而減少down機的概率,減小故障的發生。本文以在指定的compute節點建立instance,併爲其分配一個固定的ip地址爲例。
網絡
2. 獲取建立instance的基本信息app
獲取鏡像p_w_picpath id運維
[root@controller ~]# glance p_w_picpath-list +--------------------------------------+--------------------------+-------------+------------------+-------------+--------+ | ID | Name | Disk Format | Container Format | Size | Status | +--------------------------------------+--------------------------+-------------+------------------+-------------+--------+ | 37aaedc7-6fe6-4fc8-b110-408d166b8e51 | cirrors | qcow2 | bare | 13200896 | active | #須要建立instance的p_w_picpath id | ff0f7d03-a553-4357-a819-c74e913d649f | win2k8 | qcow2 | bare | 3391881216 | active | +--------------------------------------+--------------------------+-------------+------------------+-------------+--------+
2. 獲取套餐flavor idide
[root@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. 獲取安全組idui
[root@controller ~]# nova secgroup-list +--------------------------------------+---------+-------------+ | Id | Name | Description | +--------------------------------------+---------+-------------+ | 663468d9-73b1-4b04-8d4c-dac1bf21a94d | default | default | #secgroup的id號碼 +--------------------------------------+---------+-------------+
4. 獲取keypairthis
[root@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號碼3d
[root@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名稱orm
[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-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地址
[root@controller ~]# nova boot --flavor 10 \ #flavor名字 --p_w_picpath 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 happyblog_blog_51cto_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 | | p_w_picpath | cirrors (37aaedc7-6fe6-4fc8-b110-408d166b8e51) | | key_name | KEY | | metadata | {} | | name | happyblog_blog_51cto_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 | +--------------------------------------+------------------------------------------------+
校驗配置狀況
[root@controller ~]# nova list | grep 3f694eaf-aa87-456a-99ce-90dd9f4e45ee | 3f694eaf-aa87-456a-99ce-90dd9f4e45ee | happyblog_blog_51cto_com | ACTIVE | - | Running | vmTest=192.168.100.200 | ChuangYiYuan_10_16_2_11 | [root@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 | | p_w_picpath | cirrors (37aaedc7-6fe6-4fc8-b110-408d166b8e51) | | key_name | KEY | | metadata | {} | | name | happyblog_blog_51cto_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用法相關的參數
[root@controller ~]# nova help boot
usage: nova boot [--flavor <flavor>] [--p_w_picpath <p_w_picpath>]
[--p_w_picpath-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').
--p_w_picpath <p_w_picpath> Name or ID of p_w_picpath (see 'nova p_w_picpath-list').
--p_w_picpath-with <key=value>
Image metadata property (see 'nova p_w_picpath-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=p_w_picpath_id,
snapshot_id or volume_id, source=source type (p_w_picpath,
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.