OpenStack Caracal : インスタンスを起動する2024/08/06 |
仮想マシンインスタンスを起動します。 |
|
[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 | +--------------------------------------+----------------+--------+ | cfa9783d-ca91-4e3b-8016-81e3336bd5f0 | CentOS-Stream9 | active | +--------------------------------------+----------------+--------+ # 利用可能なネットワーク確認 [cent@dlp ~(keystone)]$ openstack network list +--------------------------------------+------------+--------------------------------------+ | ID | Name | Subnets | +--------------------------------------+------------+--------------------------------------+ | 03d69fb5-74c0-4273-874e-e2fd0af17339 | sharednet1 | cff78758-3fdc-450c-9cec-3b8b3b6cb44b | +--------------------------------------+------------+--------------------------------------+ # インスタンス用のセキュリティグループを作成 [cent@dlp ~(keystone)]$ openstack security group create secgroup01 +-----------------+---------------------------------------------------------------------------+ | Field | Value | +-----------------+---------------------------------------------------------------------------+ | created_at | 2024-08-06T01:39:55Z | | description | secgroup01 | | id | d5d3512c-720d-4899-89d6-cca61c92bf7b | | name | secgroup01 | | project_id | 03a31c43ede44dcbaacb05c870920e81 | | revision_number | 1 | | rules | created_at='2024-08-06T01:39:55Z', direction='egress', ethertype='IPv6... | | | created_at='2024-08-06T01:39:55Z', direction='egress', ethertype='IPv4... | | shared | False | | stateful | True | | tags | [] | | updated_at | 2024-08-06T01:39:55Z | +-----------------+---------------------------------------------------------------------------+[cent@dlp ~(keystone)]$ openstack security group list +--------------------------------------+------------+------------------------+----------------------------------+------+ | ID | Name | Description | Project | Tags | +--------------------------------------+------------+------------------------+----------------------------------+------+ | d5d3512c-720d-4899-89d6-cca61c92bf7b | secgroup01 | secgroup01 | 03a31c43ede44dcbaacb05c870920e81 | [] | | f7e1a959-708b-4a3f-8cd7-29775c1693b3 | default | Default security group | 03a31c43ede44dcbaacb05c870920e81 | [] | +--------------------------------------+------------+------------------------+----------------------------------+------+ # インスタンス接続用の 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 | b7:34:22:64:14:53:97:6f:18:50:b2:be:1a:34:8d:1b | | id | mykey | | is_deleted | None | | name | mykey | | type | ssh | | user_id | 8a9b46168b42480f889ad4fad3ca6ee4 | +-------------+-------------------------------------------------+[cent@dlp ~(keystone)]$ openstack keypair list +-------+-------------------------------------------------+------+ | Name | Fingerprint | Type | +-------+-------------------------------------------------+------+ | mykey | b7:34:22:64:14:53:97:6f:18:50:b2:be:1a:34:8d:1b | 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 | | | 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 | pAsxkr8F7srv | | config_drive | | | created | 2024-08-06T01:51:16Z | | flavor | m1.small (2) | | hostId | | | id | 3692b2c3-4378-4285-930d-b0cf4d765d66 | | image | CentOS-Stream9 (cfa9783d-ca91-4e3b-8016-81e3336bd5f0) | | key_name | mykey | | name | CentOS-St9 | | os-extended-volumes:volumes_attached | [] | | progress | 0 | | project_id | 03a31c43ede44dcbaacb05c870920e81 | | properties | | | security_groups | name='d5d3512c-720d-4899-89d6-cca61c92bf7b' | | status | BUILD | | updated | 2024-08-06T01:51:16Z | | user_id | 8a9b46168b42480f889ad4fad3ca6ee4 | +--------------------------------------+-------------------------------------------------------+ # 動作確認 (起動直後しばらくは [BUILD] ステータスとなっている) [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+------------+--------+----------+----------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+------------+--------+----------+----------------+----------+ | 3692b2c3-4378-4285-930d-b0cf4d765d66 | CentOS-St9 | BUILD | | CentOS-Stream9 | m1.small | +--------------------------------------+------------+--------+----------+----------------+----------+ # 正常に起動すると [ACTIVE] ステータスとなる [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+------------+--------+-----------------------+----------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+------------+--------+-----------------------+----------------+----------+ | 3692b2c3-4378-4285-930d-b0cf4d765d66 | CentOS-St9 | ACTIVE | sharednet1=10.0.0.213 | 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-08-06T01:52:48Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 47cf6993-e64b-4535-97cb-0098fcd2b9ab | | name | None | | normalized_cidr | 0.0.0.0/0 | | port_range_max | None | | port_range_min | None | | project_id | 03a31c43ede44dcbaacb05c870920e81 | | 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 | d5d3512c-720d-4899-89d6-cca61c92bf7b | | tags | [] | | updated_at | 2024-08-06T01:52:48Z | +-------------------------+--------------------------------------+ # 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-08-06T01:53:07Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 9ac7852e-0086-4ddf-933d-5a3cfcb39f09 | | name | None | | normalized_cidr | 0.0.0.0/0 | | port_range_max | 22 | | port_range_min | 22 | | project_id | 03a31c43ede44dcbaacb05c870920e81 | | 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 | d5d3512c-720d-4899-89d6-cca61c92bf7b | | tags | [] | | updated_at | 2024-08-06T01:53:07Z | +-------------------------+--------------------------------------+[cent@dlp ~(keystone)]$ openstack security group rule list secgroup01 +--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+ | ID | IP Protocol | Ethertype | IP Range | Port Range | Direction | Remote Security Group | Remote Address Group | +--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+ | 47cf6993-e64b-4535-97cb-0098fcd2b9ab | icmp | IPv4 | 0.0.0.0/0 | | ingress | None | None | | 658e04ee-e885-47eb-ac87-475ef4d3bf69 | None | IPv6 | ::/0 | | egress | None | None | | 9ac7852e-0086-4ddf-933d-5a3cfcb39f09 | tcp | IPv4 | 0.0.0.0/0 | 22:22 | ingress | None | None | | ab266b47-96ae-45e4-ba77-dbe19200da30 | None | IPv4 | 0.0.0.0/0 | | egress | None | None | +--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+ |
[3] | 起動した仮想マシンインスタンスに SSH ログインします。 |
[cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+------------+--------+-----------------------+----------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+------------+--------+-----------------------+----------------+----------+ | 3692b2c3-4378-4285-930d-b0cf4d765d66 | CentOS-St9 | ACTIVE | sharednet1=10.0.0.213 | CentOS-Stream9 | m1.small | +--------------------------------------+------------+--------+-----------------------+----------------+----------+ # ping 応答が返ってくれば OK [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=1.09 ms 64 bytes from 10.0.0.213: icmp_seq=2 ttl=64 time=0.561 ms 64 bytes from 10.0.0.213: icmp_seq=3 ttl=64 time=0.568 ms --- 10.0.0.213 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2017ms rtt min/avg/max/mdev = 0.561/0.741/1.094/0.249 ms # SSH でログイン [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. ED25519 key fingerprint is SHA256:f3STGxHRbBVHSNBPKC5kh1dj2i3elejqkaK/WJwIyqU. 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.213' (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 | +--------------------------------------+------------+--------+-----------------------+----------------+----------+ | 3692b2c3-4378-4285-930d-b0cf4d765d66 | CentOS-St9 | ACTIVE | sharednet1=10.0.0.213 | CentOS-Stream9 | m1.small | +--------------------------------------+------------+--------+-----------------------+----------------+----------+ # インスタンス停止 [cent@dlp ~(keystone)]$ openstack server stop CentOS-St9 [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+------------+---------+-----------------------+----------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+------------+---------+-----------------------+----------------+----------+ | 3692b2c3-4378-4285-930d-b0cf4d765d66 | CentOS-St9 | SHUTOFF | sharednet1=10.0.0.213 | CentOS-Stream9 | m1.small | +--------------------------------------+------------+---------+-----------------------+----------------+----------+ # インスタンスを起動する [cent@dlp ~(keystone)]$ openstack server start CentOS-St9 [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+------------+--------+-----------------------+----------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+------------+--------+-----------------------+----------------+----------+ | 3692b2c3-4378-4285-930d-b0cf4d765d66 | CentOS-St9 | ACTIVE | sharednet1=10.0.0.213 | 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%3D78eaec39-ad8d-40f8-b68a-8ad4fa9a598f | +----------+-----------------------------------------------------------------------------------------------+ |
[6] | 上記コマンドで表示された URL に Web アクセスすると、インスタンスに接続され、操作が可能となります。 |
Sponsored Link |
|