Ubuntu 22.04
Sponsored Link

OpenStack Caracal : インスタンスを起動する2024/04/05

 
仮想マシンインスタンスを起動します。
[1] Openstack 用の環境変数を設定した任意のユーザーでログインして、仮想マシンインスタンスを作成/起動します。
# 利用可能な [flavor] 確認

ubuntu@dlp ~(keystone)$
openstack flavor list

+----+----------+------+------+-----------+-------+-----------+
| ID | Name     |  RAM | Disk | Ephemeral | VCPUs | Is Public |
+----+----------+------+------+-----------+-------+-----------+
| 1  | m1.tiny  | 2048 |   10 |         0 |     1 | True      |
| 2  | m1.small | 4096 |   10 |         0 |     2 | True      |
| 4  | m1.large | 8192 |   10 |        10 |     4 | True      |
+----+----------+------+------+-----------+-------+-----------+

# 利用可能なイメージ確認

ubuntu@dlp ~(keystone)$
openstack image list

+--------------------------------------+------------+--------+
| ID                                   | Name       | Status |
+--------------------------------------+------------+--------+
| a4442fac-b3e8-4400-a9c4-8f15daff64cb | Ubuntu2204 | active |
+--------------------------------------+------------+--------+

# 利用可能なネットワーク確認

ubuntu@dlp ~(keystone)$
openstack network list

+--------------------------------+------------+--------------------------------+
| ID                             | Name       | Subnets                        |
+--------------------------------+------------+--------------------------------+
| 1fdae2b1-50f1-40ae-b362-       | sharednet1 | 798fa9eb-e997-45b3-9701-       |
| 41a42a79933c                   |            | 3e13d12b301a                   |
+--------------------------------+------------+--------------------------------+

# インスタンス用のセキュリティグループを作成

ubuntu@dlp ~(keystone)$
openstack security group create secgroup01

+-----------------+------------------------------------------------------------+
| Field           | Value                                                      |
+-----------------+------------------------------------------------------------+
| created_at      | 2024-04-05T04:28:32Z                                       |
| description     | secgroup01                                                 |
| id              | 455943eb-887d-4758-acff-94af23beecd0                       |
| name            | secgroup01                                                 |
| project_id      | d45d0cefc6724cfe95103e729e265015                           |
| revision_number | 1                                                          |
| rules           | created_at='2024-04-05T04:28:32Z', direction='egress',     |
|                 | ethertype='IPv4',                                          |
|                 | id='19927569-32a0-4e78-9f7e-9c24e8d7eef5',                 |
|                 | standard_attr_id='20', updated_at='2024-04-05T04:28:32Z'   |
|                 | created_at='2024-04-05T04:28:32Z', direction='egress',     |
|                 | ethertype='IPv6',                                          |
|                 | id='9eaf071b-d62d-493e-a2fb-397d5aee71a0',                 |
|                 | standard_attr_id='21', updated_at='2024-04-05T04:28:32Z'   |
| shared          | False                                                      |
| stateful        | True                                                       |
| tags            | []                                                         |
| updated_at      | 2024-04-05T04:28:32Z                                       |
+-----------------+------------------------------------------------------------+

ubuntu@dlp ~(keystone)$
openstack security group list

+------------------+------------+------------------+--------------------+------+
| ID               | Name       | Description      | Project            | Tags |
+------------------+------------+------------------+--------------------+------+
| 34d3e928-a7d2-   | default    | Default security | d45d0cefc6724cfe95 | []   |
| 4533-b46b-       |            | group            | 103e729e265015     |      |
| c8571faac3e3     |            |                  |                    |      |
| 455943eb-887d-   | secgroup01 | secgroup01       | d45d0cefc6724cfe95 | []   |
| 4758-acff-       |            |                  | 103e729e265015     |      |
| 94af23beecd0     |            |                  |                    |      |
+------------------+------------+------------------+--------------------+------+

# インスタンス接続用の SSH キーペア作成

ubuntu@dlp ~(keystone)$
ssh-keygen -q -N ""

Enter file in which to save the key (/home/ubuntu/.ssh/id_rsa):
# 公開鍵登録

ubuntu@dlp ~(keystone)$
openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey

+-------------+-------------------------------------------------+
| Field       | Value                                           |
+-------------+-------------------------------------------------+
| created_at  | None                                            |
| fingerprint | 06:20:72:5f:0d:3d:03:60:af:32:6b:05:4e:63:c4:23 |
| id          | mykey                                           |
| is_deleted  | None                                            |
| name        | mykey                                           |
| type        | ssh                                             |
| user_id     | f7a19fba25e84e63bf885722de49c269                |
+-------------+-------------------------------------------------+

ubuntu@dlp ~(keystone)$
openstack keypair list

+-------+-------------------------------------------------+------+
| Name  | Fingerprint                                     | Type |
+-------+-------------------------------------------------+------+
| mykey | 06:20:72:5f:0d:3d:03:60:af:32:6b:05:4e:63:c4:23 | ssh  |
+-------+-------------------------------------------------+------+

ubuntu@dlp ~(keystone)$
netID=$(openstack network list | grep sharednet1 | awk '{ print $2 }')

# インスタンス作成/起動

ubuntu@dlp ~(keystone)$
openstack server create --flavor m1.small --image Ubuntu2204 --security-group secgroup01 --nic net-id=$netID --key-name mykey Ubuntu-2204
+-----------------------------+------------------------------------------------+
| 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                   | QEEfWm4pLcVH                                   |
| config_drive                |                                                |
| created                     | 2024-04-05T04:31:00Z                           |
| flavor                      | m1.small (2)                                   |
| hostId                      |                                                |
| id                          | 4fdf7c7f-b8ef-4c46-a1c4-f5a0741a2472           |
| image                       | Ubuntu2204                                     |
|                             | (a4442fac-b3e8-4400-a9c4-8f15daff64cb)         |
| key_name                    | mykey                                          |
| name                        | Ubuntu-2204                                    |
| progress                    | 0                                              |
| project_id                  | d45d0cefc6724cfe95103e729e265015               |
| properties                  |                                                |
| security_groups             | name='455943eb-887d-4758-acff-94af23beecd0'    |
| status                      | BUILD                                          |
| updated                     | 2024-04-05T04:31:00Z                           |
| user_id                     | f7a19fba25e84e63bf885722de49c269               |
| volumes_attached            |                                                |
+-----------------------------+------------------------------------------------+

# 動作確認 (起動直後しばらくは [BUILD] ステータスとなっている)

ubuntu@dlp ~(keystone)$
openstack server list

+--------------+-------------+--------+-----------+------------+----------+
| ID           | Name        | Status | Networks  | Image      | Flavor   |
+--------------+-------------+--------+-----------+------------+----------+
| 4fdf7c7f-    | Ubuntu-2204 | BUILD  |           | Ubuntu2204 | m1.small |
| b8ef-4c46-   |             |        |           |            |          |
| a1c4-        |             |        |           |            |          |
| f5a0741a2472 |             |        |           |            |          |
+--------------+-------------+--------+-----------+------------+----------+

# 正常に起動すると [ACTIVE] ステータスとなる

ubuntu@dlp ~(keystone)$
openstack server list

+--------------+-------------+--------+---------------+------------+----------+
| ID           | Name        | Status | Networks      | Image      | Flavor   |
+--------------+-------------+--------+---------------+------------+----------+
| 4fdf7c7f-    | Ubuntu-2204 | ACTIVE | sharednet1=10 | Ubuntu2204 | m1.small |
| b8ef-4c46-   |             |        | .0.0.216      |            |          |
| a1c4-        |             |        |               |            |          |
| f5a0741a2472 |             |        |               |            |          |
+--------------+-------------+--------+---------------+------------+----------+
[2] 起動した仮想マシンインスタンスに SSH 接続できるように、先に作成したセキュリティグループにポート許可の設定を追加します。
# ICMP 許可

ubuntu@dlp ~(keystone)$
openstack security group rule create --protocol icmp --ingress secgroup01

+-------------------------+--------------------------------------+
| Field                   | Value                                |
+-------------------------+--------------------------------------+
| belongs_to_default_sg   | False                                |
| created_at              | 2024-04-05T04:33:08Z                 |
| description             |                                      |
| direction               | ingress                              |
| ether_type              | IPv4                                 |
| id                      | 25cc922c-1b26-4b89-b8bc-10619a108936 |
| name                    | None                                 |
| normalized_cidr         | 0.0.0.0/0                            |
| port_range_max          | None                                 |
| port_range_min          | None                                 |
| project_id              | d45d0cefc6724cfe95103e729e265015     |
| 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       | 455943eb-887d-4758-acff-94af23beecd0 |
| tags                    | []                                   |
| updated_at              | 2024-04-05T04:33:08Z                 |
+-------------------------+--------------------------------------+

# SSH 許可

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

+-------------------------+--------------------------------------+
| Field                   | Value                                |
+-------------------------+--------------------------------------+
| belongs_to_default_sg   | False                                |
| created_at              | 2024-04-05T04:33:50Z                 |
| description             |                                      |
| direction               | ingress                              |
| ether_type              | IPv4                                 |
| id                      | f19c96a6-fd4a-45b0-af27-ca68211956fd |
| name                    | None                                 |
| normalized_cidr         | 0.0.0.0/0                            |
| port_range_max          | 22                                   |
| port_range_min          | 22                                   |
| project_id              | d45d0cefc6724cfe95103e729e265015     |
| 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       | 455943eb-887d-4758-acff-94af23beecd0 |
| tags                    | []                                   |
| updated_at              | 2024-04-05T04:33:50Z                 |
+-------------------------+--------------------------------------+

ubuntu@dlp ~(keystone)$
openstack security group rule list secgroup01

+----------+-------------+-----------+----------+------------+-----------+-----------------------+----------------------+
| ID       | IP Protocol | Ethertype | IP Range | Port Range | Direction | Remote Security Group | Remote Address Group |
+----------+-------------+-----------+----------+------------+-----------+-----------------------+----------------------+
| 19927569 | None        | IPv4      | 0.0.0.0/ |            | egress    | None                  | None                 |
| -32a0-   |             |           | 0        |            |           |                       |                      |
| 4e78-    |             |           |          |            |           |                       |                      |
| 9f7e-    |             |           |          |            |           |                       |                      |
| 9c24e8d7 |             |           |          |            |           |                       |                      |
| eef5     |             |           |          |            |           |                       |                      |
| 25cc922c | icmp        | IPv4      | 0.0.0.0/ |            | ingress   | None                  | None                 |
| -1b26-   |             |           | 0        |            |           |                       |                      |
| 4b89-    |             |           |          |            |           |                       |                      |
| b8bc-    |             |           |          |            |           |                       |                      |
| 10619a10 |             |           |          |            |           |                       |                      |
| 8936     |             |           |          |            |           |                       |                      |
| 9eaf071b | None        | IPv6      | ::/0     |            | egress    | None                  | None                 |
| -d62d-   |             |           |          |            |           |                       |                      |
| 493e-    |             |           |          |            |           |                       |                      |
| a2fb-    |             |           |          |            |           |                       |                      |
| 397d5aee |             |           |          |            |           |                       |                      |
| 71a0     |             |           |          |            |           |                       |                      |
| f19c96a6 | tcp         | IPv4      | 0.0.0.0/ | 22:22      | ingress   | None                  | None                 |
| -fd4a-   |             |           | 0        |            |           |                       |                      |
| 45b0-    |             |           |          |            |           |                       |                      |
| af27-    |             |           |          |            |           |                       |                      |
| ca682119 |             |           |          |            |           |                       |                      |
| 56fd     |             |           |          |            |           |                       |                      |
+----------+-------------+-----------+----------+------------+-----------+-----------------------+----------------------+
[3] 起動した仮想マシンインスタンスに SSH ログインします。
ubuntu@dlp ~(keystone)$
openstack server list

+--------------+-------------+--------+---------------+------------+----------+
| ID           | Name        | Status | Networks      | Image      | Flavor   |
+--------------+-------------+--------+---------------+------------+----------+
| 4fdf7c7f-    | Ubuntu-2204 | ACTIVE | sharednet1=10 | Ubuntu2204 | m1.small |
| b8ef-4c46-   |             |        | .0.0.216      |            |          |
| a1c4-        |             |        |               |            |          |
| f5a0741a2472 |             |        |               |            |          |
+--------------+-------------+--------+---------------+------------+----------+

# ping 応答が返ってくれば OK

ubuntu@dlp ~(keystone)$
ping 10.0.0.216 -c3

PING 10.0.0.216 (10.0.0.216) 56(84) bytes of data.
64 bytes from 10.0.0.216: icmp_seq=1 ttl=64 time=1.18 ms
64 bytes from 10.0.0.216: icmp_seq=2 ttl=64 time=0.465 ms
64 bytes from 10.0.0.216: icmp_seq=3 ttl=64 time=0.303 ms

--- 10.0.0.216 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 0.303/0.650/1.184/0.382 ms

# SSH でログイン

ubuntu@dlp ~(keystone)$
ssh ubuntu@10.0.0.216
The authenticity of host '10.0.0.216 (10.0.0.216)' can't be established.
ED25519 key fingerprint is SHA256:KEOz7HbWfEDM/DXDvXB4l0fyl/GRYcoeYojs7M3gPBI.
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.216' (ED25519) to the list of known hosts.
Welcome to Ubuntu 22.04.4 LTS (GNU/Linux 5.15.0-101-generic x86_64)

.....
.....

To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

ubuntu@ubuntu-2204:~$     # ログインできた
[4] 一旦作成して起動した仮想マシンインスタンスを停止/起動する場合は、以下のように [start/stop] コマンドで制御できます。
ubuntu@dlp ~(keystone)$
openstack server list

+--------------+-------------+--------+---------------+------------+----------+
| ID           | Name        | Status | Networks      | Image      | Flavor   |
+--------------+-------------+--------+---------------+------------+----------+
| 4fdf7c7f-    | Ubuntu-2204 | ACTIVE | sharednet1=10 | Ubuntu2204 | m1.small |
| b8ef-4c46-   |             |        | .0.0.216      |            |          |
| a1c4-        |             |        |               |            |          |
| f5a0741a2472 |             |        |               |            |          |
+--------------+-------------+--------+---------------+------------+----------+

# インスタンス停止

ubuntu@dlp ~(keystone)$
openstack server stop Ubuntu-2004

ubuntu@dlp ~(keystone)$
openstack server list

+--------------+-------------+---------+---------------+------------+----------+
| ID           | Name        | Status  | Networks      | Image      | Flavor   |
+--------------+-------------+---------+---------------+------------+----------+
| 4fdf7c7f-    | Ubuntu-2204 | SHUTOFF | sharednet1=10 | Ubuntu2204 | m1.small |
| b8ef-4c46-   |             |         | .0.0.216      |            |          |
| a1c4-        |             |         |               |            |          |
| f5a0741a2472 |             |         |               |            |          |
+--------------+-------------+---------+---------------+------------+----------+

# インスタンスを起動する

ubuntu@dlp ~(keystone)$
openstack server start Ubuntu-2004

ubuntu@dlp ~(keystone)$
openstack server list

+--------------+-------------+--------+---------------+------------+----------+
| ID           | Name        | Status | Networks      | Image      | Flavor   |
+--------------+-------------+--------+---------------+------------+----------+
| 4fdf7c7f-    | Ubuntu-2204 | ACTIVE | sharednet1=10 | Ubuntu2204 | m1.small |
| b8ef-4c46-   |             |        | .0.0.216      |            |          |
| a1c4-        |             |        |               |            |          |
| f5a0741a2472 |             |        |               |            |          |
+--------------+-------------+--------+---------------+------------+----------+
[5] VNC コンソールを取得して Web ブラウザーでのアクセスも可能です。
ubuntu@dlp ~(keystone)$
openstack server list

+--------------+-------------+--------+---------------+------------+----------+
| ID           | Name        | Status | Networks      | Image      | Flavor   |
+--------------+-------------+--------+---------------+------------+----------+
| 4fdf7c7f-    | Ubuntu-2204 | ACTIVE | sharednet1=10 | Ubuntu2204 | m1.small |
| b8ef-4c46-   |             |        | .0.0.216      |            |          |
| a1c4-        |             |        |               |            |          |
| f5a0741a2472 |             |        |               |            |          |
+--------------+-------------+--------+---------------+------------+----------+

ubuntu@dlp ~(keystone)$
openstack console url show Ubuntu-2204

+----------+-------------------------------------------------------------------+
| Field    | Value                                                             |
+----------+-------------------------------------------------------------------+
| protocol | vnc                                                               |
| type     | novnc                                                             |
| url      | https://dlp.srv.world:6080/vnc_auto.html?path=%3Ftoken%3D2b331fc4 |
|          | -453e-47d6-8187-8ce246a7a1ca                                      |
+----------+-------------------------------------------------------------------+
[6] 上記コマンドで表示された URL に Web アクセスすると、インスタンスに接続され、操作が可能となります。
関連コンテンツ