OpenStack Antelope : インスタンスを起動する2023/03/23 |
仮想マシンインスタンスを起動します。
|
|
[1] | Openstack を利用したい任意のユーザーでログインし、Openstack 認証用の設定ファイルを作成して、仮想マシンインスタンスを作成/起動します。 認証ファイル中のプロジェクト名やユーザー名/パスワードは Keystone に登録したものを指定します。 |
ubuntu@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=https://dlp.srv.world:5000/v3 export OS_IDENTITY_API_VERSION=3 export OS_IMAGE_API_VERSION=2 export PS1='\u@\h \W(keystone)\$ '
ubuntu@dlp:~$
chmod 600 ~/keystonerc ubuntu@dlp:~$ source ~/keystonerc ubuntu@dlp ~(keystone)$ echo "source ~/keystonerc " >> ~/.bash_profile
# 利用可能な [flavor] 確認 ubuntu@dlp ~(keystone)$ openstack flavor list +----+----------+------+------+-----------+-------+-----------+ | ID | Name | RAM | Disk | Ephemeral | VCPUs | Is Public | +----+----------+------+------+-----------+-------+-----------+ | 1 | m1.small | 2048 | 10 | 0 | 1 | True | | 2 | m1.large | 8192 | 10 | 10 | 4 | True | +----+----------+------+------+-----------+-------+-----------+ # 利用可能なイメージ確認 ubuntu@dlp ~(keystone)$ openstack image list +--------------------------------------+------------+--------+ | ID | Name | Status | +--------------------------------------+------------+--------+ | 00ea6e97-0e97-4cb4-8ac4-2409c28f0289 | Ubuntu2204 | active | +--------------------------------------+------------+--------+ # 利用可能なネットワーク確認 ubuntu@dlp ~(keystone)$ openstack network list +--------------------------------------+------------+--------------------------------------+ | ID | Name | Subnets | +--------------------------------------+------------+--------------------------------------+ | 94911606-a533-43d4-b8c9-8ce984fa51a8 | sharednet1 | 5f4b2faa-b3e9-44f8-a13f-61de26724123 | +--------------------------------------+------------+--------------------------------------+ # インスタンス用のセキュリティグループを作成 ubuntu@dlp ~(keystone)$ openstack security group create secgroup01 +-----------------+---------------------------------------------------------------------------+ | Field | Value | +-----------------+---------------------------------------------------------------------------+ | created_at | 2023-03-23T05:18:28Z | | description | secgroup01 | | id | 636bd8f6-e533-436d-9a16-40440dcc22e2 | | name | secgroup01 | | project_id | e294bd7c00314facacdb46c36fb54ee9 | | revision_number | 1 | | rules | created_at='2023-03-23T05:18:28Z', direction='egress', ethertype='IPv6... | | | created_at='2023-03-23T05:18:28Z', direction='egress', ethertype='IPv4... | | shared | False | | stateful | True | | tags | [] | | updated_at | 2023-03-23T05:18:28Z | +-----------------+---------------------------------------------------------------------------+ubuntu@dlp ~(keystone)$ openstack security group list +--------------------------------------+------------+------------------------+----------------------------------+------+ | ID | Name | Description | Project | Tags | +--------------------------------------+------------+------------------------+----------------------------------+------+ | 11bc3d90-581a-443f-94b7-e7cfea87a653 | default | Default security group | e294bd7c00314facacdb46c36fb54ee9 | [] | | 636bd8f6-e533-436d-9a16-40440dcc22e2 | secgroup01 | secgroup01 | e294bd7c00314facacdb46c36fb54ee9 | [] | +--------------------------------------+------------+------------------------+----------------------------------+------+ # インスタンス接続用の 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 | b6:55:e6:68:65:fc:17:bc:ac:b4:86:9c:79:5c:7f:10 | | id | mykey | | is_deleted | None | | name | mykey | | type | ssh | | user_id | 85236576a97e492791abe70c217c8898 | +-------------+-------------------------------------------------+ubuntu@dlp ~(keystone)$ openstack keypair list +-------+-------------------------------------------------+------+ | Name | Fingerprint | Type | +-------+-------------------------------------------------+------+ | mykey | b6:55:e6:68:65:fc:17:bc:ac:b4:86:9c:79:5c:7f:10 | 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 | HTzXRC6D9x6H | | config_drive | | | created | 2023-03-23T06:29:37Z | | flavor | m1.small (1) | | hostId | | | id | 1e52774f-4982-49eb-8564-544ff2b79634 | | image | Ubuntu2204 (00ea6e97-0e97-4cb4-8ac4-2409c28f0289) | | key_name | mykey | | name | Ubuntu-2204 | | progress | 0 | | project_id | e294bd7c00314facacdb46c36fb54ee9 | | properties | | | security_groups | name='636bd8f6-e533-436d-9a16-40440dcc22e2' | | status | BUILD | | updated | 2023-03-23T06:29:37Z | | user_id | 85236576a97e492791abe70c217c8898 | | volumes_attached | | +-----------------------------+---------------------------------------------------+ # 動作確認 (起動直後しばらくは [BUILD] ステータスとなっている) ubuntu@dlp ~(keystone)$ openstack server list +--------------------------------------+-------------+--------+----------+------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-------------+--------+----------+------------+----------+ | 1e52774f-4982-49eb-8564-544ff2b79634 | Ubuntu-2204 | BUILD | | Ubuntu2204 | m1.small | +--------------------------------------+-------------+--------+----------+------------+----------+ # 正常に起動すると [ACTIVE] ステータスとなる ubuntu@dlp ~(keystone)$ openstack server list +--------------------------------------+-------------+--------+-----------------------+------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-------------+--------+-----------------------+------------+----------+ | 1e52774f-4982-49eb-8564-544ff2b79634 | Ubuntu-2204 | ACTIVE | sharednet1=10.0.0.208 | Ubuntu2204 | m1.small | +--------------------------------------+-------------+--------+-----------------------+------------+----------+ |
[2] | 起動した仮想マシンインスタンスに SSH 接続できるように、先に作成したセキュリティグループにポート許可の設定を追加します。 |
# ICMP 許可 ubuntu@dlp ~(keystone)$ openstack security group rule create --protocol icmp --ingress secgroup01 +-------------------------+--------------------------------------+ | Field | Value | +-------------------------+--------------------------------------+ | created_at | 2023-03-23T06:32:02Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | c179b63a-1f0a-4f97-877d-6a922a432cd3 | | name | None | | normalized_cidr | 0.0.0.0/0 | | port_range_max | None | | port_range_min | None | | project_id | e294bd7c00314facacdb46c36fb54ee9 | | 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 | 636bd8f6-e533-436d-9a16-40440dcc22e2 | | tags | [] | | updated_at | 2023-03-23T06:32:02Z | +-------------------------+--------------------------------------+ # SSH 許可 ubuntu@dlp ~(keystone)$ openstack security group rule create --protocol tcp --dst-port 22:22 secgroup01 +-------------------------+--------------------------------------+ | Field | Value | +-------------------------+--------------------------------------+ | created_at | 2023-03-23T06:32:23Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 86cb7857-2d65-414d-bd25-62ab833a7e0a | | name | None | | normalized_cidr | 0.0.0.0/0 | | port_range_max | 22 | | port_range_min | 22 | | project_id | e294bd7c00314facacdb46c36fb54ee9 | | 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 | 636bd8f6-e533-436d-9a16-40440dcc22e2 | | tags | [] | | updated_at | 2023-03-23T06:32:23Z | +-------------------------+--------------------------------------+ubuntu@dlp ~(keystone)$ openstack security group rule list secgroup01 +--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+ | ID | IP Protocol | Ethertype | IP Range | Port Range | Direction | Remote Security Group | Remote Address Group | +--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+ | 245dba76-7e60-4037-9be1-c7de87ef55ea | None | IPv6 | ::/0 | | egress | None | None | | 307ee7fe-333a-49d6-bc9d-5f6eacd5f77c | None | IPv4 | 0.0.0.0/0 | | egress | None | None | | 86cb7857-2d65-414d-bd25-62ab833a7e0a | tcp | IPv4 | 0.0.0.0/0 | 22:22 | ingress | None | None | | c179b63a-1f0a-4f97-877d-6a922a432cd3 | icmp | IPv4 | 0.0.0.0/0 | | ingress | None | None | +--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+ |
[3] | 起動した仮想マシンインスタンスに SSH ログインします。 |
ubuntu@dlp ~(keystone)$ openstack server list +--------------------------------------+-------------+--------+-----------------------+------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-------------+--------+-----------------------+------------+----------+ | 1e52774f-4982-49eb-8564-544ff2b79634 | Ubuntu-2204 | ACTIVE | sharednet1=10.0.0.208 | Ubuntu2204 | m1.small | +--------------------------------------+-------------+--------+-----------------------+------------+----------+ # ping 応答が返ってくれば OK ubuntu@dlp ~(keystone)$ ping 10.0.0.208 -c3 PING 10.0.0.208 (10.0.0.208) 56(84) bytes of data. 64 bytes from 10.0.0.208: icmp_seq=1 ttl=64 time=1.38 ms 64 bytes from 10.0.0.208: icmp_seq=2 ttl=64 time=0.449 ms 64 bytes from 10.0.0.208: icmp_seq=3 ttl=64 time=0.361 ms --- 10.0.0.208 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2026ms rtt min/avg/max/mdev = 0.361/0.731/1.384/0.462 ms # SSH でログイン ubuntu@dlp ~(keystone)$ ssh ubuntu@10.0.0.208
The authenticity of host '10.0.0.208 (10.0.0.208)' can't be established. ED25519 key fingerprint is SHA256:AHXQs23AdteFO/2JYaLbXPJn6UyeQTgtshCixr5exFs. 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.208' (ED25519) to the list of known hosts. Welcome to Ubuntu 22.04.2 LTS (GNU/Linux 5.15.0-67-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 | +--------------------------------------+-------------+--------+-----------------------+------------+----------+ | 1e52774f-4982-49eb-8564-544ff2b79634 | Ubuntu-2204 | ACTIVE | sharednet1=10.0.0.208 | Ubuntu2204 | m1.small | +--------------------------------------+-------------+--------+-----------------------+------------+----------+ # インスタンス停止 ubuntu@dlp ~(keystone)$ openstack server stop Ubuntu-2004 ubuntu@dlp ~(keystone)$ openstack server list +--------------------------------------+-------------+---------+-----------------------+------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-------------+---------+-----------------------+------------+----------+ | 1e52774f-4982-49eb-8564-544ff2b79634 | Ubuntu-2204 | SHUTOFF | sharednet1=10.0.0.208 | Ubuntu2204 | m1.small | +--------------------------------------+-------------+---------+-----------------------+------------+----------+ # インスタンスを起動する ubuntu@dlp ~(keystone)$ openstack server start Ubuntu-2004 ubuntu@dlp ~(keystone)$ openstack server list +--------------------------------------+-------------+--------+-----------------------+------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-------------+--------+-----------------------+------------+----------+ | 1e52774f-4982-49eb-8564-544ff2b79634 | Ubuntu-2204 | ACTIVE | sharednet1=10.0.0.208 | Ubuntu2204 | m1.small | +--------------------------------------+-------------+--------+-----------------------+------------+----------+ |
[5] | VNC コンソールを取得して Web ブラウザーでのアクセスも可能です。 |
ubuntu@dlp ~(keystone)$ openstack server list +--------------------------------------+-------------+--------+-----------------------+------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-------------+--------+-----------------------+------------+----------+ | 1e52774f-4982-49eb-8564-544ff2b79634 | Ubuntu-2204 | ACTIVE | sharednet1=10.0.0.208 | Ubuntu2204 | m1.small | +--------------------------------------+-------------+--------+-----------------------+------------+----------+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%3D7f7ea88b-6264-49ab-b23c-c4433eb11313 | +----------+-----------------------------------------------------------------------------------------------+ |
[6] | 上記コマンドで表示された URL に Web アクセスすると、インスタンスに接続され、操作が可能となります。 |
Sponsored Link |
|