CentOS 7
Sponsored Link

OpenStack Stein : Run Instances
2019/05/16
 
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 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 image list

[cent@dlp ~(keystone)]$
openstack image list

+--------------------------------------+---------+--------+
| ID                                   | Name    | Status |
+--------------------------------------+---------+--------+
| 0d0bf9ae-9d4c-445f-b2e0-5b322dffa988 | CentOS7 | active |
+--------------------------------------+---------+--------+

# show network list

[cent@dlp ~(keystone)]$
openstack network list

+--------------------------------------+------------+--------------------------------------+
| ID                                   | Name       | Subnets                              |
+--------------------------------------+------------+--------------------------------------+
| 9173cfb2-a356-4805-8db5-ab125a23da7c | sharednet1 | 2f2e5e59-ca9e-481e-9949-6a090c552780 |
+--------------------------------------+------------+--------------------------------------+

# create a security group for instances

[cent@dlp ~(keystone)]$
openstack security group create secgroup01

+-----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field           | Value                                                                                                                                                                                  |
+-----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| created_at      | 2019-05-16T01:26:38Z                                                                                                                                                                   |
| description     | secgroup01                                                                                                                                                                             |
| id              | ad1ebf01-28b1-4234-a6c0-76bb00b34821                                                                                                                                                   |
| location        | Munch({'project': Munch({'domain_name': 'default', 'domain_id': None, 'name': 'hiroshima', 'id': u'caab6ec580994e6481cd104b9d210f3f'}), 'cloud': '', 'region_name': '', 'zone': None}) |
| name            | secgroup01                                                                                                                                                                             |
| project_id      | caab6ec580994e6481cd104b9d210f3f                                                                                                                                                       |
| revision_number | 1                                                                                                                                                                                      |
| rules           | created_at='2019-05-16T01:26:38Z', direction='egress', ethertype='IPv4', id='42815c4f-107c-40a6-833f-122066b8c894', updated_at='2019-05-16T01:26:38Z'                                  |
|                 | created_at='2019-05-16T01:26:38Z', direction='egress', ethertype='IPv6', id='7c00cccc-6bf8-4cb1-81e8-ca92835d2417', updated_at='2019-05-16T01:26:38Z'                                  |
| tags            | []                                                                                                                                                                                     |
| updated_at      | 2019-05-16T01:26:38Z                                                                                                                                                                   |
+-----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

[cent@dlp ~(keystone)]$
openstack security group list

+--------------------------------------+------------+------------------------+----------------------------------+------+
| ID                                   | Name       | Description            | Project                          | Tags |
+--------------------------------------+------------+------------------------+----------------------------------+------+
| 1f039dac-a0b2-4b7b-abf8-3750f1cd1322 | default    | Default security group | caab6ec580994e6481cd104b9d210f3f | []   |
| ad1ebf01-28b1-4234-a6c0-76bb00b34821 | secgroup01 | secgroup01             | caab6ec580994e6481cd104b9d210f3f | []   |
+--------------------------------------+------------+------------------------+----------------------------------+------+

# 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 | 7a:4c:fa:cb:71:bc:d8:e6:2c:a2:75:ce:76:09:82:0b |
| name        | mykey                                           |
| user_id     | f762f107c86d4018b94e29df969a61ba                |
+-------------+-------------------------------------------------+

[cent@dlp ~(keystone)]$
openstack keypair list

+-------+-------------------------------------------------+
| Name  | Fingerprint                                     |
+-------+-------------------------------------------------+
| mykey | 7a:4c:fa:cb:71:bc:d8:e6:2c:a2:75:ce:76:09:82:0b |
+-------+-------------------------------------------------+

[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 CentOS7 --security-group secgroup01 --nic net-id=$netID --key-name mykey CentOS_7
+-----------------------------+------------------------------------------------+
| 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                   | 54P95Zzj5YF5                                   |
| config_drive                |                                                |
| created                     | 2019-05-16T01:27:22Z                           |
| flavor                      | m1.small (0)                                   |
| hostId                      |                                                |
| id                          | 274f22b0-9ec3-44d6-99aa-5aa646aba053           |
| image                       | CentOS7 (0d0bf9ae-9d4c-445f-b2e0-5b322dffa988) |
| key_name                    | mykey                                          |
| name                        | CentOS_7                                       |
| progress                    | 0                                              |
| project_id                  | caab6ec580994e6481cd104b9d210f3f               |
| properties                  |                                                |
| security_groups             | name='ad1ebf01-28b1-4234-a6c0-76bb00b34821'    |
| status                      | BUILD                                          |
| updated                     | 2019-05-16T01:27:22Z                           |
| user_id                     | b5dd128c2fd744c892ad7d1fb39d21a0               |
| volumes_attached            |                                                |
+-----------------------------+------------------------------------------------+

# show status ([BUILD] status is shown when building instance)

[cent@dlp ~(keystone)]$
openstack server list

+--------------------------------------+----------+--------+----------+---------+----------+
| ID                                   | Name     | Status | Networks | Image   | Flavor   |
+--------------------------------------+----------+--------+----------+---------+----------+
| 274f22b0-9ec3-44d6-99aa-5aa646aba053 | CentOS_7 | BUILD  |          | CentOS7 | m1.small |
+--------------------------------------+----------+--------+----------+---------+----------+

# when starting noramlly, the status turns to [ACTIVE]

[cent@dlp ~(keystone)]$
openstack server list

+--------------------------------------+----------+--------+-----------------------+---------+----------+
| ID                                   | Name     | Status | Networks              | Image   | Flavor   |
+--------------------------------------+----------+--------+-----------------------+---------+----------+
| 274f22b0-9ec3-44d6-99aa-5aa646aba053 | CentOS_7 | ACTIVE | sharednet1=10.0.0.213 | CentOS7 | 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        | 2019-05-16T01:30:26Z                                                                                 |
| description       |                                                                                                      |
| direction         | ingress                                                                                              |
| ether_type        | IPv4                                                                                                 |
| id                | ce2dce7c-b75a-4776-b8d8-410ea53330a8                                                                 |
| location          | Munch({'project': Munch({'domain_name': 'default', 'domain_id': None, 'name': 'hiroshima', 'id'...}) |
| name              | None                                                                                                 |
| port_range_max    | None                                                                                                 |
| port_range_min    | None                                                                                                 |
| project_id        | caab6ec580994e6481cd104b9d210f3f                                                                     |
| protocol          | icmp                                                                                                 |
| remote_group_id   | None                                                                                                 |
| remote_ip_prefix  | 0.0.0.0/0                                                                                            |
| revision_number   | 0                                                                                                    |
| security_group_id | ad1ebf01-28b1-4234-a6c0-76bb00b34821                                                                 |
| tags              | []                                                                                                   |
| updated_at        | 2019-05-16T01:30:26Z                                                                                 |
+-------------------+------------------------------------------------------------------------------------------------------+

# permit SSH

[cent@dlp ~(keystone)]$
openstack security group rule create --protocol tcp --dst-port 22:22 secgroup01

+-------------------+--------------------------------------------------------------------------------------------------------+
| Field             | Value                                                                                                  |
+-------------------+--------------------------------------------------------------------------------------------------------+
| created_at        | 2019-05-16T01:30:49Z                                                                                   |
| description       |                                                                                                        |
| direction         | ingress                                                                                                |
| ether_type        | IPv4                                                                                                   |
| id                | 315ccaf8-7523-4397-b446-c2b14fd78d1a                                                                   |
| location          | Munch({'project': Munch({'domain_name': 'default', 'domain_id': None, 'name': 'hiroshima', 'id': u...) |
| name              | None                                                                                                   |
| port_range_max    | 22                                                                                                     |
| port_range_min    | 22                                                                                                     |
| project_id        | caab6ec580994e6481cd104b9d210f3f                                                                       |
| protocol          | tcp                                                                                                    |
| remote_group_id   | None                                                                                                   |
| remote_ip_prefix  | 0.0.0.0/0                                                                                              |
| revision_number   | 0                                                                                                      |
| security_group_id | ad1ebf01-28b1-4234-a6c0-76bb00b34821                                                                   |
| tags              | []                                                                                                     |
| updated_at        | 2019-05-16T01:30:49Z                                                                                   |
+-------------------+--------------------------------------------------------------------------------------------------------+

[cent@dlp ~(keystone)]$
openstack security group rule list

+--------------------------------------+-------------+-----------+------------+--------------------------------------+--------------------------------------+
| ID                                   | IP Protocol | IP Range  | Port Range | Remote Security Group                | Security Group                       |
+--------------------------------------+-------------+-----------+------------+--------------------------------------+--------------------------------------+
| 0cbd5a1d-5783-46b6-8926-543db588858c | None        | None      |            | None                                 | 1f039dac-a0b2-4b7b-abf8-3750f1cd1322 |
| 315ccaf8-7523-4397-b446-c2b14fd78d1a | tcp         | 0.0.0.0/0 | 22:22      | None                                 | ad1ebf01-28b1-4234-a6c0-76bb00b34821 |
| 42815c4f-107c-40a6-833f-122066b8c894 | None        | None      |            | None                                 | ad1ebf01-28b1-4234-a6c0-76bb00b34821 |
| 529502ea-6944-4a79-b791-bb558bb85bcc | None        | None      |            | 1f039dac-a0b2-4b7b-abf8-3750f1cd1322 | 1f039dac-a0b2-4b7b-abf8-3750f1cd1322 |
| 6dcb7052-ec15-476d-b83b-8cac0c1667e0 | None        | None      |            | None                                 | 1f039dac-a0b2-4b7b-abf8-3750f1cd1322 |
| 7c00cccc-6bf8-4cb1-81e8-ca92835d2417 | None        | None      |            | None                                 | ad1ebf01-28b1-4234-a6c0-76bb00b34821 |
| a53ee0e0-1935-4204-931e-c0ee673a6478 | None        | None      |            | 1f039dac-a0b2-4b7b-abf8-3750f1cd1322 | 1f039dac-a0b2-4b7b-abf8-3750f1cd1322 |
| ce2dce7c-b75a-4776-b8d8-410ea53330a8 | icmp        | 0.0.0.0/0 |            | None                                 | ad1ebf01-28b1-4234-a6c0-76bb00b34821 |
+--------------------------------------+-------------+-----------+------------+--------------------------------------+--------------------------------------+
[3] Login to the instance with SSH.
[cent@dlp ~(keystone)]$
openstack server list

+--------------------------------------+----------+--------+-----------------------+---------+----------+
| ID                                   | Name     | Status | Networks              | Image   | Flavor   |
+--------------------------------------+----------+--------+-----------------------+---------+----------+
| 274f22b0-9ec3-44d6-99aa-5aa646aba053 | CentOS_7 | ACTIVE | sharednet1=10.0.0.213 | CentOS7 | m1.small |
+--------------------------------------+----------+--------+-----------------------+---------+----------+

[cent@dlp ~(keystone)]$
ping 10.0.0.213 -c3

PING 10.0.0.213 (10.0.0.213) 56(84) bytes of data.
64 bytes from 10.0.0.213: icmp_seq=1 ttl=64 time=2.56 ms
64 bytes from 10.0.0.213: icmp_seq=2 ttl=64 time=1.15 ms
64 bytes from 10.0.0.213: icmp_seq=3 ttl=64 time=22.9 ms

--- 10.0.0.213 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 1.155/8.892/22.959/9.963 ms

[cent@dlp ~(keystone)]$
ssh centos@10.0.0.213
The authenticity of host '10.0.0.213 (10.0.0.213)' can't be established.
ECDSA key fingerprint is SHA256:8JIQDmNwua3M1autPC3YjFOpTuP525whYxaWojC9fbw.
ECDSA key fingerprint is MD5:8e:78:d9:bf:0f:25:e4:14:b2:a2:0a:d7:58:cc:f4:66.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.213' (ECDSA) to the list of known hosts.
Last login: Wed May 15 00:33:45 2019
[centos@centos-7 ~]$    
# just logined

[4] If you'd like to stop an instance, it's also possible to control with openstack command like follows.
[cent@dlp ~(keystone)]$
openstack server list

+--------------------------------------+----------+--------+-----------------------+---------+----------+
| ID                                   | Name     | Status | Networks              | Image   | Flavor   |
+--------------------------------------+----------+--------+-----------------------+---------+----------+
| 274f22b0-9ec3-44d6-99aa-5aa646aba053 | CentOS_7 | ACTIVE | sharednet1=10.0.0.213 | CentOS7 | m1.small |
+--------------------------------------+----------+--------+-----------------------+---------+----------+

# stop instance

[cent@dlp ~(keystone)]$
openstack server stop CentOS_7

[cent@dlp ~(keystone)]$
openstack server list

+--------------------------------------+----------+---------+-----------------------+---------+----------+
| ID                                   | Name     | Status  | Networks              | Image   | Flavor   |
+--------------------------------------+----------+---------+-----------------------+---------+----------+
| 274f22b0-9ec3-44d6-99aa-5aa646aba053 | CentOS_7 | SHUTOFF | sharednet1=10.0.0.213 | CentOS7 | m1.small |
+--------------------------------------+----------+---------+-----------------------+---------+----------+

# start instance

[cent@dlp ~(keystone)]$
openstack server start CentOS_7

[cent@dlp ~(keystone)]$
openstack server list

+--------------------------------------+----------+--------+-----------------------+---------+----------+
| ID                                   | Name     | Status | Networks              | Image   | Flavor   |
+--------------------------------------+----------+--------+-----------------------+---------+----------+
| 274f22b0-9ec3-44d6-99aa-5aa646aba053 | CentOS_7 | ACTIVE | sharednet1=10.0.0.213 | CentOS7 | 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   |
+--------------------------------------+----------+--------+-----------------------+---------+----------+
| 274f22b0-9ec3-44d6-99aa-5aa646aba053 | CentOS_7 | ACTIVE | sharednet1=10.0.0.213 | CentOS7 | m1.small |
+--------------------------------------+----------+--------+-----------------------+---------+----------+

[cent@dlp ~(keystone)]$
openstack console url show CentOS_7

+-------+--------------------------------------------------------------------------------+
| Field | Value                                                                          |
+-------+--------------------------------------------------------------------------------+
| type  | novnc                                                                          |
| url   | http://10.0.0.30:6080/vnc_auto.html?token=e25c53a7-8e23-4cd6-985f-e99ee708e9e4 |
+-------+--------------------------------------------------------------------------------+
[6] Access to the URL which was displayed by the command above.
Matched Content