openstack使用命令行nova创建虚拟机

我们一台虚拟机需要的东西不多,大小、镜像、网络以及安全组。所以我们就只需要查出这些配置信息,然后就可以创建虚拟机了,这里指定IP地址和生成节点。

说明一下,本人是利用公司里docker容器里部署的openstack,所以在创建之前,先用命令行进入相应容器中:

docker exec -it -u 0 neutron-server /bin/bash

上述命令可简写成:docker exec -it neutron-server bash

进入到:neutron-server中,再继续以下命令:

1.查看flavor

使用nova flavor-list列出上面的每个flavor,选择你想要的那一个,这里选择m1.large,如下图:


flavor

2.查看image

使用nova image-list列出上面的每个image,选择你需要的那一个,这选择centos的镜像,如下图:


image

3.查看网络id 

方法(1): 使用nova network-list列出上面的每个network,选择你想要的那个,这里选择Business-1,如下图:


方法(2):使用 neutron net-list,如下图:


4.查看安全组

一般安全组都设置为default,但是有时候就不一定,所以我们还是查看一下再做选择,如下图:


security group


5.获取keypair



6.. 获取coompute的主机名和zone名称



7创建虚拟机

好了,所需要的参数都拿到之后我们就可以创建虚拟机了,使用命令:

(neutron-server)[neutron@B-OPS-9-3 /]$ nova boot --flavor m1.large  \   #flavor名字

--image xuy-Snapshot  \    #镜像id  

--nic net-id=bd0e166f-ecb4-4650-a715-32e7ca1fbecf   \

--security-groups f7f2eef3-bf34-49a2-a2e9-c8f12ec19973    \   #安全组ID

--availability-zone  nova:B-OPS-9-3  \   #在制定的区域:主机名启动instance

--key-name octavia_ssh_key    \    #KEY名字

C929    #新建虚拟机的名字

如下图:




这样就把一台虚拟机创建出来了,是不是很简单呢,我们创建完成后可以使用nova list看一下虚拟机的列表:

可能一开始会看到如下:

此时系统正在创建虚机,过一会再试一次:

如下图,此时发现,虚机创建完成(ACITVE    RUNNING)


用命令行查看虚机信息:  nova show +虚机名字或id


注意:在创建虚机时,一定要确保几个相关服务,如nova-compute服务state处于up状态。




附录

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

[root@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.




猜你喜欢

转载自blog.csdn.net/poo_chai/article/details/80858428