OpenStack Xena : Create Instances2021/11/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 | +--------------------------------------+-----------------+--------+ | cfce605e-151b-43dd-b743-2c7988d69e96 | CentOS-Stream-8 | active | +--------------------------------------+-----------------+--------+ # show available network list [cent@dlp ~(keystone)]$ openstack network list +--------------------------------------+------------+--------------------------------------+ | ID | Name | Subnets | +--------------------------------------+------------+--------------------------------------+ | e2ac29e8-55e4-4111-8a2f-14e250288440 | sharednet1 | 0918f78c-3a45-485f-834f-93d1e9982a40 | +--------------------------------------+------------+--------------------------------------+ # create a security group for instances [cent@dlp ~(keystone)]$ openstack security group create secgroup01 +-----------------+---------------------------------------------------------------------------+ | Field | Value | +-----------------+---------------------------------------------------------------------------+ | created_at | 2021-11-22T03:50:24Z | | description | secgroup01 | | id | ea02f1bb-3244-4465-bd45-21ea7024d901 | | name | secgroup01 | | project_id | 2decda8bcd724687a1cf05064ab21fdf | | revision_number | 1 | | rules | created_at='2021-11-22T03:50:24Z', direction='egress', ethertype='IPv6... | | | created_at='2021-11-22T03:50:24Z', direction='egress', ethertype='IPv4... | | stateful | True | | tags | [] | | updated_at | 2021-11-22T03:50:24Z | +-----------------+---------------------------------------------------------------------------+[cent@dlp ~(keystone)]$ openstack security group list +--------------------------------------+------------+------------------------+----------------------------------+------+ | ID | Name | Description | Project | Tags | +--------------------------------------+------------+------------------------+----------------------------------+------+ | 8e8803dd-42be-45c5-8070-533b6f4e7f47 | default | Default security group | 2decda8bcd724687a1cf05064ab21fdf | [] | | ea02f1bb-3244-4465-bd45-21ea7024d901 | secgroup01 | secgroup01 | 2decda8bcd724687a1cf05064ab21fdf | [] | +--------------------------------------+------------+------------------------+----------------------------------+------+ # 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 | 1f:1e:c1:75:27:6e:5d:6f:ef:f5:01:3b:d2:31:2b:a4 | | id | mykey | | is_deleted | None | | name | mykey | | type | ssh | | user_id | 6a517543654044e8b4ea9e0eea0adaa4 | +-------------+-------------------------------------------------+[cent@dlp ~(keystone)]$ openstack keypair list +-------+-------------------------------------------------+------+ | Name | Fingerprint | Type | +-------+-------------------------------------------------+------+ | mykey | 1f:1e:c1:75:27:6e:5d:6f:ef:f5:01:3b:d2:31:2b:a4 | 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 | CHF6Cfp4SHnB | | config_drive | | | created | 2021-11-22T03:52:35Z | | flavor | m1.small (0) | | hostId | | | id | 892c46a7-0472-44b9-95d0-b81273129caf | | image | CentOS-Stream-8 (cfce605e-151b-43dd-b743-2c7988d69e96) | | key_name | mykey | | name | CentOS-St-8 | | progress | 0 | | project_id | 2decda8bcd724687a1cf05064ab21fdf | | properties | | | security_groups | name='ea02f1bb-3244-4465-bd45-21ea7024d901' | | status | BUILD | | updated | 2021-11-22T03:52:35Z | | user_id | 6a517543654044e8b4ea9e0eea0adaa4 | | volumes_attached | | +-----------------------------+--------------------------------------------------------+ # show status ([BUILD] status is shown when building instance) [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+-------------+--------+----------+-----------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-------------+--------+----------+-----------------+----------+ | 892c46a7-0472-44b9-95d0-b81273129caf | 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 | +--------------------------------------+-------------+--------+-----------------------+-----------------+----------+ | 892c46a7-0472-44b9-95d0-b81273129caf | CentOS-St-8 | ACTIVE | sharednet1=10.0.0.219 | 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-11-22T03:53:50Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 154172ea-e18c-44e8-90b2-eda7a665cd54 | | name | None | | port_range_max | None | | port_range_min | None | | project_id | 2decda8bcd724687a1cf05064ab21fdf | | 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 | ea02f1bb-3244-4465-bd45-21ea7024d901 | | tags | [] | | updated_at | 2021-11-22T03:53:50Z | +-------------------------+--------------------------------------+ # permit SSH [cent@dlp ~(keystone)]$ openstack security group rule create --protocol tcp --dst-port 22:22 secgroup01 +-------------------------+--------------------------------------+ | Field | Value | +-------------------------+--------------------------------------+ | created_at | 2021-11-22T03:54:03Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | ac473670-1693-405e-9eca-70b1b20465ec | | name | None | | port_range_max | 22 | | port_range_min | 22 | | project_id | 2decda8bcd724687a1cf05064ab21fdf | | 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 | ea02f1bb-3244-4465-bd45-21ea7024d901 | | tags | [] | | updated_at | 2021-11-22T03:54:03Z | +-------------------------+--------------------------------------+[cent@dlp ~(keystone)]$ openstack security group rule list secgroup01 +--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+ | ID | IP Protocol | Ethertype | IP Range | Port Range | Direction | Remote Security Group | Remote Address Group | +--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+ | 154172ea-e18c-44e8-90b2-eda7a665cd54 | icmp | IPv4 | 0.0.0.0/0 | | ingress | None | None | | 5add4ebf-3d5d-4a79-a017-ffa7d6c24610 | None | IPv6 | ::/0 | | egress | None | None | | 7bc37284-d2f5-486f-8d70-8d0c44c8d1af | None | IPv4 | 0.0.0.0/0 | | egress | None | None | | ac473670-1693-405e-9eca-70b1b20465ec | 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 | +--------------------------------------+-------------+--------+-----------------------+-----------------+----------+ | 892c46a7-0472-44b9-95d0-b81273129caf | CentOS-St-8 | ACTIVE | sharednet1=10.0.0.219 | CentOS-Stream-8 | m1.small | +--------------------------------------+-------------+--------+-----------------------+-----------------+----------+[cent@dlp ~(keystone)]$ ping 10.0.0.219 -c3 PING 10.0.0.219 (10.0.0.219) 56(84) bytes of data. 64 bytes from 10.0.0.219: icmp_seq=1 ttl=64 time=1.58 ms 64 bytes from 10.0.0.219: icmp_seq=2 ttl=64 time=0.789 ms 64 bytes from 10.0.0.219: icmp_seq=3 ttl=64 time=0.637 ms --- 10.0.0.219 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2004ms rtt min/avg/max/mdev = 0.637/1.002/1.580/0.413 ms[cent@dlp ~(keystone)]$ ssh centos@10.0.0.219
The authenticity of host '10.0.0.219 (10.0.0.219)' can't be established. ECDSA key fingerprint is SHA256:3gLFosEgnUDvIjrOiWL+J17ZA8vor0cu45t8Ea/VR5Q. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '10.0.0.219' (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 | +--------------------------------------+-------------+--------+-----------------------+-----------------+----------+ | 892c46a7-0472-44b9-95d0-b81273129caf | CentOS-St-8 | ACTIVE | sharednet1=10.0.0.219 | 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 | +--------------------------------------+-------------+---------+-----------------------+-----------------+----------+ | 892c46a7-0472-44b9-95d0-b81273129caf | CentOS-St-8 | SHUTOFF | sharednet1=10.0.0.219 | 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 | +--------------------------------------+-------------+--------+-----------------------+-----------------+----------+ | 892c46a7-0472-44b9-95d0-b81273129caf | CentOS-St-8 | ACTIVE | sharednet1=10.0.0.219 | 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 | +--------------------------------------+-------------+--------+-----------------------+-----------------+----------+ | 892c46a7-0472-44b9-95d0-b81273129caf | CentOS-St-8 | ACTIVE | sharednet1=10.0.0.219 | 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%3Dfc6e596b-3aa1-4168-bee2-d1f5e117b2e2 | +----------+------------------------------------------------------------------------------------------+ |
[6] | Access to the URL which was displayed by the command above. |
Sponsored Link |
|