OpenStack Victoria : Create Instances2021/03/23 |
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 | +--------------------------------------+-----------------+--------+ | 4d7293af-be5b-471b-9507-2a32f1955b11 | CentOS-Stream-8 | active | +--------------------------------------+-----------------+--------+ # show available network list [cent@dlp ~(keystone)]$ openstack network list +--------------------------------------+------------+--------------------------------------+ | ID | Name | Subnets | +--------------------------------------+------------+--------------------------------------+ | 1897bcee-670c-4015-8a57-0f61f7865061 | sharednet1 | ba0005fc-ca93-4f5d-b4f2-20e51f6fc44a | +--------------------------------------+------------+--------------------------------------+ # create a security group for instances [cent@dlp ~(keystone)]$ openstack security group create secgroup01 +-----------------+--------------------------------------------------------------------------------+ | Field | Value | +-----------------+--------------------------------------------------------------------------------+ | created_at | 2021-03-23T04:16:49Z | | description | secgroup01 | | id | 469fb0c0-3fa4-48e7-a1e5-79a0d79bfd01 | | name | secgroup01 | | project_id | f1f04d774d2141fb9acabd28d0e00c33 | | revision_number | 1 | | rules | created_at='2021-03-23T04:16:49Z', direction='egress', ethertype='IPv6', ..... | | | created_at='2021-03-23T04:16:49Z', direction='egress', ethertype='IPv4', ..... | | stateful | True | | tags | [] | | updated_at | 2021-03-23T04:16:49Z | +-----------------+--------------------------------------------------------------------------------+[cent@dlp ~(keystone)]$ openstack security group list +--------------------------------------+------------+------------------------+----------------------------------+------+ | ID | Name | Description | Project | Tags | +--------------------------------------+------------+------------------------+----------------------------------+------+ | 469fb0c0-3fa4-48e7-a1e5-79a0d79bfd01 | secgroup01 | secgroup01 | f1f04d774d2141fb9acabd28d0e00c33 | [] | | 674c256f-cac6-4c17-9131-9675d143d494 | default | Default security group | f1f04d774d2141fb9acabd28d0e00c33 | [] | +--------------------------------------+------------+------------------------+----------------------------------+------+ # 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 | a1:ea:44:e8:d4:a9:f6:40:f7:05:19:d4:eb:e5:fe:0a | | name | mykey | | user_id | e08c35de3b6746bd9518c97f7068a71e | +-------------+-------------------------------------------------+[cent@dlp ~(keystone)]$ openstack keypair list +-------+-------------------------------------------------+ | Name | Fingerprint | +-------+-------------------------------------------------+ | mykey | a1:ea:44:e8:d4:a9:f6:40:f7:05:19:d4:eb:e5:fe:0a | +-------+-------------------------------------------------+
[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 | ms88a8CBHrjF | | config_drive | | | created | 2021-03-23T04:19:23Z | | flavor | m1.small (0) | | hostId | | | id | 5b2d6808-9703-4591-a896-483f1cba6909 | | image | CentOS-Stream-8 (4d7293af-be5b-471b-9507-2a32f1955b11) | | key_name | mykey | | name | CentOS-St-8 | | progress | 0 | | project_id | f1f04d774d2141fb9acabd28d0e00c33 | | properties | | | security_groups | name='469fb0c0-3fa4-48e7-a1e5-79a0d79bfd01' | | status | BUILD | | updated | 2021-03-23T04:19:23Z | | user_id | e08c35de3b6746bd9518c97f7068a71e | | volumes_attached | | +-----------------------------+--------------------------------------------------------+ # show status ([BUILD] status is shown when building instance) [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+-------------+--------+----------+-----------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-------------+--------+----------+-----------------+----------+ | 5b2d6808-9703-4591-a896-483f1cba6909 | 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 | +--------------------------------------+-------------+--------+-----------------------+-----------------+----------+ | 5b2d6808-9703-4591-a896-483f1cba6909 | CentOS-St-8 | ACTIVE | sharednet1=10.0.0.224 | 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-03-23T04:20:36Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 625ded53-8a40-4e3a-8108-9343832ea93c | | name | None | | port_range_max | None | | port_range_min | None | | project_id | f1f04d774d2141fb9acabd28d0e00c33 | | protocol | icmp | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 0 | | security_group_id | 469fb0c0-3fa4-48e7-a1e5-79a0d79bfd01 | | tags | [] | | updated_at | 2021-03-23T04:20:36Z | +-------------------+--------------------------------------+ # permit SSH [cent@dlp ~(keystone)]$ openstack security group rule create --protocol tcp --dst-port 22:22 secgroup01 +-------------------+--------------------------------------+ | Field | Value | +-------------------+--------------------------------------+ | created_at | 2021-03-23T04:20:50Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 52055b2a-8517-4dbf-a182-d2357d29615d | | name | None | | port_range_max | 22 | | port_range_min | 22 | | project_id | f1f04d774d2141fb9acabd28d0e00c33 | | protocol | tcp | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 0 | | security_group_id | 469fb0c0-3fa4-48e7-a1e5-79a0d79bfd01 | | tags | [] | | updated_at | 2021-03-23T04:20:50Z | +-------------------+--------------------------------------+[cent@dlp ~(keystone)]$ openstack security group rule list +--------------------------------------+-------------+-----------+-----------+------------+------------+ | ID | IP Protocol | Ethertype | IP Range | Port Range | Remote Sec | +--------------------------------------+-------------+-----------+-----------+------------+------------+ | 00a13bf4-9fd0-4dd7-b793-7df4d2f57600 | None | IPv6 | ::/0 | | None | | 52055b2a-8517-4dbf-a182-d2357d29615d | tcp | IPv4 | 0.0.0.0/0 | 22:22 | None | | 625ded53-8a40-4e3a-8108-9343832ea93c | icmp | IPv4 | 0.0.0.0/0 | | None | | 6263d19b-fc72-4944-9ad0-c97a28661702 | None | IPv6 | ::/0 | | None | | 92d18dd9-ad87-431d-808d-5311c0c47943 | None | IPv6 | ::/0 | | 674c2..... | | 990e0f4a-1eca-4a13-8e04-1e3d5969f22a | None | IPv4 | 0.0.0.0/0 | | None | | c3be9697-831f-4cb8-b4b7-3ced378e86a3 | None | IPv4 | 0.0.0.0/0 | | 674c2..... | | d1c5228a-bcd1-46bf-839f-aa6035585316 | None | IPv4 | 0.0.0.0/0 | | None | +--------------------------------------+-------------+-----------+-----------+------------+------------+ |
[3] | Login to the instance with SSH. |
[cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+-------------+--------+-----------------------+-----------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-------------+--------+-----------------------+-----------------+----------+ | 5b2d6808-9703-4591-a896-483f1cba6909 | CentOS-St-8 | ACTIVE | sharednet1=10.0.0.224 | CentOS-Stream-8 | m1.small | +--------------------------------------+-------------+--------+-----------------------+-----------------+----------+[cent@dlp ~(keystone)]$ ping 10.0.0.224 -c3 PING 10.0.0.224 (10.0.0.224) 56(84) bytes of data. 64 bytes from 10.0.0.224: icmp_seq=1 ttl=64 time=2.12 ms 64 bytes from 10.0.0.224: icmp_seq=2 ttl=64 time=1.12 ms 64 bytes from 10.0.0.224: icmp_seq=3 ttl=64 time=0.760 ms --- 10.0.0.224 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2003ms rtt min/avg/max/mdev = 0.760/1.334/2.122/0.576 ms[cent@dlp ~(keystone)]$ ssh centos@10.0.0.224
The authenticity of host '10.0.0.224 (10.0.0.224)' can't be established. ECDSA key fingerprint is SHA256:9V7gTMh2wGbgagyHph8zggYJwysFaGJSG8GKWOZraQ0. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '10.0.0.224' (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 | +--------------------------------------+-------------+--------+-----------------------+-----------------+----------+ | 5b2d6808-9703-4591-a896-483f1cba6909 | CentOS-St-8 | ACTIVE | sharednet1=10.0.0.224 | 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 | +--------------------------------------+-------------+---------+-----------------------+-----------------+----------+ | 5b2d6808-9703-4591-a896-483f1cba6909 | CentOS-St-8 | SHUTOFF | sharednet1=10.0.0.224 | 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 | +--------------------------------------+-------------+--------+-----------------------+-----------------+----------+ | 5b2d6808-9703-4591-a896-483f1cba6909 | CentOS-St-8 | ACTIVE | sharednet1=10.0.0.224 | 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 | +--------------------------------------+-------------+--------+-----------------------+-----------------+----------+ | 5b2d6808-9703-4591-a896-483f1cba6909 | CentOS-St-8 | ACTIVE | sharednet1=10.0.0.224 | CentOS-Stream-8 | m1.small | +--------------------------------------+-------------+--------+-----------------------+-----------------+----------+[cent@dlp ~(keystone)]$ openstack console url show CentOS-St-8 +-------+------------------------------------------------------------------------------------------+ | Field | Value | +-------+------------------------------------------------------------------------------------------+ | type | novnc | | url | http://10.0.0.30:6080/vnc_auto.html?path=%3Ftoken%3D2fd73068-6408-412e-8497-a77d8871c89a | +-------+------------------------------------------------------------------------------------------+ |
[6] | Access to the URL which was displayed by the command above, then you can use your instance on the web browser. |
Sponsored Link |
|