OpenStack Zed : Create Instances2022/11/10 |
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 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 | +--------------------------------------+----------------+--------+ | 8367cc21-61f4-480b-8d03-90c057c7a7cf | CentOS-Stream9 | active | +--------------------------------------+----------------+--------+ # show available network list [cent@dlp ~(keystone)]$ openstack network list +--------------------------------------+------------+--------------------------------------+ | ID | Name | Subnets | +--------------------------------------+------------+--------------------------------------+ | 06a8e848-a2a4-498e-9fe7-22c10faae23d | sharednet1 | eaa26a3d-2591-4418-8145-1e83d42eac79 | +--------------------------------------+------------+--------------------------------------+ # create a security group for instances [cent@dlp ~(keystone)]$ openstack security group create secgroup01 +-----------------+-------------------------------------------------------------------------------+ | Field | Value | +-----------------+-------------------------------------------------------------------------------+ | created_at | 2022-11-10T03:25:42Z | | description | secgroup01 | | id | 08495290-cf41-4c99-9c12-dff54cc7e385 | | name | secgroup01 | | project_id | 28b6e37c787240e4a975d3614821cc71 | | revision_number | 1 | | rules | created_at='2022-11-10T03:25:42Z', direction='egress', ethertype='IPv6', i... | | | created_at='2022-11-10T03:25:42Z', direction='egress', ethertype='IPv4', i... | | stateful | True | | tags | [] | | updated_at | 2022-11-10T03:25:42Z | +-----------------+-------------------------------------------------------------------------------+[cent@dlp ~(keystone)]$ openstack security group list +--------------------------------------+------------+------------------------+----------------------------------+------+ | ID | Name | Description | Project | Tags | +--------------------------------------+------------+------------------------+----------------------------------+------+ | 08495290-cf41-4c99-9c12-dff54cc7e385 | secgroup01 | secgroup01 | 28b6e37c787240e4a975d3614821cc71 | [] | | 96b9d926-730a-4513-ac9c-4fa8e87d7040 | default | Default security group | 28b6e37c787240e4a975d3614821cc71 | [] | +--------------------------------------+------------+------------------------+----------------------------------+------+ # 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 | 7f:ce:9f:a7:59:96:8c:59:5c:7e:d4:3b:b1:62:ea:41 | | id | mykey | | is_deleted | None | | name | mykey | | type | ssh | | user_id | 9e8824a151c949ad9105535ead452501 | +-------------+-------------------------------------------------+[cent@dlp ~(keystone)]$ openstack keypair list +-------+-------------------------------------------------+------+ | Name | Fingerprint | Type | +-------+-------------------------------------------------+------+ | mykey | 7f:ce:9f:a7:59:96:8c:59:5c:7e:d4:3b:b1:62:ea:41 | 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 | sKXLe7yC3gUX | | config_drive | | | created | 2022-11-10T03:28:30Z | | flavor | m1.small (0) | | hostId | | | id | 0df438c6-3c62-4d87-8696-8befd33b5f15 | | image | CentOS-Stream9 (8367cc21-61f4-480b-8d03-90c057c7a7cf) | | key_name | mykey | | name | CentOS-St9 | | progress | 0 | | project_id | 28b6e37c787240e4a975d3614821cc71 | | properties | | | security_groups | name='08495290-cf41-4c99-9c12-dff54cc7e385' | | status | BUILD | | updated | 2022-11-10T03:28:30Z | | user_id | 9e8824a151c949ad9105535ead452501 | | volumes_attached | | +-----------------------------+-------------------------------------------------------+ # show status ([BUILD] status is shown when building instance) [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+------------+--------+----------+----------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+------------+--------+----------+----------------+----------+ | 0df438c6-3c62-4d87-8696-8befd33b5f15 | 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 | +--------------------------------------+------------+--------+-----------------------+----------------+----------+ | 0df438c6-3c62-4d87-8696-8befd33b5f15 | CentOS-St9 | ACTIVE | sharednet1=10.0.0.201 | 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-11-10T03:29:45Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | a5dc1224-4fc1-44c9-a0fa-a946e833feaf | | name | None | | port_range_max | None | | port_range_min | None | | project_id | 28b6e37c787240e4a975d3614821cc71 | | 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 | 08495290-cf41-4c99-9c12-dff54cc7e385 | | tags | [] | | updated_at | 2022-11-10T03:29:45Z | +-------------------------+--------------------------------------+ # permit SSH [cent@dlp ~(keystone)]$ openstack security group rule create --protocol tcp --dst-port 22:22 secgroup01 +-------------------------+--------------------------------------+ | Field | Value | +-------------------------+--------------------------------------+ | created_at | 2022-11-10T03:30:04Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 11c5d9c8-b83f-4ceb-9e2e-f94637e6dad9 | | name | None | | port_range_max | 22 | | port_range_min | 22 | | project_id | 28b6e37c787240e4a975d3614821cc71 | | 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 | 08495290-cf41-4c99-9c12-dff54cc7e385 | | tags | [] | | updated_at | 2022-11-10T03:30:04Z | +-------------------------+--------------------------------------+[cent@dlp ~(keystone)]$ openstack security group rule list secgroup01 +--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+ | ID | IP Protocol | Ethertype | IP Range | Port Range | Direction | Remote Security Group | Remote Address Group | +--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+ | 07717e7e-34ef-4619-ba03-bef1e9ccca8f | None | IPv6 | ::/0 | | egress | None | None | | 11c5d9c8-b83f-4ceb-9e2e-f94637e6dad9 | tcp | IPv4 | 0.0.0.0/0 | 22:22 | ingress | None | None | | a5dc1224-4fc1-44c9-a0fa-a946e833feaf | icmp | IPv4 | 0.0.0.0/0 | | ingress | None | None | | d115c111-6227-4ab1-956f-c8edf7379a78 | 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 | +--------------------------------------+------------+--------+-----------------------+----------------+----------+ | 0df438c6-3c62-4d87-8696-8befd33b5f15 | CentOS-St9 | ACTIVE | sharednet1=10.0.0.201 | CentOS-Stream9 | m1.small | +--------------------------------------+------------+--------+-----------------------+----------------+----------+[cent@dlp ~(keystone)]$ ping 10.0.0.201 -c3 PING 10.0.0.201 (10.0.0.201) 56(84) bytes of data. 64 bytes from 10.0.0.201: icmp_seq=1 ttl=64 time=0.890 ms 64 bytes from 10.0.0.201: icmp_seq=2 ttl=64 time=0.646 ms 64 bytes from 10.0.0.201: icmp_seq=3 ttl=64 time=0.545 ms --- 10.0.0.201 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2033ms rtt min/avg/max/mdev = 0.545/0.693/0.890/0.144 ms[cent@dlp ~(keystone)]$ ssh centos@10.0.0.201
The authenticity of host '10.0.0.201 (10.0.0.201)' can't be established. ED25519 key fingerprint is SHA256:HysoxiaBRbrm59rD5IxCHzVRgFplOQpxSAr2IzoEovI. 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.201' (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 | +--------------------------------------+------------+--------+-----------------------+----------------+----------+ | 0df438c6-3c62-4d87-8696-8befd33b5f15 | CentOS-St9 | ACTIVE | sharednet1=10.0.0.201 | 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 | +--------------------------------------+------------+--------+-----------------------+----------------+----------+ | 0df438c6-3c62-4d87-8696-8befd33b5f15 | CentOS-St9 | SHUTOFF | sharednet1=10.0.0.201 | 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 | +--------------------------------------+------------+--------+-----------------------+----------------+----------+ | 0df438c6-3c62-4d87-8696-8befd33b5f15 | CentOS-St9 | ACTIVE | sharednet1=10.0.0.201 | 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 | +--------------------------------------+------------+--------+-----------------------+----------------+----------+ | 0df438c6-3c62-4d87-8696-8befd33b5f15 | CentOS-St9 | ACTIVE | sharednet1=10.0.0.201 | 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%3D23509da1-ba5b-48cc-bcb8-f190c76d7a75 | +----------+-----------------------------------------------------------------------------------------------+ |
[6] | Access to the URL which was displayed by the command above. |
Sponsored Link |