OpenStack Yoga : Create Instances2022/06/09 |
Create and Start Virtual Machine Instance.
|
|
[1] | Login with a user and create a config for authentication of Keystone. 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=https://dlp.srv.world: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 | +--------------------------------------+----------------+--------+ | 1044ab46-c42b-4cf6-ab1f-aaeb011fb3b9 | CentOS-Stream9 | active | +--------------------------------------+----------------+--------+ # show available network list [cent@dlp ~(keystone)]$ openstack network list +--------------------------------------+------------+--------------------------------------+ | ID | Name | Subnets | +--------------------------------------+------------+--------------------------------------+ | 93b750c0-06e2-496e-a619-cfe98bf5ac4f | sharednet1 | 091c5237-b632-4a63-a1a2-58f100c60416 | +--------------------------------------+------------+--------------------------------------+ # create a security group for instances [cent@dlp ~(keystone)]$ openstack security group create secgroup01 +-----------------+------------------------------------------------------------------------------+ | Field | Value | +-----------------+------------------------------------------------------------------------------+ | created_at | 2022-06-09T00:44:56Z | | description | secgroup01 | | id | 31b313e0-f26a-4b07-98a3-b0135d95f006 | | name | secgroup01 | | project_id | 911e5ff7686741c782d6acc6d7155db1 | | revision_number | 1 | | rules | created_at='2022-06-09T00:44:56Z', direction='egress', ethertype='IPv6'..... | | | created_at='2022-06-09T00:44:56Z', direction='egress', ethertype='IPv4'..... | | stateful | True | | tags | [] | | updated_at | 2022-06-09T00:44:56Z | +-----------------+------------------------------------------------------------------------------+[cent@dlp ~(keystone)]$ openstack security group list +--------------------------------------+------------+------------------------+----------------------------------+------+ | ID | Name | Description | Project | Tags | +--------------------------------------+------------+------------------------+----------------------------------+------+ | 31b313e0-f26a-4b07-98a3-b0135d95f006 | secgroup01 | secgroup01 | 911e5ff7686741c782d6acc6d7155db1 | [] | | 743724ee-7033-4c0e-a833-be391619f39a | default | Default security group | 911e5ff7686741c782d6acc6d7155db1 | [] | +--------------------------------------+------------+------------------------+----------------------------------+------+ # create an 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 | cc:37:b7:c0:72:56:3e:66:71:f8:b1:59:72:c6:88:57 | | id | mykey | | is_deleted | None | | name | mykey | | type | ssh | | user_id | 1ff4591a7f8140fcad38fd9f606a66a6 | +-------------+-------------------------------------------------+[cent@dlp ~(keystone)]$ openstack keypair list +-------+-------------------------------------------------+------+ | Name | Fingerprint | Type | +-------+-------------------------------------------------+------+ | mykey | cc:37:b7:c0:72:56:3e:66:71:f8:b1:59:72:c6:88:57 | 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-Stream9 --security-group secgroup01 --nic net-id=$netID --key-name mykey CentOS-St9
+-----------------------------+-------------------------------------------------------+ | 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 | V8UBAjTqic5d | | config_drive | | | created | 2022-06-09T00:47:42Z | | flavor | m1.small (0) | | hostId | | | id | 2799cc3a-affb-42d1-b48e-59f3e49a9902 | | image | CentOS-Stream9 (1044ab46-c42b-4cf6-ab1f-aaeb011fb3b9) | | key_name | mykey | | name | CentOS-St9 | | progress | 0 | | project_id | 911e5ff7686741c782d6acc6d7155db1 | | properties | | | security_groups | name='31b313e0-f26a-4b07-98a3-b0135d95f006' | | status | BUILD | | updated | 2022-06-09T00:47:43Z | | user_id | 1ff4591a7f8140fcad38fd9f606a66a6 | | volumes_attached | | +-----------------------------+-------------------------------------------------------+ # show status ([BUILD] status is shown when building instance) [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+------------+--------+----------+----------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+------------+--------+----------+----------------+----------+ | 2799cc3a-affb-42d1-b48e-59f3e49a9902 | CentOS-St9 | BUILD | | CentOS-Stream9 | m1.small | +--------------------------------------+------------+--------+----------+----------------+----------+ # when starting normally, the status turns to [ACTIVE] [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+------------+--------+-----------------------+----------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+------------+--------+-----------------------+----------------+----------+ | 2799cc3a-affb-42d1-b48e-59f3e49a9902 | CentOS-St9 | ACTIVE | sharednet1=10.0.0.253 | CentOS-Stream9 | 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 | 2022-06-09T00:49:04Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 89a8f669-789b-44d5-ba04-1df850bb7637 | | name | None | | port_range_max | None | | port_range_min | None | | project_id | 911e5ff7686741c782d6acc6d7155db1 | | 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 | 31b313e0-f26a-4b07-98a3-b0135d95f006 | | tags | [] | | tenant_id | 911e5ff7686741c782d6acc6d7155db1 | | updated_at | 2022-06-09T00:49:04Z | +-------------------------+--------------------------------------+ # permit SSH [cent@dlp ~(keystone)]$ openstack security group rule create --protocol tcp --dst-port 22:22 secgroup01 +-------------------------+--------------------------------------+ | Field | Value | +-------------------------+--------------------------------------+ | created_at | 2022-06-09T00:49:31Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 9fe9c938-a281-42bf-9798-61288280845b | | name | None | | port_range_max | 22 | | port_range_min | 22 | | project_id | 911e5ff7686741c782d6acc6d7155db1 | | 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 | 31b313e0-f26a-4b07-98a3-b0135d95f006 | | tags | [] | | tenant_id | 911e5ff7686741c782d6acc6d7155db1 | | updated_at | 2022-06-09T00:49:31Z | +-------------------------+--------------------------------------+[cent@dlp ~(keystone)]$ openstack security group rule list secgroup01 +--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+ | ID | IP Protocol | Ethertype | IP Range | Port Range | Direction | Remote Security Group | Remote Address Group | +--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+ | 02d6b78e-3ed6-4699-8680-595a3296f3a0 | None | IPv6 | ::/0 | | egress | None | None | | 0f15d3d5-7e35-451f-9bdb-57a45c3c9e3c | None | IPv4 | 0.0.0.0/0 | | egress | None | None | | 89a8f669-789b-44d5-ba04-1df850bb7637 | icmp | IPv4 | 0.0.0.0/0 | | ingress | None | None | | 9fe9c938-a281-42bf-9798-61288280845b | tcp | IPv4 | 0.0.0.0/0 | 22:22 | ingress | None | None | +--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+ |
[3] | Login to the instance with SSH. |
[cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+------------+--------+-----------------------+----------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+------------+--------+-----------------------+----------------+----------+ | 2799cc3a-affb-42d1-b48e-59f3e49a9902 | CentOS-St9 | ACTIVE | sharednet1=10.0.0.253 | CentOS-Stream9 | m1.small | +--------------------------------------+------------+--------+-----------------------+----------------+----------+[cent@dlp ~(keystone)]$ ping 10.0.0.253 -c3 PING 10.0.0.253 (10.0.0.253) 56(84) bytes of data. 64 bytes from 10.0.0.253: icmp_seq=1 ttl=64 time=2.78 ms 64 bytes from 10.0.0.253: icmp_seq=2 ttl=64 time=0.951 ms 64 bytes from 10.0.0.253: icmp_seq=3 ttl=64 time=0.660 ms --- 10.0.0.253 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2003ms rtt min/avg/max/mdev = 0.660/1.465/2.784/0.940 ms[cent@dlp ~(keystone)]$ ssh centos@10.0.0.253
The authenticity of host '10.0.0.253 (10.0.0.253)' can't be established. ED25519 key fingerprint is SHA256:WG+DnlFIAvQSJ3dQnVlNuCb4Fupvbuc+F+D/Z7Al+30. This key is not known by any other names Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '10.0.0.253' (ED25519) to the list of known hosts. [centos@centos-st9 ~]$ # 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 | +--------------------------------------+------------+--------+-----------------------+----------------+----------+ | 2799cc3a-affb-42d1-b48e-59f3e49a9902 | CentOS-St9 | ACTIVE | sharednet1=10.0.0.253 | CentOS-Stream9 | m1.small | +--------------------------------------+------------+--------+-----------------------+----------------+----------+ # stop instance [cent@dlp ~(keystone)]$ openstack server stop CentOS-St9 [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+------------+---------+-----------------------+----------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+------------+--------+-----------------------+----------------+----------+ | 2799cc3a-affb-42d1-b48e-59f3e49a9902 | CentOS-St9 | SHUTOFF | sharednet1=10.0.0.253 | CentOS-Stream9 | m1.small | +--------------------------------------+------------+---------+-----------------------+----------------+----------+ # start instance [cent@dlp ~(keystone)]$ openstack server start CentOS-St9 [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+------------+--------+-----------------------+----------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+------------+--------+-----------------------+----------------+----------+ | 2799cc3a-affb-42d1-b48e-59f3e49a9902 | CentOS-St9 | ACTIVE | sharednet1=10.0.0.253 | CentOS-Stream9 | 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 | +--------------------------------------+------------+--------+-----------------------+----------------+----------+ | 2799cc3a-affb-42d1-b48e-59f3e49a9902 | CentOS-St9 | ACTIVE | sharednet1=10.0.0.253 | CentOS-Stream9 | m1.small | +--------------------------------------+------------+--------+-----------------------+----------------+----------+[cent@dlp ~(keystone)]$ openstack console url show CentOS-St9 +----------+-----------------------------------------------------------------------------------------------+ | Field | Value | +----------+-----------------------------------------------------------------------------------------------+ | protocol | vnc | | type | novnc | | url | https://dlp.srv.world:6080/vnc_auto.html?path=%3Ftoken%3D000cc47f-fafa-478c-9cc6-20c124c5bf2c | +----------+-----------------------------------------------------------------------------------------------+ |
[6] | Access to the URL which was displayed by the command above. |
Sponsored Link |