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


目录
相关文章
|
Linux 虚拟化
VMware安装Linux虚拟机之NAT模式网络配置图文详解
VMware安装Linux虚拟机之NAT模式网络配置图文详解
355 0
|
6月前
|
网络协议
虚拟机的三种网络模式
虚拟机的三种网络模式
|
6月前
|
Linux 虚拟化
VMware workstation 中centos7虚拟机在nat模式下怎么配置网卡,指定我想要的IP并且可以联网
https://blog.csdn.net/2302_78534730/article/details/132825156?spm=1001.2014.3001.5502
298 0
|
3月前
|
虚拟化
VMware NAT 模式 虚拟机网络电缆被拔出,连不上网
VMware NAT 模式 虚拟机网络电缆被拔出,连不上网
100 0
|
5月前
|
安全 Linux 网络安全
NAT模式下主机连接虚拟机
NAT模式下主机连接虚拟机,VMware虚拟机系统以CentOS7为例。
153 0
|
5月前
|
存储 安全 测试技术
网络奇谭:虚拟机中的共享、桥接与Host-Only模式解析
网络奇谭:虚拟机中的共享、桥接与Host-Only模式解析
73 0
|
6月前
|
网络安全
虚拟机三种网络模式
虚拟机三种网络模式
|
6月前
|
存储 安全 测试技术
网络奇谭:虚拟机中的共享、桥接与Host-Only模式解析
网络奇谭:虚拟机中的共享、桥接与Host-Only模式解析
119 0
|
监控 安全 Linux
虚拟机CentOS的Nginx+keepalived 高可用集群配置主从模式
虚拟机CentOS的Nginx+keepalived 高可用集群配置主从模式
186 0
|
网络协议 Windows
如何在虚拟机中配置静态IP,以解决在NAT模式下的网络连接问题?
如何在虚拟机中配置静态IP,以解决在NAT模式下的网络连接问题?
272 0