当前位置:   article > 正文

374. 【openstack】命令行模式创建虚拟机_openstack flavor create

openstack flavor create

一、创建一个实例类型(flavor)

命令:

openstack flavor create \
--id 'id_flavor_m1_nano' \
--vcpus 4 \
--ram $(( 1024 * 16 )) \
--disk 200 m1.nano 
  • 1
  • 2
  • 3
  • 4
  • 5

备注:$(( ))是linux 里做数学计算的一种写法,也可以用 $[ ]

执行结果:

root@OpenStack:~#  openstack flavor create --id 'id_flavor_m1_nano' --vcpus 4 --ram $(( 1024 * 16 )) --disk 200 m1.nano
/usr/lib/python3/dist-packages/secretstorage/dhcrypto.py:15: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
  from cryptography.utils import int_from_bytes
/usr/lib/python3/dist-packages/secretstorage/util.py:19: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
  from cryptography.utils import int_from_bytes
+----------------------------+-------------------+
| Field                      | Value             |
+----------------------------+-------------------+
| OS-FLV-DISABLED:disabled   | False             |
| OS-FLV-EXT-DATA:ephemeral  | 0                 |
| description                | None              |
| disk                       | 200               |
| id                         | id_flavor_m1_nano |
| name                       | m1.nano           |
| os-flavor-access:is_public | True              |
| properties                 |                   |
| ram                        | 16384             |
| rxtx_factor                | 1.0               |
| swap                       |                   |
| vcpus                      | 4                 |
+----------------------------+-------------------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

执行结果

二、生成访问 key

命令:

openstack keypair create --public-key ~/.ssh/id_rsa.pub key
  • 1

执行结果:

root@OpenStack:~#  openstack keypair create --public-key ~/.ssh/id_rsa.pub key
/usr/lib/python3/dist-packages/secretstorage/dhcrypto.py:15: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
  from cryptography.utils import int_from_bytes
/usr/lib/python3/dist-packages/secretstorage/util.py:19: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
  from cryptography.utils import int_from_bytes
+-------------+-------------------------------------------------+
| Field       | Value                                           |
+-------------+-------------------------------------------------+
| created_at  | None                                            |
| fingerprint | 9d:b1:80:3d:cc:2a:7d:ad:54:97:a2:4a:28:89:c2:e5 |
| id          | key                                             |
| is_deleted  | None                                            |
| name        | key                                             |
| type        | ssh                                             |
| user_id     | f0f29beca3b24ae59a5270d666c4f812                |
+-------------+-------------------------------------------------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

执行结果

备注:执行 openstack keypair list可验证 key 是否创建成功。

三、启动实例

1. 查看可用的实例类型

root@OpenStack:~#  openstack flavor list
/usr/lib/python3/dist-packages/secretstorage/dhcrypto.py:15: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
  from cryptography.utils import int_from_bytes
/usr/lib/python3/dist-packages/secretstorage/util.py:19: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
  from cryptography.utils import int_from_bytes
+--------------------------------------+-----------+-------+------+-----------+-------+-----------+
| ID                                   | Name      |   RAM | Disk | Ephemeral | VCPUs | Is Public |
+--------------------------------------+-----------+-------+------+-----------+-------+-----------+
| id_flavor_m1_nano                    | m1.nano   | 16384 |  200 |         0 |     4 | True      |
+--------------------------------------+-----------+-------+------+-----------+-------+-----------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

2.查看可用的镜像

root@OpenStack:~#  openstack image list
/usr/lib/python3/dist-packages/secretstorage/dhcrypto.py:15: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
  from cryptography.utils import int_from_bytes
/usr/lib/python3/dist-packages/secretstorage/util.py:19: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
  from cryptography.utils import int_from_bytes
+--------------------------------------+--------------+--------+
| ID                                   | Name         | Status |
+--------------------------------------+--------------+--------+
| 27dcc741-3203-4b48-aca2-abe2bb551aa6 | centos7      | active |
| f8767732-0773-4371-b660-906be13f590a | centos8      | active |
| db204b30-5cec-4301-b6ba-f6d7e6cea263 | debian       | active |
| a1175f50-9b3c-4bfb-aaad-b27e64ab28f4 | spatial_v1   | active |
| 00865766-a484-49d8-86d7-4917f4895b65 | ubuntu20.0.4 | active |
+--------------------------------------+--------------+--------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

3.查看可用的网络

root@OpenStack:~#  openstack network list
/usr/lib/python3/dist-packages/secretstorage/dhcrypto.py:15: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
  from cryptography.utils import int_from_bytes
/usr/lib/python3/dist-packages/secretstorage/util.py:19: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
  from cryptography.utils import int_from_bytes
+--------------------------------------+----------+--------------------------------------+
| ID                                   | Name     | Subnets                              |
+--------------------------------------+----------+--------------------------------------+
| 0698d3c2-b029-4b63-9d04-8905d2908f9c | external | 6604485c-25a5-4981-a5c2-d98358a0b62e |
| 1e0a8e56-b169-4562-8d6e-e5e846ae49fd | internal | 14463c1b-462f-4fd1-ae18-b204009150ce |
+--------------------------------------+----------+--------------------------------------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

4. 查看可用的安全组

root@OpenStack:~#  openstack security group list     
/usr/lib/python3/dist-packages/secretstorage/dhcrypto.py:15: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
  from cryptography.utils import int_from_bytes
/usr/lib/python3/dist-packages/secretstorage/util.py:19: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
  from cryptography.utils import int_from_bytes
+--------------------------------------+---------+------------------------+----------------------------------+------+
| ID                                   | Name    | Description            | Project                          | Tags |
+--------------------------------------+---------+------------------------+----------------------------------+------+
| 98429665-ffd0-47b2-b09a-5a82f398e7f9 | default | Default security group | f800648190e4429a8c30b0c194f22c32 | []   |
+--------------------------------------+---------+------------------------+----------------------------------+------+

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

5.创建实例

root@OpenStack:~#  openstack server create --flavor m1.nano --image debian --nic net-id=1e0a8e56-b169-4562-8d6e-e5e846ae49fd --key-name key instance_create_by_cli2                                                         
/usr/lib/python3/dist-packages/secretstorage/dhcrypto.py:15: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
  from cryptography.utils import int_from_bytes
/usr/lib/python3/dist-packages/secretstorage/util.py:19: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
  from cryptography.utils import int_from_bytes
+-------------------------------------+-----------------------------------------------+
| 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                           | Vzjk2ak6Wq7s                                  |
| config_drive                        |                                               |
| created                             | 2022-07-21T01:12:29Z                          |
| flavor                              | m1.nano (id_flavor_m1_nano)                   |
| hostId                              |                                               |
| id                                  | 9d27c29d-41e7-44aa-b9a7-dffee7e5598f          |
| image                               | debian (db204b30-5cec-4301-b6ba-f6d7e6cea263) |
| key_name                            | key                                           |
| name                                | instance_create_by_cli2                       |
| progress                            | 0                                             |
| project_id                          | f800648190e4429a8c30b0c194f22c32              |
| properties                          |                                               |
| security_groups                     | name='default'                                |
| status                              | BUILD                                         |
| updated                             | 2022-07-21T01:12:29Z                          |
| user_id                             | f0f29beca3b24ae59a5270d666c4f812              |
| volumes_attached                    |                                               |
+-------------------------------------+-----------------------------------------------+
  • 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

6.检查结果

root@OpenStack:~#  openstack server list
/usr/lib/python3/dist-packages/secretstorage/dhcrypto.py:15: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
  from cryptography.utils import int_from_bytes
/usr/lib/python3/dist-packages/secretstorage/util.py:19: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
  from cryptography.utils import int_from_bytes
+--------------------------------------+-------------------------+--------+--------------------------------------+---------+-----------+
| ID                                   | Name                    | Status | Networks                             | Image   | Flavor    |
+--------------------------------------+-------------------------+--------+--------------------------------------+---------+-----------+
| 9d27c29d-41e7-44aa-b9a7-dffee7e5598f | instance_create_by_cli2 | ACTIVE | internal=10.10.18.183                | debian  | m1.nano   |
| 5d9a84a5-7c00-4085-bd6f-86b7615f0803 | test                    | ACTIVE | internal=10.10.18.69                 | debian  | warehouse |
+--------------------------------------+-------------------------+--------+--------------------------------------+---------+-----------+

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

7.创建浮动IP(floating ip)

root@OpenStack:~#  openstack floating ip create external
/usr/lib/python3/dist-packages/secretstorage/dhcrypto.py:15: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
  from cryptography.utils import int_from_bytes
/usr/lib/python3/dist-packages/secretstorage/util.py:19: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
  from cryptography.utils import int_from_bytes
The option [tenant_id] has been deprecated. Please avoid using it.
+---------------------+--------------------------------------+
| Field               | Value                                |
+---------------------+--------------------------------------+
| created_at          | 2022-07-21T01:16:45Z                 |
| description         |                                      |
| dns_domain          | None                                 |
| dns_name            | None                                 |
| fixed_ip_address    | None                                 |
| floating_ip_address | 192.168.3.212                        |
| floating_network_id | 0698d3c2-b029-4b63-9d04-8905d2908f9c |
| id                  | 6eb1f91b-25cc-44ee-ad3b-a6bb97754851 |
| name                | 192.168.3.212                        |
| port_details        | None                                 |
| port_id             | None                                 |
| project_id          | f800648190e4429a8c30b0c194f22c32     |
| qos_policy_id       | None                                 |
| revision_number     | 0                                    |
| router_id           | None                                 |
| status              | DOWN                                 |
| subnet_id           | None                                 |
| tags                | []                                   |
| tenant_id           | f800648190e4429a8c30b0c194f22c32     |
| updated_at          | 2022-07-21T01:16:45Z                 |
+---------------------+--------------------------------------+
  • 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

8.绑定浮动IP

root@OpenStack:~#  openstack server add floating ip instance_create_by_cli2 192.168.3.212 
/usr/lib/python3/dist-packages/secretstorage/dhcrypto.py:15: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
  from cryptography.utils import int_from_bytes
/usr/lib/python3/dist-packages/secretstorage/util.py:19: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
  from cryptography.utils import int_from_bytes
The option [tenant_id] has been deprecated. Please avoid using it.
The option [tenant_id] has been deprecated. Please avoid using it.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

备注:执行 openstack server list可以查看浮动IP是否绑定成功。

四、附加

openstack server create 命令:

openstack server create
    --flavor <flavor>
    (--image <image> | --image-property <key=value> | --volume <volume> | --snapshot <snapshot>)
    [--boot-from-volume <volume-size>]
    [--block-device-mapping <dev-name=mapping>]
    [--block-device]
    [--swap <swap>]
    [--ephemeral <size=size[,format=format]
    >]
    [--network <network>]
    [--port <port>]
    [--nic <net-id=net-uuid,port-id=port-uuid,v4-fixed-ip=ip-addr,v6-fixed-ip=ip-addr,tag=tag,auto,none>]
    [--password <password>]
    [--security-group <security-group>]
    [--key-name <key-name>]
    [--property <key=value>]
    [--file <dest-filename=source-filename>]
    [--user-data <user-data>]
    [--description <description>]
    [--availability-zone <zone-name>]
    [--host <host>]
    [--hypervisor-hostname <hypervisor-hostname>]
    [--hint <key=value>]
    [--use-config-drive | --no-config-drive | --config-drive <config-drive-volume>|True]
    [--min <count>]
    [--max <count>]
    [--tag <tag>]
    [--hostname <hostname>]
    [--wait]
    [--trusted-image-cert <trusted-cert-id>]
    <server-name>
  • 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
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号