OpenStack Wallaby : Create Instances2021/04/22 |
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 available [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 available image list [cent@dlp ~(keystone)]$ openstack image list +--------------------------------------+-----------------+--------+ | ID | Name | Status | +--------------------------------------+-----------------+--------+ | a7f1ad19-4d09-498c-8152-404bf626af98 | CentOS-Stream-8 | active | +--------------------------------------+-----------------+--------+ # show available network list [cent@dlp ~(keystone)]$ openstack network list +--------------------------------------+------------+--------------------------------------+ | ID | Name | Subnets | +--------------------------------------+------------+--------------------------------------+ | a174e1f9-ecf7-437b-b31e-9c37f164ec76 | sharednet1 | b4a9ceeb-2b79-48c0-9799-0965fbd6f77a | +--------------------------------------+------------+--------------------------------------+ # create a security group for instances [cent@dlp ~(keystone)]$ openstack security group create secgroup01 +-----------------+-------------------------------------------------------------------------------+ | Field | Value | +-----------------+-------------------------------------------------------------------------------+ | created_at | 2021-04-22T05:24:42Z | | description | secgroup01 | | id | f93ac919-bc4b-442f-a601-79b1f4c20cc5 | | name | secgroup01 | | project_id | 9bdf6ca0e49a416da8df5554fbfdec74 | | revision_number | 1 | | rules | created_at='2021-04-22T05:24:42Z', direction='egress', ethertype='IPv4',..... | | | created_at='2021-04-22T05:24:42Z', direction='egress', ethertype='IPv6',..... | | stateful | True | | tags | [] | | updated_at | 2021-04-22T05:24:42Z | +-----------------+-------------------------------------------------------------------------------+[cent@dlp ~(keystone)]$ openstack security group list +--------------------------------------+------------+------------------------+----------------------------------+------+ | ID | Name | Description | Project | Tags | +--------------------------------------+------------+------------------------+----------------------------------+------+ | 9f58ed95-4a13-4580-bcca-8fe4dd562a89 | default | Default security group | 9bdf6ca0e49a416da8df5554fbfdec74 | [] | | f93ac919-bc4b-442f-a601-79b1f4c20cc5 | secgroup01 | secgroup01 | 9bdf6ca0e49a416da8df5554fbfdec74 | [] | +--------------------------------------+------------+------------------------+----------------------------------+------+ # 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 | +-------------+-------------------------------------------------+ | created_at | None | | fingerprint | e9:e1:7e:6e:7f:53:70:8d:28:2c:4e:78:30:80:e2:47 | | id | mykey | | is_deleted | None | | name | mykey | | type | ssh | | user_id | b7aeb44b614d46f69b4a53ecee906800 | +-------------+-------------------------------------------------+[cent@dlp ~(keystone)]$ openstack keypair list +-------+-------------------------------------------------+------+ | Name | Fingerprint | Type | +-------+-------------------------------------------------+------+ | mykey | e9:e1:7e:6e:7f:53:70:8d:28:2c:4e:78:30:80:e2:47 | ssh | +-------+-------------------------------------------------+------+
[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 CentOS-Stream-8 --security-group secgroup01 --nic net-id=$netID --key-name mykey CentOS-St-8
+-----------------------------+--------------------------------------------------------+ | 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 | 5GJ7vYZzu6bg | | config_drive | | | created | 2021-04-22T05:27:10Z | | flavor | m1.small (0) | | hostId | | | id | 2b04dc33-aff9-4e55-8f09-d2156f7a6660 | | image | CentOS-Stream-8 (a7f1ad19-4d09-498c-8152-404bf626af98) | | key_name | mykey | | name | CentOS-St-8 | | progress | 0 | | project_id | 9bdf6ca0e49a416da8df5554fbfdec74 | | properties | | | security_groups | name='f93ac919-bc4b-442f-a601-79b1f4c20cc5' | | status | BUILD | | updated | 2021-04-22T05:27:10Z | | user_id | b7aeb44b614d46f69b4a53ecee906800 | | volumes_attached | | +-----------------------------+--------------------------------------------------------+ # show status ([BUILD] status is shown when building instance) [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+-------------+--------+----------+-----------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-------------+--------+----------+-----------------+----------+ | 2b04dc33-aff9-4e55-8f09-d2156f7a6660 | CentOS-St-8 | BUILD | | CentOS-Stream-8 | m1.small | +--------------------------------------+-------------+--------+----------+-----------------+----------+ # when starting noramlly, the status turns to [ACTIVE] [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+-------------+--------+-----------------------+-----------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-------------+--------+-----------------------+-----------------+----------+ | 2b04dc33-aff9-4e55-8f09-d2156f7a6660 | CentOS-St-8 | ACTIVE | sharednet1=10.0.0.210 | CentOS-Stream-8 | 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 | 2021-04-22T05:28:19Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 9543774f-4244-4702-8bbd-f81663706511 | | name | None | | port_range_max | None | | port_range_min | None | | project_id | 9bdf6ca0e49a416da8df5554fbfdec74 | | protocol | icmp | | remote_address_group_id | None | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 0 | | security_group_id | f93ac919-bc4b-442f-a601-79b1f4c20cc5 | | tags | [] | | updated_at | 2021-04-22T05:28:19Z | +-------------------------+--------------------------------------+ # permit SSH [cent@dlp ~(keystone)]$ openstack security group rule create --protocol tcp --dst-port 22:22 secgroup01 +-------------------------+--------------------------------------+ | Field | Value | +-------------------------+--------------------------------------+ | created_at | 2021-04-22T05:28:51Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 43aa0950-5e61-4d02-b00d-880cff09c194 | | name | None | | port_range_max | 22 | | port_range_min | 22 | | project_id | 9bdf6ca0e49a416da8df5554fbfdec74 | | protocol | tcp | | remote_address_group_id | None | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 0 | | security_group_id | f93ac919-bc4b-442f-a601-79b1f4c20cc5 | | tags | [] | | updated_at | 2021-04-22T05:28:51Z | +-------------------------+--------------------------------------+[cent@dlp ~(keystone)]$ openstack security group rule list secgroup01 +--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+ | ID | IP Protocol | Ethertype | IP Range | Port Range | Direction | Remote Security Group | Remote Address Group | +--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+ | 43aa0950-5e61-4d02-b00d-880cff09c194 | tcp | IPv4 | 0.0.0.0/0 | 22:22 | ingress | None | None | | 6baaacef-4045-4e1d-8180-0fca158d91bb | None | IPv4 | 0.0.0.0/0 | | egress | None | None | | 7241a8aa-e3e3-4dfc-8e5b-186580ca2ed4 | None | IPv6 | ::/0 | | egress | None | None | | 9543774f-4244-4702-8bbd-f81663706511 | icmp | IPv4 | 0.0.0.0/0 | | ingress | None | None | +--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+ |
[3] | Login to the instance with SSH. |
[cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+-------------+--------+-----------------------+-----------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-------------+--------+-----------------------+-----------------+----------+ | 2b04dc33-aff9-4e55-8f09-d2156f7a6660 | CentOS-St-8 | ACTIVE | sharednet1=10.0.0.210 | CentOS-Stream-8 | m1.small | +--------------------------------------+-------------+--------+-----------------------+-----------------+----------+[cent@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.91 ms 64 bytes from 10.0.0.210: icmp_seq=2 ttl=64 time=0.892 ms 64 bytes from 10.0.0.210: icmp_seq=3 ttl=64 time=0.525 ms --- 10.0.0.210 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms rtt min/avg/max/mdev = 0.525/1.107/1.905/0.584 ms[cent@dlp ~(keystone)]$ ssh centos@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:8I8kM9t2oo8hneE8InhQOWkV9AhED7wbp5La7AfIomw. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '10.0.0.210' (ECDSA) to the list of known hosts. Activate the web console with: systemctl enable --now cockpit.socket [centos@centos-st-8 ~]$ # logined |
[4] | If you'd like to stop an instance, it's possible to control with openstack command like follows. |
[cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+-------------+--------+-----------------------+-----------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-------------+--------+-----------------------+-----------------+----------+ | 2b04dc33-aff9-4e55-8f09-d2156f7a6660 | CentOS-St-8 | ACTIVE | sharednet1=10.0.0.210 | CentOS-Stream-8 | m1.small | +--------------------------------------+-------------+--------+-----------------------+-----------------+----------+ # stop instance [cent@dlp ~(keystone)]$ openstack server stop CentOS-St-8 [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+-------------+---------+-----------------------+-----------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-------------+---------+-----------------------+-----------------+----------+ | 2b04dc33-aff9-4e55-8f09-d2156f7a6660 | CentOS-St-8 | SHUTOFF | sharednet1=10.0.0.210 | CentOS-Stream-8 | m1.small | +--------------------------------------+-------------+---------+-----------------------+-----------------+----------+ # start instance [cent@dlp ~(keystone)]$ openstack server start CentOS-St-8 [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+-------------+--------+-----------------------+-----------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-------------+--------+-----------------------+-----------------+----------+ | 2b04dc33-aff9-4e55-8f09-d2156f7a6660 | CentOS-St-8 | ACTIVE | sharednet1=10.0.0.210 | CentOS-Stream-8 | 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 | +--------------------------------------+-------------+--------+-----------------------+-----------------+----------+ | 2b04dc33-aff9-4e55-8f09-d2156f7a6660 | CentOS-St-8 | ACTIVE | sharednet1=10.0.0.210 | CentOS-Stream-8 | m1.small | +--------------------------------------+-------------+--------+-----------------------+-----------------+----------+[cent@dlp ~(keystone)]$ openstack console url show CentOS-St-8 +----------+------------------------------------------------------------------------------------------+ | Field | Value | +----------+------------------------------------------------------------------------------------------+ | protocol | vnc | | type | novnc | | url | http://10.0.0.30:6080/vnc_auto.html?path=%3Ftoken%3D8ad40ae9-bf0d-4afe-87fe-771e0bd54832 | +----------+------------------------------------------------------------------------------------------+ |
[6] | Access to the URL which was displayed by the command above. |
Sponsored Link |
|