从一镜像启动一实例

从一镜像启动一实例

按照下面的步骤从镜像中启动一个云主机。

  1. 在您收集完所需的参数后,运行以下命令启动一个云主机。指定服务器名称、规格标识编码和镜像标识编码。

    $ openstack server create --flavor FLAVOR_ID --image IMAGE_ID --key-name KEY_NAME \
      --user-data USER_DATA_FILE --security-group SEC_GROUP_NAME --property KEY=VALUE \
      INSTANCE_NAME
    

    可选地,您可以为访问控制提供一个关键字,为安全指定安全组。您也可以包括元数据关键字和值对。比如,提供参数``–property description=”My Server”``,为您的服务器添加一个描述。

    当虚拟机启动时,通过``–user-data USER-DATA-FILE``参数用本地文件为虚拟机传递用户数据。

    重要

    If you boot an instance with an INSTANCE_NAME greater than 63 characters, Compute truncates it automatically when turning it into a host name to ensure the correct work of dnsmasq. The corresponding warning is written into the neutron-dnsmasq.log file.

    下面的命令启动了一个名称为``MyCirrosServer``的实例。其规格为``m1.small`` (ID 为 1), 镜像为 cirros-0.3.2-x86_64-uec (ID 为 397e713c-b95b-4186-ad46-6126863ea0a9), 安全组为``default``, 密钥对名称为``KeyPair01``, 以及名称为``cloudinit.file``的用户数据文件:

    $ openstack server create --flavor 1 --image 397e713c-b95b-4186-ad46-6126863ea0a9 \
      --security-group default --key-name KeyPair01 --user-data cloudinit.file \
      myCirrosServer
    

    根据传递的参数,命令返回一个云主机属性列表。

    +--------------------------------------+-----------------------------------------------+
    | Field                                | Value                                         |
    +--------------------------------------+-----------------------------------------------+
    | OS-DCF:diskConfig                    | MANUAL                                        |
    | OS-EXT-AZ:availability_zone          |                                               |
    | OS-EXT-SRV-ATTR:host                 | None                                          |
    | OS-EXT-SRV-ATTR:hypervisor_hostname  | None                                          |
    | OS-EXT-SRV-ATTR:instance_name        |                                               |
    | OS-EXT-STS:power_state               | NOSTATE                                       |
    | OS-EXT-STS:task_state                | scheduling                                    |
    | OS-EXT-STS:vm_state                  | building                                      |
    | OS-SRV-USG:launched_at               | None                                          |
    | OS-SRV-USG:terminated_at             | None                                          |
    | accessIPv4                           |                                               |
    | accessIPv6                           |                                               |
    | addresses                            |                                               |
    | adminPass                            | E4Ksozt4Efi8                                  |
    | config_drive                         |                                               |
    | created                              | 2016-11-30T14:48:05Z                          |
    | flavor                               | m1.tiny                                       |
    | hostId                               |                                               |
    | id                                   | 89015cc9-bdf1-458a-8518-fdca2b4a5785          |
    | image                                | cirros (397e713c-b95b-4186-ad46-6126863ea0a9) |
    | key_name                             | KeyPair01                                     |
    | name                                 | myCirrosServer                                |
    | os-extended-volumes:volumes_attached | []                                            |
    | progress                             | 0                                             |
    | project_id                           | 5669caad86a04256994cdf755df4d3c1              |
    | properties                           |                                               |
    | security_groups                      | [{u'name': u'default'}]                       |
    | status                               | BUILD                                         |
    | updated                              | 2016-11-30T14:48:05Z                          |
    | user_id                              | c36cec73b0e44876a4478b1e6cd749bb              |
    | metadata                             | {u'KEY': u'VALUE'}                            |
    +--------------------------------------+-----------------------------------------------+
    

    ``BUILD``状态表示实例已启动但未联机。

    “ACTIVE”状态表明实例是活动状态。

  2. 从输出中拷贝``id``作为云主机的ID. 使用该ID获取云主机详细信息或删除云主机。

  3. 拷贝``adminPass``的值作为管理员密码。用改密码登陆云主机。

    注解

    You can also place arbitrary local files into the instance file system at creation time by using the --file <dst-path=src-path> option. You can store up to five files. For example, if you have a special authorized keys file named special_authorized_keysfile that you want to put on the instance rather than using the regular SSH key injection, you can use the --file option as shown in the following example.

    $ openstack server create --image ubuntu-cloudimage --flavor 1 vm-name \
      --file /root/.ssh/authorized_keys=special_authorized_keysfile
    
  4. 核实实例是否为联机的

    $ openstack server list
    

    列表显示了项目中您所属的所有实例的标识、名称、状态和私有(如果分配为公有的)IP地址:

    +-------------+----------------------+--------+------------+-------------+------------------+------------+
    | ID          | Name                 | Status | Task State | Power State | Networks         | Image Name |
    +-------------+----------------------+--------+------------+-------------+------------------+------------+
    | 84c6e57d... | myCirrosServer       | ACTIVE | None       | Running     | private=10.0.0.3 | cirros     |
    | 8a99547e... | myInstanceFromVolume | ACTIVE | None       | Running     | private=10.0.0.4 | centos     |
    +-------------+----------------------+--------+------------+-------------+------------------+------------+
    

    如果实例状态为ACTIVE,则实例为联机状态。

  5. 运行以下命令查看命令:command:`openstack server list`的可用选项:

    $ openstack help server list
    

    注解

    如果你没有提供一个密钥对,安全组,或规则,你只能从内部云通过VNC访问实例。甚至ping实例也是不可能的。

Creative Commons Attribution 3.0 License

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.