How to Create an Instance (VM) via Command line in OpenStack
如何通过命令行在OpenStack中创建VM实例
by Pradeep Kumar · January 28, 2020
普挼蒂噗·库玛,2020年1月28日
Translated By Manpo Teng
翻译:孟伯
As we all of know that Openstack is getting popular day by day. Most of the organizations are moving their IT infrastructure from traditional virtualization to the private cloud like OpenStack. Openstack is available in two versions:
众所周知,Openstack正处于日渐流行的状态。大部分组织正试图把他们的IT基础设施从传统的虚拟化产品上迁移到诸如OpenStack的私有云平台上。OpenStack有两种可用版本:
Community OpenStack – As the name suggests, it is an open source and community based private cloud. Community usually release new version of openstack in every 6 months
Enterprise OpenStack – As the name suggests, it is commercial openstack, different vendors created their own openstack like Red hat has its own RHOSP ( Red Hat Openstack Platform), Mirantis Openstack, Canonical OpenStack, SUSE OpenStack Cloud and VIO (VMware Integrated OpenStack).
OpenStack社区版:顾名思义,它是一个开源的、由社区驱动的私有云项目。通常每6个月社区就会释放出一个新版本。
OpenStack企业版:顾名思义,它是一个商业化支持的产品,不同的OpenStack服务供应商提供了不同的类OpenStack产品,例如红帽公司的Red Hat Openstack Platform、Mirantis Openstack、 Canonical OpenStack、SUSE OpenStack Cloud、VMware Integrated OpenStack【还包括惠普的Hewlett-Packard】。
Being a cloud administrator we generally create and delete virtual machines from GUI (Horizon dashboard). But a Linux geek always prefer to use command line to do all day to day openstack operations task, so in this article I will demonstrate how to create and delete virtual machine from the command line.
作为云平台管理员,我们通常借助GUI(如Horizon面板)来创建和删除虚拟机。然而,Linux痴迷者更喜欢用命令行来完成OpenStack的日常运维工作。一次,在这篇教程中我将演示如何通过命令行来创建和删除虚拟机。
Creating Virtual Machine from command Line
从命令行创建虚拟机
To create virtual machine from command line, first login to the controller node. Create a project credential file. In this tutorial I will be using non production project credential.
要从命令行创建虚拟机,首先得登录到控制节点。创建一个项目凭证文件。在这篇教程中,我将使用非生产环境项目凭证。
# source keystone_linuxtechi_rc
First find the following details using openstack command, we would required these details during the creation of virtual machine.
首先使用OpenStack命令行列出以下详情,在创建虚拟机的过程中我们需要用到它们。
Flavor
Image
Network
Security Group
Key Name
Get the flavor list using below openstack command:
使用下述命令列出flavor清单:
# openstack flavor list
Get the image name and its id:
获取镜像名称及唯一标识【此处筛选了镜像cirros】:
# openstack image list | grep cirros
Get Private Virtual network details, which will be attached to the VM:
获取私有虚拟网络详情,这将被添加到VM上:
# openstack network list | grep -i nonprod
Find the Security Group:
列出安全组信息【此处筛选了安全组SG】:
# openstack security group list | grep SG
Find the Key pair, in my case I have below :
列出秘钥对,我自己的信息如下:
# openstack keypair list | grep -i linuxtechi
Note: Above details will be different for you based on your project and env.
注意:以上详情会因你的项目及环境不同而不同。
Now we have all the details, let’s create a virtual machine using “openstack server create” command
现在我们拿到了足够的项目详情,让我们使用“openstack server create”管理命令创建虚拟机吧:
Syntax :
命令语法格式:
openstack server create --flavor {约束模板名称} --image {镜像名称或其唯一标识} --nic net-id={网络唯一标识} --security-group {安全组唯一标识} –key-name {秘钥对名称} <虚拟机实例名>
Example:
示例:
openstack server create --flavor m1.tiny --image cirros --nic net-id=e0be93b8-728b-4d4d-a272-7d672b2560a6 --security-group LinuxTechi_SG --key-name linuxtechi pkumar_test_vm
Note : To get more help on “openstack server create” command , use:# openstack -h server create
注意:获取更多帮助,请使用命令“openstack -h server create”
Now Verify the test vm status using below commands:
现在用以下命令验证VM test:
# openstack server list | grep pkumar 或 # openstack server show pkumar_test_vm
Associating a Floating IP to VM
为VM关联浮动IP
To Associate a floating IP to VM, first get the unused floating IP using beneath command:
要关联浮动IP,首先得通过下面的命令获取到未使用的浮动IP:
# openstack ip floating list | grep None | head -2
Now Associate the first IP to the server using following command:
现在用下述命令为VM关联第一个浮动IP:
# openstack ip floating add 169.144.107.154 pkumar_test_vm
Use the beneath command to verify whether floating ip is assigned to the VM or not:
使用下面的命令验证浮动IP是否已经关联到了VM上:
# openstack server list | grep pkumar_test_vm
Now you can access this VM from outside using the floating IP.
现在可以从外网通过浮动IP访问VM了。
Create a Virtual machine in Specific Availability zone and compute Host
在特定区域的主机上创建VM
Let’s assume we want to create a test VM on compute-02 in NonProduction Availability Zone. To accomplish this pass “–availability-zone” parameter in openstack server create command,
假设我们将要创建的VM位于非生产可用区域的compute-02
Syntax would be something like below:
命令语法格式如下:
# openstack server create --flavor {约束模板名称} --image {镜像名称或其唯一标识} --nic net-id={网络唯一标识} --security-group {安全组唯一标识} --key-name {秘钥对名称} --availability-zone {可用区域名称}:{主机名} <虚拟机实例名>
示例:
# openstack server create --flavor m1.tiny --image cirros --nic net-id=e0be93b8-728b-4d4d-a272-7d672b2560a6 --security-group LinuxTechi_SG --key-name linuxtechi --availability-zone NonProduction:compute-02 nonprod_test_vm
Deleting Virtual Machine from Command Line
从命令行删除虚拟机
Use “openstack server delete” command to delete the virtual machines, let’s assume we want to delete above created test vm.
使用“openstack server delete”命令删除虚拟机,假设我们想要删除内的虚拟机就是前述创建的那台VM。
# openstack server delete pkumar_test_vm
This conclude our article, I hope you got basic idea on how to create and delete virtual machine from command line in openstack.
行文至此,希望读者能对在OpenStack中如何通过命令行创建和删除虚拟机有所了解。
原文:https://www.linuxtechi.com/create-delete-virtual-machine-command-line-openstack/
孟伯,20200312
交流联系:WeChat 1807479153;QQ 1807479153 ;Phone:177 3781 5124