OpenStack Train : Create Instances2019/10/25 |
Create and Start Virtual Machine Instance.
|
|
[1] | Login with a user and create a config for authentication of Keystyone. The username or password in the config are just the one you added in keystone like here. Next Create and run an instance. |
[cent@dlp ~]$
vi ~/keystonerc
export OS_PROJECT_DOMAIN_NAME=default
export OS_USER_DOMAIN_NAME=default export OS_PROJECT_NAME=hiroshima export OS_USERNAME=serverworld export OS_PASSWORD=userpassword export OS_AUTH_URL=http://10.0.0.30:5000/v3 export OS_IDENTITY_API_VERSION=3 export OS_IMAGE_API_VERSION=2 export PS1='[\u@\h \W(keystone)]\$ '
[cent@dlp ~]$
chmod 600 ~/keystonerc [cent@dlp ~]$ source ~/keystonerc [cent@dlp ~(keystone)]$ echo "source ~/keystonerc " >> ~/.bash_profile
# show flavor list [cent@dlp ~(keystone)]$ openstack flavor list +----+----------+------+------+-----------+-------+-----------+ | ID | Name | RAM | Disk | Ephemeral | VCPUs | Is Public | +----+----------+------+------+-----------+-------+-----------+ | 0 | m1.small | 2048 | 10 | 0 | 1 | True | +----+----------+------+------+-----------+-------+-----------+ # show image list [cent@dlp ~(keystone)]$ openstack image list +--------------------------------------+---------+--------+ | ID | Name | Status | +--------------------------------------+---------+--------+ | c742c8ed-9d0f-4555-9844-7f063a0b585f | CentOS7 | active | +--------------------------------------+---------+--------+ # show network list [cent@dlp ~(keystone)]$ openstack network list +--------------------------------------+------------+--------------------------------------+ | ID | Name | Subnets | +--------------------------------------+------------+--------------------------------------+ | 7ee2f2bc-b93c-4c09-8d7e-ea8b3f0a1d9d | sharednet1 | dc8ecae8-5536-4fe4-a4ed-52af28bbae34 | +--------------------------------------+------------+--------------------------------------+ # create a security group for instances [cent@dlp ~(keystone)]$ openstack security group create secgroup01 +-----------------+-------------------------------------------------------------------------------+ | Field | Value | +-----------------+-------------------------------------------------------------------------------+ | created_at | 2019-10-25T05:20:14Z | | description | secgroup01 | | id | 01c09567-055e-41f0-b01a-9466186dbc80 | | location | cloud='', project.domain_id=, project.domain_name='default', project.id='67...| | name | secgroup01 | | project_id | 67b2b71cee384d69939e6b3963e0b2db | | revision_number | 1 | | rules | created_at='2019-10-25T05:20:14Z', direction='egress', ethertype='IPv4', id...| | | created_at='2019-10-25T05:20:14Z', direction='egress', ethertype='IPv6', id...| | tags | [] | | updated_at | 2019-10-25T05:20:14Z | +-----------------+-------------------------------------------------------------------------------+[cent@dlp ~(keystone)]$ openstack security group list +--------------------------------------+------------+------------------------+----------------------------------+------+ | ID | Name | Description | Project | Tags | +--------------------------------------+------------+------------------------+----------------------------------+------+ | 01c09567-055e-41f0-b01a-9466186dbc80 | secgroup01 | secgroup01 | 67b2b71cee384d69939e6b3963e0b2db | [] | | 56c159ec-8ff6-4859-a27b-b919a415af8c | default | Default security group | 67b2b71cee384d69939e6b3963e0b2db | [] | +--------------------------------------+------------+------------------------+----------------------------------+------+ # create a SSH keypair for connecting to instances [cent@dlp ~(keystone)]$ ssh-keygen -q -N "" Enter file in which to save the key (/home/cent/.ssh/id_rsa): # add public-key [cent@dlp ~(keystone)]$ openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey +-------------+-------------------------------------------------+ | Field | Value | +-------------+-------------------------------------------------+ | fingerprint | d5:92:85:8b:8a:ae:8a:e7:9b:6e:a3:cc:eb:e7:1d:10 | | name | mykey | | user_id | 14ad73cc98744e01a51886e13d541013 | +-------------+-------------------------------------------------+[cent@dlp ~(keystone)]$ openstack keypair list +-------+-------------------------------------------------+ | Name | Fingerprint | +-------+-------------------------------------------------+ | mykey | d5:92:85:8b:8a:ae:8a:e7:9b:6e:a3:cc:eb:e7:1d:10 | +-------+-------------------------------------------------+
[cent@dlp ~(keystone)]$
netID=$(openstack network list | grep sharednet1 | awk '{ print $2 }') # create and boot an instance [cent@dlp ~(keystone)]$ openstack server create --flavor m1.small --image CentOS7 --security-group secgroup01 --nic net-id=$netID --key-name mykey CentOS_7
+-----------------------------+------------------------------------------------+ | Field | Value | +-----------------------------+------------------------------------------------+ | OS-DCF:diskConfig | MANUAL | | OS-EXT-AZ:availability_zone | | | 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 | 9MQ7bXx29npr | | config_drive | | | created | 2019-10-25T05:21:43Z | | flavor | m1.small (0) | | hostId | | | id | 3c9b79b5-b97b-406d-93ed-9871f22eb38e | | image | CentOS7 (c742c8ed-9d0f-4555-9844-7f063a0b585f) | | key_name | mykey | | name | CentOS_7 | | progress | 0 | | project_id | 67b2b71cee384d69939e6b3963e0b2db | | properties | | | security_groups | name='01c09567-055e-41f0-b01a-9466186dbc80' | | status | BUILD | | updated | 2019-10-25T05:21:43Z | | user_id | 14ad73cc98744e01a51886e13d541013 | | volumes_attached | | +-----------------------------+------------------------------------------------+ # show status ([BUILD] status is shown when building instance) [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+----------+--------+----------+---------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+----------+--------+----------+---------+----------+ | 3c9b79b5-b97b-406d-93ed-9871f22eb38e | CentOS_7 | BUILD | | CentOS7 | m1.small | +--------------------------------------+----------+--------+----------+---------+----------+ # when starting noramlly, the status turns to [ACTIVE] [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+----------+--------+-----------------------+---------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+----------+--------+-----------------------+---------+----------+ | 3c9b79b5-b97b-406d-93ed-9871f22eb38e | CentOS_7 | ACTIVE | sharednet1=10.0.0.233 | CentOS7 | m1.small | +--------------------------------------+----------+--------+-----------------------+---------+----------+ |
[2] | Configure security settings for the security group you created above to access with SSH and ICMP. |
# permit ICMP [cent@dlp ~(keystone)]$ openstack security group rule create --protocol icmp --ingress secgroup01 +-------------------+-----------------------------------------------------------------------------+ | Field | Value | +-------------------+-----------------------------------------------------------------------------+ | created_at | 2019-10-25T05:23:02Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | a18174d5-d3e0-43af-b619-0d91edd555eb | | location | cloud='', project.domain_id=, project.domain_name='default', project.id='...| | name | None | | port_range_max | None | | port_range_min | None | | project_id | 67b2b71cee384d69939e6b3963e0b2db | | protocol | icmp | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 0 | | security_group_id | 01c09567-055e-41f0-b01a-9466186dbc80 | | tags | [] | | updated_at | 2019-10-25T05:23:02Z | +-------------------+-----------------------------------------------------------------------------+ # permit SSH [cent@dlp ~(keystone)]$ openstack security group rule create --protocol tcp --dst-port 22:22 secgroup01 +-------------------+------------------------------------------------------------------------------+ | Field | Value | +-------------------+------------------------------------------------------------------------------+ | created_at | 2019-10-25T05:23:34Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 299768ac-b412-4f2a-ad78-e86b2428ed71 | | location | cloud='', project.domain_id=, project.domain_name='default', project.id='6...| | name | None | | port_range_max | 22 | | port_range_min | 22 | | project_id | 67b2b71cee384d69939e6b3963e0b2db | | protocol | tcp | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 0 | | security_group_id | 01c09567-055e-41f0-b01a-9466186dbc80 | | tags | [] | | updated_at | 2019-10-25T05:23:34Z | +-------------------+------------------------------------------------------------------------------+[cent@dlp ~(keystone)]$ openstack security group rule list +--------------------------------------+-------------+-----------+-----------+------------+--------------------------------------+--------------------------------------+ | ID | IP Protocol | Ethertype | IP Range | Port Range | Remote Security Group | Security Group | +--------------------------------------+-------------+-----------+-----------+------------+--------------------------------------+--------------------------------------+ | 13c7878c-cabd-413f-b8ec-09dc1b24b171 | None | IPv6 | ::/0 | | None | 56c159ec-8ff6-4859-a27b-b919a415af8c | | 175d58d2-5610-47b2-80b3-9c0565fc70d4 | None | IPv4 | 0.0.0.0/0 | | None | 01c09567-055e-41f0-b01a-9466186dbc80 | | 1c49618e-a2a0-462c-b96d-fa3a38e3f81e | None | IPv4 | 0.0.0.0/0 | | None | 56c159ec-8ff6-4859-a27b-b919a415af8c | | 299768ac-b412-4f2a-ad78-e86b2428ed71 | tcp | IPv4 | 0.0.0.0/0 | 22:22 | None | 01c09567-055e-41f0-b01a-9466186dbc80 | | a18174d5-d3e0-43af-b619-0d91edd555eb | icmp | IPv4 | 0.0.0.0/0 | | None | 01c09567-055e-41f0-b01a-9466186dbc80 | | adc74741-2df4-4f2e-92a6-b0349573e12b | None | IPv6 | ::/0 | | 56c159ec-8ff6-4859-a27b-b919a415af8c | 56c159ec-8ff6-4859-a27b-b919a415af8c | | eb6b34cf-c921-43d1-bc0a-8407aa2dd18e | None | IPv4 | 0.0.0.0/0 | | 56c159ec-8ff6-4859-a27b-b919a415af8c | 56c159ec-8ff6-4859-a27b-b919a415af8c | | fb5bb278-2db1-41fd-8d4a-c36c36729e8a | None | IPv6 | ::/0 | | None | 01c09567-055e-41f0-b01a-9466186dbc80 | +--------------------------------------+-------------+-----------+-----------+------------+--------------------------------------+--------------------------------------+ |
[3] | Login to the instance with SSH. |
[cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+----------+--------+-----------------------+---------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+----------+--------+-----------------------+---------+----------+ | 3c9b79b5-b97b-406d-93ed-9871f22eb38e | CentOS_7 | ACTIVE | sharednet1=10.0.0.233 | CentOS7 | m1.small | +--------------------------------------+----------+--------+-----------------------+---------+----------+[cent@dlp ~(keystone)]$ ping 10.0.0.233 -c3 PING 10.0.0.233 (10.0.0.233) 56(84) bytes of data. 64 bytes from 10.0.0.233: icmp_seq=1 ttl=64 time=0.607 ms 64 bytes from 10.0.0.233: icmp_seq=2 ttl=64 time=0.764 ms 64 bytes from 10.0.0.233: icmp_seq=3 ttl=64 time=0.490 ms --- 10.0.0.233 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2000ms rtt min/avg/max/mdev = 0.490/0.620/0.764/0.114 ms[cent@dlp ~(keystone)]$ ssh centos@10.0.0.233
The authenticity of host '10.0.0.233 (10.0.0.233)' can't be established.
ECDSA key fingerprint is SHA256:8Mxh+vSFka75QgGaBO/RGWYnFNAOtdgw9q3OQv+QaJw.
ECDSA key fingerprint is MD5:7c:f3:35:bf:ab:01:d7:d0:98:a3:2b:2d:04:11:74:56.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.233' (ECDSA) to the list of known hosts.
[centos@centos-7 ~]$ # just logined |
[4] | If you'd like to stop an instance, it's also possible to control with openstack command like follows. |
[cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+----------+--------+-----------------------+---------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+----------+--------+-----------------------+---------+----------+ | 3c9b79b5-b97b-406d-93ed-9871f22eb38e | CentOS_7 | ACTIVE | sharednet1=10.0.0.233 | CentOS7 | m1.small | +--------------------------------------+----------+--------+-----------------------+---------+----------+ # stop instance [cent@dlp ~(keystone)]$ openstack server stop CentOS_7 [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+----------+---------+-----------------------+---------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+----------+---------+-----------------------+---------+----------+ | 3c9b79b5-b97b-406d-93ed-9871f22eb38e | CentOS_7 | SHUTOFF | sharednet1=10.0.0.233 | CentOS7 | m1.small | +--------------------------------------+----------+---------+-----------------------+---------+----------+ # start instance [cent@dlp ~(keystone)]$ openstack server start CentOS_7 [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+----------+--------+-----------------------+---------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+----------+--------+-----------------------+---------+----------+ | 3c9b79b5-b97b-406d-93ed-9871f22eb38e | CentOS_7 | ACTIVE | sharednet1=10.0.0.233 | CentOS7 | m1.small | +--------------------------------------+----------+--------+-----------------------+---------+----------+ |
[5] | It's possible to access with Web browser to get VNC console. |
[cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+----------+--------+-----------------------+---------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+----------+--------+-----------------------+---------+----------+ | 3c9b79b5-b97b-406d-93ed-9871f22eb38e | CentOS_7 | ACTIVE | sharednet1=10.0.0.233 | CentOS7 | m1.small | +--------------------------------------+----------+--------+-----------------------+---------+----------+[cent@dlp ~(keystone)]$ openstack console url show CentOS_7 +-------+------------------------------------------------------------------------------------------+ | Field | Value | +-------+------------------------------------------------------------------------------------------+ | type | novnc | | url | http://10.0.0.30:6080/vnc_auto.html?path=%3Ftoken%3D2b431b69-c9b5-41aa-8672-6e0b6615db52 | +-------+------------------------------------------------------------------------------------------+ |
[6] | Access to the URL which was displayed by the command above. |
Sponsored Link |
|