CentOS Stream 9
Sponsored Link

OpenStack Dalmatian : インスタンスを起動する2024/10/09

 

仮想マシンインスタンスを起動します。

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

[cent@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      |
| 3  | m1.medium |  8192 |   10 |         0 |     4 | True      |
| 4  | m1.large  | 16384 |   10 |         0 |     8 | True      |
| 5  | m2.large  | 16384 |   10 |        10 |     8 | True      |
+----+-----------+-------+------+-----------+-------+-----------+

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

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

+--------------------------------------+----------------+--------+
| ID                                   | Name           | Status |
+--------------------------------------+----------------+--------+
| 75e0d976-4075-4488-8f26-87d4a50aebe9 | CentOS-Stream9 | active |
+--------------------------------------+----------------+--------+

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

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

+--------------------------------------+------------+--------------------------------------+
| ID                                   | Name       | Subnets                              |
+--------------------------------------+------------+--------------------------------------+
| 6939c291-ee09-481b-985a-baaee9248d3b | sharednet1 | 8a92efea-7b16-45b0-9f99-9e787371e95b |
+--------------------------------------+------------+--------------------------------------+

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

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

+-----------------+---------------------------------------------------------------------------+
| Field           | Value                                                                     |
+-----------------+---------------------------------------------------------------------------+
| created_at      | 2024-10-09T08:08:44Z                                                      |
| description     | secgroup01                                                                |
| id              | 8cf6191b-d9e3-4ffa-bbe0-505a66631030                                      |
| name            | secgroup01                                                                |
| project_id      | 756e2b4937c44d3991028e294f92d89a                                          |
| revision_number | 1                                                                         |
| rules           | created_at='2024-10-09T08:08:44Z', direction='egress', ethertype='IPv6... |
|                 | created_at='2024-10-09T08:08:44Z', direction='egress', ethertype='IPv4... |
| shared          | False                                                                     |
| stateful        | True                                                                      |
| tags            | []                                                                        |
| updated_at      | 2024-10-09T08:08:44Z                                                      |
+-----------------+---------------------------------------------------------------------------+

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

+--------------------------------------+------------+------------------------+----------------------------------+------+
| ID                                   | Name       | Description            | Project                          | Tags |
+--------------------------------------+------------+------------------------+----------------------------------+------+
| 8cf6191b-d9e3-4ffa-bbe0-505a66631030 | secgroup01 | secgroup01             | 756e2b4937c44d3991028e294f92d89a | []   |
| b7870e42-4f47-439b-adbf-6e9912bcb675 | default    | Default security group | 756e2b4937c44d3991028e294f92d89a | []   |
+--------------------------------------+------------+------------------------+----------------------------------+------+

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

[cent@dlp ~(keystone)]$
ssh-keygen -q -N ""

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

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

+-------------+-------------------------------------------------+
| Field       | Value                                           |
+-------------+-------------------------------------------------+
| created_at  | None                                            |
| fingerprint | a9:e0:a5:58:72:86:f3:77:64:22:51:1d:a3:51:64:8d |
| id          | mykey                                           |
| is_deleted  | None                                            |
| name        | mykey                                           |
| type        | ssh                                             |
| user_id     | 19c7530debb54eb0bfe6dc47aae3df32                |
+-------------+-------------------------------------------------+

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

+-------+-------------------------------------------------+------+
| Name  | Fingerprint                                     | Type |
+-------+-------------------------------------------------+------+
| mykey | a9:e0:a5:58:72:86:f3:77:64:22:51:1d:a3:51:64:8d | ssh  |
+-------+-------------------------------------------------+------+

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

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

[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         | None                                                     |
| OS-EXT-SRV-ATTR:host                | None                                                     |
| OS-EXT-SRV-ATTR:hostname            | centos-st9                                               |
| OS-EXT-SRV-ATTR:hypervisor_hostname | None                                                     |
| OS-EXT-SRV-ATTR:instance_name       | None                                                     |
| OS-EXT-SRV-ATTR:kernel_id           | None                                                     |
| OS-EXT-SRV-ATTR:launch_index        | None                                                     |
| OS-EXT-SRV-ATTR:ramdisk_id          | None                                                     |
| OS-EXT-SRV-ATTR:reservation_id      | None                                                     |
| OS-EXT-SRV-ATTR:root_device_name    | None                                                     |
| OS-EXT-SRV-ATTR:user_data           | None                                                     |
| OS-EXT-STS:power_state              | N/A                                                      |
| 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                          | None                                                     |
| accessIPv6                          | None                                                     |
| addresses                           | N/A                                                      |
| adminPass                           | Q5csDLMnjy7h                                             |
| config_drive                        | None                                                     |
| created                             | 2024-10-09T08:10:53Z                                     |
| description                         | None                                                     |
| flavor                              | description=, disk='10', ephemeral='0', , id='m1.smal... |
| hostId                              | None                                                     |
| host_status                         | None                                                     |
| id                                  | b993f42a-adc7-45dd-b36f-6131a12b9eb7                     |
| image                               | CentOS-Stream9 (75e0d976-4075-4488-8f26-87d4a50aebe9)    |
| key_name                            | mykey                                                    |
| locked                              | None                                                     |
| locked_reason                       | None                                                     |
| name                                | CentOS-St9                                               |
| pinned_availability_zone            | None                                                     |
| progress                            | None                                                     |
| project_id                          | 756e2b4937c44d3991028e294f92d89a                         |
| properties                          | None                                                     |
| security_groups                     | name='8cf6191b-d9e3-4ffa-bbe0-505a66631030'              |
| server_groups                       | None                                                     |
| status                              | BUILD                                                    |
| tags                                |                                                          |
| trusted_image_certificates          | None                                                     |
| updated                             | 2024-10-09T08:10:53Z                                     |
| user_id                             | 19c7530debb54eb0bfe6dc47aae3df32                         |
| volumes_attached                    |                                                          |
+-------------------------------------+----------------------------------------------------------+

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

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

+--------------------------------------+------------+--------+----------+----------------+----------+
| ID                                   | Name       | Status | Networks | Image          | Flavor   |
+--------------------------------------+------------+--------+----------+----------------+----------+
| b993f42a-adc7-45dd-b36f-6131a12b9eb7 | CentOS-St9 | BUILD  |          | CentOS-Stream9 | m1.small |
+--------------------------------------+------------+--------+----------+----------------+----------+

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

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

+--------------------------------------+------------+--------+-----------------------+----------------+----------+
| ID                                   | Name       | Status | Networks              | Image          | Flavor   |
+--------------------------------------+------------+--------+-----------------------+----------------+----------+
| b993f42a-adc7-45dd-b36f-6131a12b9eb7 | CentOS-St9 | ACTIVE | sharednet1=10.0.0.230 | CentOS-Stream9 | m1.small |
+--------------------------------------+------------+--------+-----------------------+----------------+----------+
[2] 起動した仮想マシンインスタンスに SSH 接続できるように、先に作成したセキュリティグループにポート許可の設定を追加します。
# ICMP 許可

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

+-------------------------+--------------------------------------+
| Field                   | Value                                |
+-------------------------+--------------------------------------+
| belongs_to_default_sg   | False                                |
| created_at              | 2024-10-09T08:12:30Z                 |
| description             |                                      |
| direction               | ingress                              |
| ether_type              | IPv4                                 |
| id                      | 13469673-c265-4292-b60b-feb46149a920 |
| name                    | None                                 |
| normalized_cidr         | 0.0.0.0/0                            |
| port_range_max          | None                                 |
| port_range_min          | None                                 |
| project_id              | 756e2b4937c44d3991028e294f92d89a     |
| 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       | 8cf6191b-d9e3-4ffa-bbe0-505a66631030 |
| tags                    | []                                   |
| updated_at              | 2024-10-09T08:12:30Z                 |
+-------------------------+--------------------------------------+

# SSH 許可

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

+-------------------------+--------------------------------------+
| Field                   | Value                                |
+-------------------------+--------------------------------------+
| belongs_to_default_sg   | False                                |
| created_at              | 2024-10-09T08:12:48Z                 |
| description             |                                      |
| direction               | ingress                              |
| ether_type              | IPv4                                 |
| id                      | 34dd38f5-3c0f-4a6e-81ac-94e1e6ca4f3e |
| name                    | None                                 |
| normalized_cidr         | 0.0.0.0/0                            |
| port_range_max          | 22                                   |
| port_range_min          | 22                                   |
| project_id              | 756e2b4937c44d3991028e294f92d89a     |
| 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       | 8cf6191b-d9e3-4ffa-bbe0-505a66631030 |
| tags                    | []                                   |
| updated_at              | 2024-10-09T08:12:48Z                 |
+-------------------------+--------------------------------------+

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

+--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+
| ID                                   | IP Protocol | Ethertype | IP Range  | Port Range | Direction | Remote Security Group | Remote Address Group |
+--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+
| 13469673-c265-4292-b60b-feb46149a920 | icmp        | IPv4      | 0.0.0.0/0 |            | ingress   | None                  | None                 |
| 293abad5-8fa8-423f-bfe4-1168b6223736 | None        | IPv6      | ::/0      |            | egress    | None                  | None                 |
| 34dd38f5-3c0f-4a6e-81ac-94e1e6ca4f3e | tcp         | IPv4      | 0.0.0.0/0 | 22:22      | ingress   | None                  | None                 |
| d2663982-46fb-4f26-b8d0-71c83bfe8db3 | None        | IPv4      | 0.0.0.0/0 |            | egress    | None                  | None                 |
+--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+
[3] 起動した仮想マシンインスタンスに SSH ログインします。
[cent@dlp ~(keystone)]$
openstack server list

+--------------------------------------+------------+--------+-----------------------+----------------+----------+
| ID                                   | Name       | Status | Networks              | Image          | Flavor   |
+--------------------------------------+------------+--------+-----------------------+----------------+----------+
| b993f42a-adc7-45dd-b36f-6131a12b9eb7 | CentOS-St9 | ACTIVE | sharednet1=10.0.0.230 | CentOS-Stream9 | m1.small |
+--------------------------------------+------------+--------+-----------------------+----------------+----------+

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

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

PING 10.0.0.230 (10.0.0.230) 56(84) bytes of data.
64 bytes from 10.0.0.230: icmp_seq=1 ttl=64 time=0.918 ms
64 bytes from 10.0.0.230: icmp_seq=2 ttl=64 time=0.827 ms
64 bytes from 10.0.0.230: icmp_seq=3 ttl=64 time=0.432 ms

--- 10.0.0.230 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2047ms
rtt min/avg/max/mdev = 0.432/0.725/0.918/0.210 ms

# SSH でログイン

[cent@dlp ~(keystone)]$
ssh centos@10.0.0.230
The authenticity of host '10.0.0.230 (10.0.0.230)' can't be established.
ED25519 key fingerprint is SHA256:G7xHFrUYe5Gdkr2Qi1lDUpG5mUWnEMOpQVr/FpY4D3s.
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.230' (ED25519) to the list of known hosts.
[centos@centos-st9 ~]$     # ログインできた
[4] 一旦作成して起動した仮想マシンインスタンスを停止/起動する場合は、以下のように [start/stop] コマンドで制御できます。
[cent@dlp ~(keystone)]$
openstack server list

+--------------------------------------+------------+--------+-----------------------+----------------+----------+
| ID                                   | Name       | Status | Networks              | Image          | Flavor   |
+--------------------------------------+------------+--------+-----------------------+----------------+----------+
| b993f42a-adc7-45dd-b36f-6131a12b9eb7 | CentOS-St9 | ACTIVE | sharednet1=10.0.0.230 | CentOS-Stream9 | m1.small |
+--------------------------------------+------------+--------+-----------------------+----------------+----------+

# インスタンス停止

[cent@dlp ~(keystone)]$
openstack server stop CentOS-St9

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

+--------------------------------------+------------+---------+-----------------------+----------------+----------+
| ID                                   | Name       | Status  | Networks              | Image          | Flavor   |
+--------------------------------------+------------+---------+-----------------------+----------------+----------+
| b993f42a-adc7-45dd-b36f-6131a12b9eb7 | CentOS-St9 | SHUTOFF | sharednet1=10.0.0.230 | CentOS-Stream9 | m1.small |
+--------------------------------------+------------+---------+-----------------------+----------------+----------+

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

[cent@dlp ~(keystone)]$
openstack server start CentOS-St9

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

+--------------------------------------+------------+--------+-----------------------+----------------+----------+
| ID                                   | Name       | Status | Networks              | Image          | Flavor   |
+--------------------------------------+------------+--------+-----------------------+----------------+----------+
| b993f42a-adc7-45dd-b36f-6131a12b9eb7 | CentOS-St9 | ACTIVE | sharednet1=10.0.0.230 | CentOS-Stream9 | m1.small |
+--------------------------------------+------------+--------+-----------------------+----------------+----------+
[5] VNC コンソールを取得して Web ブラウザーでのアクセスも可能です。
[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%3De713f751-e16b-43fa-bdf7-629f73e32a0e |
+----------+-----------------------------------------------------------------------------------------------+
[6] 上記コマンドで表示された URL に Web アクセスすると、インスタンスに接続され、操作が可能となります。
関連コンテンツ