OpenStack Caracal : インスタンスを起動する2024/05/21 |
仮想マシンインスタンスを起動します。 |
|
[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 | | 3 | m1.medium | 8192 | 10 | 0 | 4 | True | | 4 | m2.medium | 8192 | 10 | 10 | 4 | True | +----+-----------+------+------+-----------+-------+-----------+ # 利用可能なイメージ確認 ubuntu@dlp ~(keystone)$ openstack image list +--------------------------------------+------------+--------+ | ID | Name | Status | +--------------------------------------+------------+--------+ | 7620a182-99f2-4132-9c6e-4b2da962b241 | Ubuntu2404 | active | +--------------------------------------+------------+--------+ # 利用可能なネットワーク確認 ubuntu@dlp ~(keystone)$ openstack network list +--------------------------------+------------+--------------------------------+ | ID | Name | Subnets | +--------------------------------+------------+--------------------------------+ | 8ffae09c-4cf2-4f65-97d4- | sharednet1 | 6f639fb2-8aa7-46f4-8124- | | 8a204e523b7a | | a2eb32d3a8c7 | +--------------------------------+------------+--------------------------------+ # インスタンス用のセキュリティグループを作成 ubuntu@dlp ~(keystone)$ openstack security group create secgroup01 +-----------------+------------------------------------------------------------+ | Field | Value | +-----------------+------------------------------------------------------------+ | created_at | 2024-05-21T01:28:53Z | | description | secgroup01 | | id | bfeb7f29-41e4-4532-a4a9-31f79c567497 | | name | secgroup01 | | project_id | 18ede7365bdc430093e8fd4a90f77369 | | revision_number | 1 | | rules | created_at='2024-05-21T01:28:53Z', direction='egress', | | | ethertype='IPv4', | | | id='24b92da6-fc55-4eb3-8ac4-6f31c6e6c95e', | | | standard_attr_id='20', updated_at='2024-05-21T01:28:53Z' | | | created_at='2024-05-21T01:28:53Z', direction='egress', | | | ethertype='IPv6', | | | id='d62ec0a3-0837-4d33-a368-8e5e675fd0b6', | | | standard_attr_id='21', updated_at='2024-05-21T01:28:53Z' | | shared | False | | stateful | True | | tags | [] | | updated_at | 2024-05-21T01:28:53Z | +-----------------+------------------------------------------------------------+ubuntu@dlp ~(keystone)$ openstack security group list +------------------+------------+------------------+--------------------+------+ | ID | Name | Description | Project | Tags | +------------------+------------+------------------+--------------------+------+ | 6a835325-7c60- | default | Default security | 18ede7365bdc430093 | [] | | 4109-8030- | | group | e8fd4a90f77369 | | | aaf9c6d499d9 | | | | | | bfeb7f29-41e4- | secgroup01 | secgroup01 | 18ede7365bdc430093 | [] | | 4532-a4a9- | | | e8fd4a90f77369 | | | 31f79c567497 | | | | | +------------------+------------+------------------+--------------------+------+ # インスタンス接続用の SSH キーペア作成 ubuntu@dlp ~(keystone)$ ssh-keygen -q -N "" Enter file in which to save the key (/home/ubuntu/.ssh/id_ed25519): # 公開鍵登録 ubuntu@dlp ~(keystone)$ openstack keypair create --public-key ~/.ssh/id_ed25519.pub mykey +-------------+-------------------------------------------------+ | Field | Value | +-------------+-------------------------------------------------+ | created_at | None | | fingerprint | 15:4f:61:7b:45:32:70:bc:55:3e:e6:ef:43:6b:34:06 | | id | mykey | | is_deleted | None | | name | mykey | | type | ssh | | user_id | b9371d015e0d43dca74f29161448ffd2 | +-------------+-------------------------------------------------+ubuntu@dlp ~(keystone)$ openstack keypair list +-------+-------------------------------------------------+------+ | Name | Fingerprint | Type | +-------+-------------------------------------------------+------+ | mykey | 15:4f:61:7b:45:32:70:bc:55:3e:e6:ef:43:6b:34:06 | ssh | +-------+-------------------------------------------------+------+
ubuntu@dlp ~(keystone)$
netID=$(openstack network list | grep sharednet1 | awk '{ print $2 }') # インスタンス作成/起動 ubuntu@dlp ~(keystone)$ openstack server create --flavor m1.small --image Ubuntu2404 --security-group secgroup01 --nic net-id=$netID --key-name mykey Ubuntu-2404
+--------------------------------------+---------------------------------------+ | 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 | 6x3tFrYHBTsM | | config_drive | | | created | 2024-05-21T01:31:59Z | | flavor | m1.small (2) | | hostId | | | id | e499117a-58e4-4c75-9712-836d4fbe5572 | | image | Ubuntu2404 (7620a182-99f2-4132-9c6e- | | | 4b2da962b241) | | key_name | mykey | | name | Ubuntu-2404 | | os-extended-volumes:volumes_attached | [] | | progress | 0 | | project_id | 18ede7365bdc430093e8fd4a90f77369 | | properties | | | security_groups | name='bfeb7f29-41e4-4532-a4a9- | | | 31f79c567497' | | status | BUILD | | updated | 2024-05-21T01:31:59Z | | user_id | b9371d015e0d43dca74f29161448ffd2 | +--------------------------------------+---------------------------------------+ # 動作確認 (起動直後しばらくは [BUILD] ステータスとなっている) ubuntu@dlp ~(keystone)$ openstack server list +--------------+-------------+--------+-----------+------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------+-------------+--------+-----------+------------+----------+ | e499117a- | Ubuntu-2204 | BUILD | | Ubuntu2204 | m1.small | | 58e4-4c75- | | | | | | | 9712- | | | | | | | 836d4fbe5572 | | | | | | +--------------+-------------+--------+-----------+------------+----------+ # 正常に起動すると [ACTIVE] ステータスとなる ubuntu@dlp ~(keystone)$ openstack server list +--------------+-------------+--------+---------------+------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------+-------------+--------+---------------+------------+----------+ | e499117a- | Ubuntu-2404 | ACTIVE | sharednet1=10 | Ubuntu2404 | m1.small | | 58e4-4c75- | | | .0.0.219 | | | | 9712- | | | | | | | 836d4fbe5572 | | | | | | +--------------+-------------+--------+---------------+------------+----------+ |
[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-05-21T01:33:41Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | a3fddb94-1c85-4f62-939d-7308b0677126 | | name | None | | normalized_cidr | 0.0.0.0/0 | | port_range_max | None | | port_range_min | None | | project_id | 18ede7365bdc430093e8fd4a90f77369 | | 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 | bfeb7f29-41e4-4532-a4a9-31f79c567497 | | tags | [] | | updated_at | 2024-05-21T01:33:41Z | +-------------------------+--------------------------------------+ # 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-05-21T01:34:07Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | ec433a0d-3d18-4878-acaa-ba8281805399 | | name | None | | normalized_cidr | 0.0.0.0/0 | | port_range_max | 22 | | port_range_min | 22 | | project_id | 18ede7365bdc430093e8fd4a90f77369 | | 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 | bfeb7f29-41e4-4532-a4a9-31f79c567497 | | tags | [] | | updated_at | 2024-05-21T01:34:07Z | +-------------------------+--------------------------------------+ubuntu@dlp ~(keystone)$ openstack security group rule list secgroup01 +----------+-------------+-----------+----------+------------+-----------+-----------------------+----------------------+ | ID | IP Protocol | Ethertype | IP Range | Port Range | Direction | Remote Security Group | Remote Address Group | +----------+-------------+-----------+----------+------------+-----------+-----------------------+----------------------+ | 24b92da6 | None | IPv4 | 0.0.0.0/ | | egress | None | None | | -fc55- | | | 0 | | | | | | 4eb3- | | | | | | | | | 8ac4- | | | | | | | | | 6f31c6e6 | | | | | | | | | c95e | | | | | | | | | a3fddb94 | icmp | IPv4 | 0.0.0.0/ | | ingress | None | None | | -1c85- | | | 0 | | | | | | 4f62- | | | | | | | | | 939d- | | | | | | | | | 7308b067 | | | | | | | | | 7126 | | | | | | | | | d62ec0a3 | None | IPv6 | ::/0 | | egress | None | None | | -0837- | | | | | | | | | 4d33- | | | | | | | | | a368- | | | | | | | | | 8e5e675f | | | | | | | | | d0b6 | | | | | | | | | ec433a0d | tcp | IPv4 | 0.0.0.0/ | 22:22 | ingress | None | None | | -3d18- | | | 0 | | | | | | 4878- | | | | | | | | | acaa-ba8 | | | | | | | | | 28180539 | | | | | | | | | 9 | | | | | | | | +----------+-------------+-----------+----------+------------+-----------+-----------------------+----------------------+ |
[3] | 起動した仮想マシンインスタンスに SSH ログインします。 |
ubuntu@dlp ~(keystone)$ openstack server list +--------------+-------------+--------+---------------+------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------+-------------+--------+---------------+------------+----------+ | e499117a- | Ubuntu-2404 | ACTIVE | sharednet1=10 | Ubuntu2404 | m1.small | | 58e4-4c75- | | | .0.0.219 | | | | 9712- | | | | | | | 836d4fbe5572 | | | | | | +--------------+-------------+--------+---------------+------------+----------+ # ping 応答が返ってくれば OK ubuntu@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.11 ms 64 bytes from 10.0.0.219: icmp_seq=2 ttl=64 time=0.443 ms 64 bytes from 10.0.0.219: icmp_seq=3 ttl=64 time=0.272 ms --- 10.0.0.219 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2013ms rtt min/avg/max/mdev = 0.272/0.607/1.108/0.360 ms # SSH でログイン ubuntu@dlp ~(keystone)$ ssh ubuntu@10.0.0.219
The authenticity of host '10.0.0.219 (10.0.0.219)' can't be established. ED25519 key fingerprint is SHA256:bSxv3n3xqTFacKUkkm33Uarf3mnbyC8IKrycTenpMMw. 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.219' (ED25519) to the list of known hosts. Welcome to Ubuntu 24.04 LTS (GNU/Linux 6.8.0-31-generic x86_64) ..... ..... To run a command as administrator (user "root"), use "sudo <command>". See "man sudo_root" for details. ubuntu@ubuntu-2404:~$ # ログインできた |
[4] | 一旦作成して起動した仮想マシンインスタンスを停止/起動する場合は、以下のように [start/stop] コマンドで制御できます。 |
ubuntu@dlp ~(keystone)$ openstack server list +--------------+-------------+--------+---------------+------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------+-------------+--------+---------------+------------+----------+ | e499117a- | Ubuntu-2404 | ACTIVE | sharednet1=10 | Ubuntu2404 | m1.small | | 58e4-4c75- | | | .0.0.219 | | | | 9712- | | | | | | | 836d4fbe5572 | | | | | | +--------------+-------------+--------+---------------+------------+----------+ # インスタンス停止 ubuntu@dlp ~(keystone)$ openstack server stop Ubuntu-2404 ubuntu@dlp ~(keystone)$ openstack server list +--------------+-------------+---------+---------------+------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------+-------------+---------+---------------+------------+----------+ | e499117a- | Ubuntu-2404 | SHUTOFF | sharednet1=10 | Ubuntu2404 | m1.small | | 58e4-4c75- | | | .0.0.219 | | | | 9712- | | | | | | | 836d4fbe5572 | | | | | | +--------------+-------------+---------+---------------+------------+----------+ # インスタンスを起動する ubuntu@dlp ~(keystone)$ openstack server start Ubuntu-2404 ubuntu@dlp ~(keystone)$ openstack server list +--------------+-------------+--------+---------------+------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------+-------------+--------+---------------+------------+----------+ | e499117a- | Ubuntu-2404 | ACTIVE | sharednet1=10 | Ubuntu2404 | m1.small | | 58e4-4c75- | | | .0.0.219 | | | | 9712- | | | | | | | 836d4fbe5572 | | | | | | +--------------+-------------+--------+---------------+------------+----------+ |
[5] | VNC コンソールを取得して Web ブラウザーでのアクセスも可能です。 |
ubuntu@dlp ~(keystone)$ openstack server list +--------------+-------------+--------+---------------+------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------+-------------+--------+---------------+------------+----------+ | e499117a- | Ubuntu-2404 | ACTIVE | sharednet1=10 | Ubuntu2404 | m1.small | | 58e4-4c75- | | | .0.0.219 | | | | 9712- | | | | | | | 836d4fbe5572 | | | | | | +--------------+-------------+--------+---------------+------------+----------+ubuntu@dlp ~(keystone)$ openstack console url show Ubuntu-2404 +----------+-------------------------------------------------------------------+ | Field | Value | +----------+-------------------------------------------------------------------+ | protocol | vnc | | type | novnc | | url | https://dlp.srv.world:6080/vnc_auto.html?path=%3Ftoken%3Dd8e8dcd4 | | | -8368-408c-83f7-e38dd2299f77 | +----------+-------------------------------------------------------------------+ |
[6] | 上記コマンドで表示された URL に Web アクセスすると、インスタンスに接続され、操作が可能となります。 |
Sponsored Link |