OpenStack Yoga : Create Instances2022/05/31 |
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=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 | +--------------------------------------+-----------------+--------+ | 7be5b7ab-36e8-43c7-95dd-34b4139a0e44 | CentOS-Stream-8 | active | +--------------------------------------+-----------------+--------+ # show available network list [cent@dlp ~(keystone)]$ openstack network list +--------------------------------------+------------+--------------------------------------+ | ID | Name | Subnets | +--------------------------------------+------------+--------------------------------------+ | ed951532-0b6e-484e-8909-ba20007752c2 | sharednet1 | 863e41c2-48b8-4c27-9846-f00fd486f7e9 | +--------------------------------------+------------+--------------------------------------+ # create a security group for instances [cent@dlp ~(keystone)]$ openstack security group create secgroup01 +-----------------+----------------------------------------------------------------------------+ | Field | Value | +-----------------+----------------------------------------------------------------------------+ | created_at | 2022-05-31T05:04:14Z | | description | secgroup01 | | id | 86d9d627-fd49-490a-b0da-02ef925566fb | | name | secgroup01 | | project_id | 3d85d1e79d654b3dade01eb5bfbf0679 | | revision_number | 1 | | rules | created_at='2022-05-31T05:04:14Z', direction='egress', ethertype='IPv..... | | | created_at='2022-05-31T05:04:14Z', direction='egress', ethertype='IPv..... | | stateful | True | | tags | [] | | updated_at | 2022-05-31T05:04:14Z | +-----------------+----------------------------------------------------------------------------+[cent@dlp ~(keystone)]$ openstack security group list +--------------------------------------+------------+------------------------+----------------------------------+------+ | ID | Name | Description | Project | Tags | +--------------------------------------+------------+------------------------+----------------------------------+------+ | 4e46aafd-178b-4476-8d4f-7e5bf0ef2599 | default | Default security group | 3d85d1e79d654b3dade01eb5bfbf0679 | [] | | 86d9d627-fd49-490a-b0da-02ef925566fb | secgroup01 | secgroup01 | 3d85d1e79d654b3dade01eb5bfbf0679 | [] | +--------------------------------------+------------+------------------------+----------------------------------+------+ # 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 | 00:74:cd:5c:68:56:f0:b6:f4:c4:de:e5:65:fd:ef:f8 | | id | mykey | | is_deleted | None | | name | mykey | | type | ssh | | user_id | ed0bc393ae81411fa1db0828e1d5e160 | +-------------+-------------------------------------------------+[cent@dlp ~(keystone)]$ openstack keypair list +-------+-------------------------------------------------+------+ | Name | Fingerprint | Type | +-------+-------------------------------------------------+------+ | mykey | 00:74:cd:5c:68:56:f0:b6:f4:c4:de:e5:65:fd:ef:f8 | 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-St8
+-----------------------------+--------------------------------------------------------+ | 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 | TsM2BcxzQ2gy | | config_drive | | | created | 2022-05-31T05:07:10Z | | flavor | m1.small (0) | | hostId | | | id | d94d7fce-1321-45f7-b6a7-a2c03c5f8646 | | image | CentOS-Stream-8 (7be5b7ab-36e8-43c7-95dd-34b4139a0e44) | | key_name | mykey | | name | CentOS-St8 | | progress | 0 | | project_id | 3d85d1e79d654b3dade01eb5bfbf0679 | | properties | | | security_groups | name='86d9d627-fd49-490a-b0da-02ef925566fb' | | status | BUILD | | updated | 2022-05-31T05:07:10Z | | user_id | ed0bc393ae81411fa1db0828e1d5e160 | | volumes_attached | | +-----------------------------+--------------------------------------------------------+ # show status ([BUILD] status is shown when building instance) [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+------------+--------+----------+-----------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+------------+--------+----------+-----------------+----------+ | d94d7fce-1321-45f7-b6a7-a2c03c5f8646 | CentOS-St8 | 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 | +--------------------------------------+------------+--------+-----------------------+-----------------+----------+ | d94d7fce-1321-45f7-b6a7-a2c03c5f8646 | CentOS-St8 | ACTIVE | sharednet1=10.0.0.202 | 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 | 2022-05-31T05:08:29Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 2da9b1af-ef5e-40e5-9411-89f59001bec5 | | name | None | | port_range_max | None | | port_range_min | None | | project_id | 3d85d1e79d654b3dade01eb5bfbf0679 | | 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 | 86d9d627-fd49-490a-b0da-02ef925566fb | | tags | [] | | tenant_id | 3d85d1e79d654b3dade01eb5bfbf0679 | | updated_at | 2022-05-31T05:08:29Z | +-------------------------+--------------------------------------+ # permit SSH [cent@dlp ~(keystone)]$ openstack security group rule create --protocol tcp --dst-port 22:22 secgroup01 +-------------------------+--------------------------------------+ | Field | Value | +-------------------------+--------------------------------------+ | created_at | 2022-05-31T05:08:43Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 31ca1b95-ddb8-475d-8086-e235470f6d94 | | name | None | | port_range_max | 22 | | port_range_min | 22 | | project_id | 3d85d1e79d654b3dade01eb5bfbf0679 | | 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 | 86d9d627-fd49-490a-b0da-02ef925566fb | | tags | [] | | tenant_id | 3d85d1e79d654b3dade01eb5bfbf0679 | | updated_at | 2022-05-31T05:08:43Z | +-------------------------+--------------------------------------+[cent@dlp ~(keystone)]$ openstack security group rule list secgroup01 +--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+ | ID | IP Protocol | Ethertype | IP Range | Port Range | Direction | Remote Security Group | Remote Address Group | +--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+ | 2da9b1af-ef5e-40e5-9411-89f59001bec5 | icmp | IPv4 | 0.0.0.0/0 | | ingress | None | None | | 31ca1b95-ddb8-475d-8086-e235470f6d94 | tcp | IPv4 | 0.0.0.0/0 | 22:22 | ingress | None | None | | 4a7149f0-ae95-462a-83a0-e58c77078e44 | None | IPv6 | ::/0 | | egress | None | None | | 81c3b639-dead-4728-9a29-d66ed3deb9bf | None | IPv4 | 0.0.0.0/0 | | egress | None | None | +--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+ |
[3] | Login to the instance with SSH. |
[cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+------------+--------+-----------------------+-----------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+------------+--------+-----------------------+-----------------+----------+ | d94d7fce-1321-45f7-b6a7-a2c03c5f8646 | CentOS-St8 | ACTIVE | sharednet1=10.0.0.202 | CentOS-Stream-8 | m1.small | +--------------------------------------+------------+--------+-----------------------+-----------------+----------+[cent@dlp ~(keystone)]$ ping 10.0.0.202 -c3 PING 10.0.0.202 (10.0.0.202) 56(84) bytes of data. 64 bytes from 10.0.0.202: icmp_seq=1 ttl=64 time=2.37 ms 64 bytes from 10.0.0.202: icmp_seq=2 ttl=64 time=1.03 ms 64 bytes from 10.0.0.202: icmp_seq=3 ttl=64 time=0.885 ms --- 10.0.0.202 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2003ms rtt min/avg/max/mdev = 0.885/1.428/2.370/0.669 ms[cent@dlp ~(keystone)]$ ssh centos@10.0.0.202
The authenticity of host '10.0.0.202 (10.0.0.202)' can't be established. ECDSA key fingerprint is SHA256:KLqoS54PfUBeH+H97tXUROOHgYz/O+aY9+lqc081yyk. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '10.0.0.202' (ECDSA) to the list of known hosts. Activate the web console with: systemctl enable --now cockpit.socket [centos@centos-st8 ~]$ # 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 | +--------------------------------------+------------+--------+-----------------------+-----------------+----------+ | d94d7fce-1321-45f7-b6a7-a2c03c5f8646 | CentOS-St8 | ACTIVE | sharednet1=10.0.0.202 | CentOS-Stream-8 | m1.small | +--------------------------------------+------------+--------+-----------------------+-----------------+----------+ # stop instance [cent@dlp ~(keystone)]$ openstack server stop CentOS-St8 [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+------------+---------+-----------------------+-----------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+------------+---------+-----------------------+-----------------+----------+ | d94d7fce-1321-45f7-b6a7-a2c03c5f8646 | CentOS-St8 | SHUTOFF | sharednet1=10.0.0.202 | CentOS-Stream-8 | m1.small | +--------------------------------------+------------+---------+-----------------------+-----------------+----------+ # start instance [cent@dlp ~(keystone)]$ openstack server start CentOS-St8 [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+------------+--------+-----------------------+-----------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+------------+--------+-----------------------+-----------------+----------+ | d94d7fce-1321-45f7-b6a7-a2c03c5f8646 | CentOS-St8 | ACTIVE | sharednet1=10.0.0.202 | 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 | +--------------------------------------+------------+--------+-----------------------+-----------------+----------+ | d94d7fce-1321-45f7-b6a7-a2c03c5f8646 | CentOS-St8 | ACTIVE | sharednet1=10.0.0.202 | CentOS-Stream-8 | m1.small | +--------------------------------------+------------+--------+-----------------------+-----------------+----------+[cent@dlp ~(keystone)]$ openstack console url show CentOS-St8 +----------+-----------------------------------------------------------------------------------------------+ | Field | Value | +----------+-----------------------------------------------------------------------------------------------+ | protocol | vnc | | type | novnc | | url | https://dlp.srv.world:6080/vnc_auto.html?path=%3Ftoken%3D3ffce855-bae1-4914-b4fb-de1ff0d808e7 | +----------+-----------------------------------------------------------------------------------------------+ |
[6] | Access to the URL which was displayed by the command above. |
Sponsored Link |
|