How to manually create a virtual machine on the control node of openstack

Source: Internet
Author: User

Although you can use dashbord to create a new virtual machine, it is also a good way to use commands to create a virtual machine.

1. Activate environment variables.

This step is unnecessary if it is activated.

Create File novarc

export OS_TENANT_NAME=adminexport OS_USERNAME=adminexport OS_PASSWORD=123456export OS_AUTH_URL="http://10.214.0.179:5000/v2.0/"

Execute scripts

Source novarc

2. Download or create your own virtual machine image.

You can refer to the vpsee blog or download it from the official website. Http://cloud-images.ubuntu.com/lucid/current/

3. Upload the image.

glance add name="ubuntu rubis" is_public=true container_format=vof disk_format=vhd < /root/images/disk.img

PS: (optional) script:

Create File upimage. Sh

Image_name = 'quantal-server-cloudimg-amd64 '# change to the name of your downloaded image echo "upload images" mkdir-P/tmp/imagestar-zxf. /export image_name.tar.gz-C/tmp/imagesrval = 'glance Add name = "ubuntu-10.04.2-kernel" is_public = true container_format = Aki disk_format = Aki </tmp/images/$ IMAGE_NAME-vmlinuz * 'kernel _ id = 'echo $ rval | cut-d ": "-F2 | tr-d" "'glance Add name =" ubuntu-10.04.2 "is_public = true container_format = AMI disk_format = AMI kernel_id = $ kernel_id </tmp/images/$ image_name.img

Run the script sh upimage. Sh.

Note:

The actual location of the image on the physical machine:

root@nova-controller:/var/lib/glance#lsglance.sqlite  image-cache images

4. Create a virtual machine key pair.

root@nova-controller:/var/lib/stackops# ssh-keygen Generating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa): /root/.ssh/id_rsa2Created directory '/root/.ssh'.Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa2.Your public key has been saved in /root/.ssh/id_rsa2.pub.The key fingerprint is:46:ef:fa:ee:46:f4:7f:82:37:b9:e4:fe:39:2e:3e:30 root@nova-controllerThe key's randomart image is:+--[ RSA 2048]----+|                 ||                 ||        .        ||       . ..      ||        S...     ||       . ..E.    ||         .. oo.. ||         .. .=*.o||        .=+ .+BOo|+-----------------+

5. Import key

root@nova-controller:/var/lib/stackops# nova keypair-listroot@nova-controller:~# nova keypair-add --pub_key .ssh/id_rsa2.pub key2

6. view images

root@nova-controller:~# nova image-list+----+-----------------------+--------+| ID |          Name         | Status |+----+-----------------------+--------+| 1  | ubuntu-10.04.2-kernel | ACTIVE || 2  | ubuntu-10.04.2        | ACTIVE |+----+-----------------------+--------+

7. View VM specifications

root@nova-controller:~# nova flavor-list+----+-----------+-----------+------+----------+-------+------------+----------+| ID |    Name   | Memory_MB | Swap | Local_GB | VCPUs | RXTX_Quota | RXTX_Cap |+----+-----------+-----------+------+----------+-------+------------+----------+| 1  | m1.tiny   | 512       | 0    | 0        | 1     | 0          | 0        || 2  | m1.small  | 2048      | 0    | 20       | 1     | 0          | 0        || 3  | m1.medium | 4096      | 0    | 40       | 2     | 0          | 0        || 4  | m1.large  | 8192      | 0    | 80       | 4     | 0          | 0        || 5  | m1.xlarge | 16384     | 0    | 160      | 8     | 0          | 0        |+----+-----------+-----------+------+----------+-------+------------+----------+

8. Create a virtual machine

root@nova-controller:~# nova boot --flavor  1 --image 2 --key_name key2 Secondvmzju+--------------+--------------------------------------+|   Property   |                Value                 |+--------------+--------------------------------------+| accessIPv4   |                                      || accessIPv6   |                                      || adminPass    | SgoPBBCaaN5BumLA                     || config_drive |                                      || created      | 2012-06-22T19:14:17Z                 || flavor       | m1.tiny                              || hostId       |                                      || id           | 1                                    || image        | ubuntu-10.04.2                       || key_name     | key2                                 || metadata     | {}                                   || name         | Secondvmzju                          || progress     | 0                                    || status       | BUILD                                || tenant_id    | 1                                    || updated      | 2012-06-22T19:14:17Z                 || user_id      | admin                                || uuid         | 4cf112db-5db2-4e1a-af5a-219689a11300 |+--------------+--------------------------------------+

-- Flavor: Specifies the specification of the VM.

-- Image: Specifies the image to be used.

-- Key_name: Specifies the key used.

"Secondvmzju" is the virtual machine name.

(One image can create multiple virtual machines, but your image is in qcow2 format .)

9. view the newly created Virtual Machine

root@nova-controller:~# nova show Secondvmzju+-----------------+----------------------------------------------------------+|     Property    |                          Value                           |+-----------------+----------------------------------------------------------+| accessIPv4      |                                                          || accessIPv6      |                                                          || config_drive    |                                                          || created         | 2012-06-22T19:14:17Z                                     || flavor          | m1.tiny                                                  || hostId          | 28aabad0d319fc4dc6bd5a1f0d496229ee46648ec74f45fd7084047d || id              | 1                                                        || image           | ubuntu-10.04.2                                           || key_name        | key2                                                     || metadata        | {}                                                       || name            | Secondvmzju                                              || progress        | 100                                                      || service network | 10.0.0.2                                                 || status          | ACTIVE                                                   || tenant_id       | 1                                                        || updated         | 2012-07-05T11:32:19Z                                     || user_id         | admin                                                    || uuid            | 4cf112db-5db2-4e1a-af5a-219689a11300                     |+-----------------+----------------------------------------------------------+

10. Network Configuration

Configure the network for the Virtual Machine (optional ).

View the IP address used by the public network: root @ Nova-Controller :~ # Nova floating-IP-list + ------------- + ----------- + ---------- + | IP | instance id | fixed IP | + ------------- + ---------- + | 192.168.1.1 | none | 192.168.1.2 | 1 | 10.0.0.2 | + ------------- + ---------- + create a public address root @ Nova-controller: ~ # Nova floating-IP-create + ------------- + ----------- + ---------- + | IP | instance id | fixed IP | + ------------- + ---------- + | 192.168.1.2 | none | + ------------- + ------------- + ---------- + bind the public IP address to the VM root @ Nova-controller: ~ # Nova add-Floating-IP secondvmzju 192.168.1.2 check the VM again. Pay attention to servicenetworkroot @ Nova-Controller :~ # NOVA show secondvmzju + ----------------- + dimensions + | property | value | + --------------- + dimensions + | accessipv4 | accessipv6 | config_drive | created | 2012-06-22t19: 14: 17z | flavor | m1.tiny | hostid | 28aabad0d319fc4dc6bd5a1f0d496229ee46648ec74f45fd7084047d | ID | 1 | image | ubuntu-10. 04.2 | key_name | key2 | metadata | {}| | Name | secondvmzju | progress | 100 | Service Network | 10.0.0.2, 192.168.1.2 | status | active | tenant_id | 1 | updated | 2012-07-05t11: 32: 19z | user_id | admin | UUID | + --------------- + Firewall settings: allow SSH: root @ Nova-Controller :~ # Nova secgroup-add-Rule default TCP 22 0.0.0.0/0 + --------------- + ----------- + --------- + ----------- + -------------- + | IP protocol | from Port | to port | IP Range | source Group | + accept + ----------- + --------- + ----------- + -------------- + | TCP | 22 | 22 | 0.0.0.0/0 | + accept + ----------- + --------- + ----------- + -------------- + allow pingroot @-Nova- controller: ~ # Nova secgroup-add-Rule default ICMP-1-1 0.0.0.0/0 + ------------- + ----------- + --------- + ----------- + -------------- + | IP protocol | from Port | to port | IP Range | source group | + ------------- + ----------- + --------- + ----------- + -------------- + | ICMP |-1 |-1 | 0.0.0.0/0 | + accept + ----------- + --------- + ----------- + View firewall Rules: root @ Nova-Controller :~ # Nova secgroup-list-rules default + --------------- + ----------- + --------- + ----------- + -------------- + | IP protocol | from Port | to port | IP Range | source group | + ------------- + ----------- + --------- + ----------- + ------------ + | ICMP |-1 |-1 | 0.0.0.0/0 | TCP | 22 | 22 | 0.0.0.0/0 | + ------------- + ----------- + --------- + ----------- + -------------- +

11. Connect to the Virtual Machine

Connect to (enter) a VM Using SSH
Ssh-I logs on through authentication files.

root@nova-controller:~# ssh -i .ssh/id_rsa2 ubuntu@10.0.0.2The authenticity of host '10.0.0.2 (10.0.0.2)' can't be established.RSA key fingerprint is aa:fc:78:9a:bd:6d:f3:bb:67:cd:28:15:b5:06:fb:c8.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added '10.0.0.2' (RSA) to the list of known hosts.

You can view the Virtual Machine name, which is the name set at the time of creation.

ubuntu@secondvmzju:~$ hostnamesecondvmzjuubuntu@secondvmzju:~$

12. Remarks

You can use virsh to manage virtual machines on computing nodes (however, Nova is recommended ).

root@nova-compute-1:~# virsh list --all Id Name                 State----------------------------------  1 instance-00000001    running

The actual location of the instance on the computing node:

root@nova-compute-1:/var/lib/nova/instances# ls_base  instance-00000001

You can unbind the public IP from the virtual machine.

Root @ Nova-Controller :~ # Nova remove-Floating-IP secondvmzju 192.168.1.2 reclaim the IP address. Root @ Nova-Controller :~ # Nova floating-IP-delete 192.168.1.2

References:

Http://www.slideshare.net/slmagicbox/stackops-step-bystep-guide

Http://docs.stackops.org/display/doc03/Operating+Openstack+with+Stackops+Distro

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.