【openstack】命令行模式创建虚拟机

简介: 【openstack】命令行模式创建虚拟机

正文


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


命令:

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


备注:$(( )) 是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                 |
+----------------------------+-------------------+


12.webp.jpg

执行结果


二、生成访问 key


命令:

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


执行结果:


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                |
+-------------+-------------------------------------------------+


33.webp.jpg

执行结果


备注:执行 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      |
+--------------------------------------+-----------+-------+------+-----------+-------+-----------+


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 |
+--------------------------------------+--------------+--------+


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 |
+--------------------------------------+----------+--------------------------------------+


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 | []   |
+--------------------------------------+---------+------------------------+----------------------------------+------+



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                    |                                               |
+-------------------------------------+-----------------------------------------------+



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 |
+--------------------------------------+-------------------------+--------+--------------------------------------+---------+-----------+



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                 |
+---------------------+--------------------------------------+


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.


备注:执行 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>


目录
相关文章
在openstack云平台中,使用命令行创建云主机操作步骤
在openstack云平台中,使用命令行创建云主机操作步骤
481 0
在openstack云平台中,使用命令行创建云主机操作步骤
|
存储 算法 API
云计算---openstack创建虚拟机过程
   虚拟机创建过程:(1)界面或命令行通过RESTful API向keystone获取认证信息。(2)keystone通过用户请求认证信息,并生成auth-token返回给对应的认证请求。
1768 0
|
网络安全
openstack 命令行管理一 - br-ex 网络设定 (备忘)
 理解: openstack 内部网络结构如下 |------------  内部网络   ----------|    &lt;- 虚拟路由 -&gt;  |----- 外部网络 ------|  [instance1 eth0]  ==== br-int                                                br-ext======
1766 0
openstack 命令行管理二 - 镜像管理 (备忘)
帮助[root@station140 ~(keystone_admin)]# glance help | grep image [--os-image-url OS_IMAGE_URL] [-U OS_IMAGE_URL] [--os-image-api-version OS_IMAGE_API_VERSION] add
1281 0
|
前端开发
openstack 命令行管理三 - tenant 管理 (备忘)
Openstack 中, 以租户作为云主机隔离的单位   project 等同于 tenant OpenStack Compute Service (nova) 作为认证时候, 称为 project OpenStack Identity Service (keystone) 作为认证时候, 称为 tenant   在管理 openstack 时候, 需要添加独立的 proj
1644 0
|
关系型数据库
openstack 命令行管理四 - 资源管理 (备忘)
 配额用于对每个 tenants 进行限制, 如浮动 IP, 内存, CPU, 磁盘, 密钥, 安全规则, 云硬盘等 资源管理帮助 [root@station140 ~(keystone_admin)]# nova help | grep quota quota-class-show List the quotas for a quota class.
1323 0
|
5G Swift 容器
openstack 命令行管理五 - 磁盘配额管理(备忘)
 磁盘配额由 Swift 1.8 (OpenStack Grizzly) 管理 Container Quotas: Limits the total size (in bytes) or number of objects that can be stored in a single container. Account Quotas: Limits the total size
1732 0