我们一台虚拟机需要的东西不多,大小、镜像、网络以及安全组。所以我们就只需要查出这些配置信息,然后就可以创建虚拟机了,这里指定IP地址和生成节点。
说明一下,本人是利用公司里docker容器里部署的openstack,所以在创建之前,先用命令行进入相应容器中:
docker exec -it -u 0 neutron-server /bin/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名字
C919 #新建虚拟机的名字
如下图:
这样就把一台虚拟机创建出来了,是不是很简单呢,我们创建完成后可以使用nova list看一下虚拟机的列表:
附录
附录提供了nova boot用法相关的参数
[root@controller ~]# nova help boot
usage: nova boot [–flavor
[–image-with
[–snapshot
[–meta
[–key-name
[–availability-zone
[–security-groups
[–block-device-mapping
[–block-device key1=value1[,key2=value2…]]
[–swap
[–ephemeral size=
[–hint
[–nic
[–config-drive
Boot a new server.
Positional arguments:
Optional arguments:
–flavor
–image
–image-with
Image metadata property (see ‘nova image-show’).
–boot-volume
Volume ID to boot from.
–snapshot
Snapshot ID to boot from (will create a volume).
–num-instances
boot multiple servers at a time (limited by quota).
–meta
new server. Can be specified multiple times.
–file
Store arbitrary files from
path> on the new server. You may store up to 5 files.
–key-name
Key name of keypair that should be created earlier
with the command keypair-add
–user-data
user data file to pass to be exposed by the metadata
server.
–availability-zone
The availability zone for server placement.
–security-groups
Comma separated list of security group names.
–block-device-mapping
Block device mapping in the format
name>=
–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
–ephemeral size=
Create and attach a local ephemeral block device of
–hint
custom use.
–nic
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
Enable config drive
–poll Blocks while server builds so progress can be
reported.