OpenStack Pike : Create Instances2017/09/01 |
Create and Start Virtual Machine Instance.
|
|
[1] | Specify the flavor (memory or disk) and create an instance and boot it. |
# create a flavor root@dlp ~(keystone)# openstack flavor create --id 0 --vcpus 1 --ram 2048 --disk 10 m1.small +----------------------------+----------+ | Field | Value | +----------------------------+----------+ | OS-FLV-DISABLED:disabled | False | | OS-FLV-EXT-DATA:ephemeral | 0 | | disk | 10 | | id | 0 | | name | m1.small | | os-flavor-access:is_public | True | | properties | | | ram | 2048 | | rxtx_factor | 1.0 | | swap | | | vcpus | 1 | +----------------------------+----------+root@dlp ~(keystone)# openstack flavor list +----+----------+------+------+-----------+-------+-----------+ | ID | Name | RAM | Disk | Ephemeral | VCPUs | Is Public | +----+----------+------+------+-----------+-------+-----------+ | 0 | m1.small | 2048 | 10 | 0 | 1 | True | +----+----------+------+------+-----------+-------+-----------+ # show the list of images root@dlp ~(keystone)# openstack image list +--------------------------------------+------------+--------+ | ID | Name | Status | +--------------------------------------+------------+--------+ | b8b5a1f9-914e-4adc-b368-82eb7f573bec | Ubuntu1604 | active | +--------------------------------------+------------+--------+ # show the list of network root@dlp ~(keystone)# openstack network list +--------------------------------+------------+--------------------------------+ | ID | Name | Subnets | +--------------------------------+------------+--------------------------------+ | 8da7f4bc-0bd2-4e9f- | sharednet1 | ed6be86e-2fec- | | bf65-c667c587eff4 | | 498d-a250-b7243bd5ab69 | +--------------------------------+------------+--------------------------------+
root@dlp ~(keystone)#
netID=`openstack network list | grep sharednet1 | awk '{ print $2 }'` # create and boot an instance root@dlp ~(keystone)# openstack server create --flavor m1.small --image Ubuntu1604 --security-group default --nic net-id=$netID Ubuntu_1604 +-------------------------------------+----------------------------------------+ | 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 | Ch85WniiXr3h | | config_drive | | | created | 2017-09-01T07:45:34Z | | flavor | m1.small (0) | | hostId | | | id | 852edd8d-f0d3-4366-8c13-da1a9ea45362 | | image | Ubuntu1604 (b8b5a1f9-914e- | | | 4adc-b368-82eb7f573bec) | | key_name | None | | name | Ubuntu_1604 | | progress | 0 | | project_id | 859896d22f074d16bc67fe7eef6f36db | | properties | | | security_groups | name='default' | | status | BUILD | | updated | 2017-09-01T07:45:34Z | | user_id | f73e3c2f9e7f4eb793a010f60d5b4674 | | volumes_attached | | +-------------------------------------+----------------------------------------+ # show status ([BUILD] status is shown when building instance) root@dlp ~(keystone)# openstack server list +--------------------+-------------+--------+---------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------+-------------+--------+---------------------+------------+ | 852edd8d-f0d3-4366 | Ubuntu_1604 | BUILD | sharednet1=10.0.0.2 | Ubuntu1604 | | -8c13-da1a9ea45362 | | | 10 | | +--------------------+-------------+--------+---------------------+------------+ # when starting noramlly, the status turns to [ACTIVE] root@dlp ~(keystone)# openstack server list +--------------------+-------------+--------+---------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------+-------------+--------+---------------------+------------+ | 852edd8d-f0d3-4366 | Ubuntu_1604 | ACTIVE | sharednet1=10.0.0.2 | Ubuntu1604 | | -8c13-da1a9ea45362 | | | 10 | | +--------------------+-------------+--------+---------------------+------------+ |
[2] | Configure security settings like follows to access with SSH and ICMP. |
# permit ICMP root@dlp ~(keystone)# openstack security group rule create --protocol icmp --ingress default +-------------------+--------------------------------------+ | Field | Value | +-------------------+--------------------------------------+ | created_at | 2017-09-01T05:17:52Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 035a5407-7d7c-4630-bc9d-7d8d16cac16c | | name | None | | port_range_max | None | | port_range_min | None | | project_id | 859896d22f074d16bc67fe7eef6f36db | | protocol | icmp | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 1 | | security_group_id | be5df507-29eb-4deb-8b43-3ce576dd070e | | updated_at | 2017-09-01T05:17:52Z | +-------------------+--------------------------------------+ # permit SSH root@dlp ~(keystone)# openstack security group rule create --protocol tcp --dst-port 22:22 default +-------------------+--------------------------------------+ | Field | Value | +-------------------+--------------------------------------+ | created_at | 2017-09-01T05:18:07Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 21c1dfa9-8705-4630-bc22-8c977dcb25ad | | name | None | | port_range_max | 22 | | port_range_min | 22 | | project_id | 859896d22f074d16bc67fe7eef6f36db | | protocol | tcp | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 1 | | security_group_id | be5df507-29eb-4deb-8b43-3ce576dd070e | | updated_at | 2017-09-01T05:18:07Z | +-------------------+--------------------------------------+root@dlp ~(keystone)# openstack security group rule list +------------+-------------+-----------+------------+-----------------------+----------------+ | ID | IP Protocol | IP Range | Port Range | Remote Security Group | Security Group | +------------+-------------+-----------+------------+-----------------------+----------------+ | 035a5407-7 | icmp | 0.0.0.0/0 | | None | be5df507-29eb- | | d7c-4630 | | | | | 4deb-8b43-3ce5 | | -bc9d-7d8d | | | | | 76dd070e | | 16cac16c | | | | | | | 21c1dfa9-8 | tcp | 0.0.0.0/0 | 22:22 | None | be5df507-29eb- | | 705-4630-b | | | | | 4deb-8b43-3ce5 | | c22-8c977d | | | | | 76dd070e | | cb25ad | | | | | | | 27fdafb0-f | None | None | | be5df507-29eb-4deb- | be5df507-29eb- | | 4f6-4ddc- | | | | 8b43-3ce576dd070e | 4deb-8b43-3ce5 | | b31c-fdee8 | | | | | 76dd070e | | 94fb48d | | | | | | | 3479a490-0 | None | None | | be5df507-29eb-4deb- | be5df507-29eb- | | 766-4eb5 | | | | 8b43-3ce576dd070e | 4deb-8b43-3ce5 | | -aa7e-34a2 | | | | | 76dd070e | | 33c19aa1 | | | | | | | 5f9ae2d4-1 | None | None | | None | be5df507-29eb- | | 366-46b5-9 | | | | | 4deb-8b43-3ce5 | | c51-2ec356 | | | | | 76dd070e | | 8635ac | | | | | | | d8ba5c56-3 | None | None | | None | be5df507-29eb- | | 647-475a-8 | | | | | 4deb-8b43-3ce5 | | 375-5e202d | | | | | 76dd070e | | 838333 | | | | | | +------------+-------------+-----------+------------+-----------------------+----------------+ |
[3] | Login to instance with SSH. |
root@dlp ~(keystone)# openstack server list +--------------------+-------------+--------+---------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------+-------------+--------+---------------------+------------+ | 852edd8d-f0d3-4366 | Ubuntu_1604 | ACTIVE | sharednet1=10.0.0.2 | Ubuntu1604 | | -8c13-da1a9ea45362 | | | 10 | | +--------------------+-------------+--------+---------------------+------------+root@dlp ~(keystone)# ping 10.0.0.210 -c3 PING 10.0.0.210 (10.0.0.210) 56(84) bytes of data. 64 bytes from 10.0.0.210: icmp_seq=1 ttl=64 time=1.46 ms 64 bytes from 10.0.0.210: icmp_seq=2 ttl=64 time=0.661 ms 64 bytes from 10.0.0.210: icmp_seq=3 ttl=64 time=0.573 ms --- 10.0.0.210 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2003ms rtt min/avg/max/mdev = 0.573/0.899/1.464/0.401 ms # SSH login root@dlp ~(keystone)# ssh ubuntu@10.0.0.210 The authenticity of host '10.0.0.210 (10.0.0.210)' can't be established. ECDSA key fingerprint is SHA256:wFP0dngojZ8YTSEmWlq0dpIs/UfSveGbeS0wYyztqF0. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '10.0.0.210' (ECDSA) to the list of known hosts. ubuntu@10.0.0.210's password: # the one you set during installation Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-93-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage Last login: Fri Sep 1 12:34:38 2017ubuntu@ubuntu-1604:~$ # just logined |
[4] | If you using a virtual machine image provided from internet and do not know any password for login, Add SSH key-pair to login like follows. For self-created image, if you installed [cloud-init] package and enable [cloud-init] service in it, it's possible to set SSH key-pair for it. The default user of cloud-init setting for SSH is [ubuntu] user. |
# create key-pair root@dlp ~(keystone)# ssh-keygen -q -N "" Enter file in which to save the key (/root/.ssh/id_rsa): # add public key root@dlp ~(keystone)# openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey +-------------+-------------------------------------------------+ | Field | Value | +-------------+-------------------------------------------------+ | fingerprint | 7c:99:60:16:6e:79:a5:11:fc:71:f5:c2:77:8c:77:77 | | name | mykey | | user_id | f73e3c2f9e7f4eb793a010f60d5b4674 | +-------------+-------------------------------------------------+root@dlp ~(keystone)# openstack keypair list +-------+-------------------------------------------------+ | Name | Fingerprint | +-------+-------------------------------------------------+ | mykey | 7c:99:60:16:6e:79:a5:11:fc:71:f5:c2:77:8c:77:77 | +-------+-------------------------------------------------+ # run instance with key root@dlp ~(keystone)# openstack server create --flavor m1.small --image Ubuntu1604 --security-group default --nic net-id=$netID --key-name mykey Ubuntu_1604_3
openstack server list +------------------+---------------+--------+------------------+------------+ | ID | Name | Status | Networks | Image Name | +------------------+---------------+--------+------------------+------------+ | 4d3ad582-e200-49 | Ubuntu_1604_3 | ACTIVE | sharednet1=10.0. | Ubuntu1604 | | 24-a636-ea86f167 | | | 0.211 | | | b3bf | | | | | +------------------+---------------+--------+------------------+------------+ # login with key root@dlp ~(keystone)# ssh -i mykey ubuntu@10.0.0.211
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-93-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage Last login: Fri Sep 1 12:34:38 2017ubuntu@ubuntu-1604:~$ # just logined
|
[5] | If you'd like to stop an instance, it's also possible to control with openstack command like follows. |
root@dlp ~(keystone)# openstack server list +--------------------+-------------+--------+---------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------+-------------+--------+---------------------+------------+ | 852edd8d-f0d3-4366 | Ubuntu_1604 | ACTIVE | sharednet1=10.0.0.2 | Ubuntu1604 | | -8c13-da1a9ea45362 | | | 10 | | +--------------------+-------------+--------+---------------------+------------+ # stop instance root@dlp ~(keystone)# openstack server stop Ubuntu_1604 root@dlp ~(keystone)# openstack server list +--------------------+-------------+---------+---------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------+-------------+---------+---------------------+------------+ | 852edd8d-f0d3-4366 | Ubuntu_1604 | SHUTOFF | sharednet1=10.0.0.2 | Ubuntu1604 | | -8c13-da1a9ea45362 | | | 10 | | +--------------------+-------------+---------+---------------------+------------+ # start instance root@dlp ~(keystone)# openstack server start Ubuntu_1604 root@dlp ~(keystone)# openstack server list +--------------------+-------------+--------+---------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------+-------------+--------+---------------------+------------+ | 852edd8d-f0d3-4366 | Ubuntu_1604 | ACTIVE | sharednet1=10.0.0.2 | Ubuntu1604 | | -8c13-da1a9ea45362 | | | 10 | | +--------------------+-------------+--------+---------------------+------------+ |
[6] | It's possible to access with Web browser to get VNC console. |
root@dlp ~(keystone)# openstack server list +--------------------+-------------+--------+---------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------+-------------+--------+---------------------+------------+ | 852edd8d-f0d3-4366 | Ubuntu_1604 | ACTIVE | sharednet1=10.0.0.2 | Ubuntu1604 | | -8c13-da1a9ea45362 | | | 10 | | +--------------------+-------------+--------+---------------------+------------+root@dlp ~(keystone)# openstack console url show Ubuntu_1604 +-------+----------------------------------------------------------------------+ | Field | Value | +-------+----------------------------------------------------------------------+ | type | novnc | | url | http://10.0.0.30:6080/vnc_auto.html?token=6e4da98f-e773-4060-ba2b- | | | 89f578083392 | +-------+----------------------------------------------------------------------+ |
[7] | Access to the URL which was displayed by the command above. |
Sponsored Link |
|