OpenStack Zed : インスタンスを起動する2023/06/27 |
仮想マシンインスタンスを起動します。
|
|
[1] | Openstack を利用したい任意のユーザーでログインし、Openstack 認証用の設定ファイルを作成して、仮想マシンインスタンスを作成/起動します。 認証ファイル中のプロジェクト名やユーザー名/パスワードは Keystone に登録したものを指定します。 |
debian@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)\$ '
debian@dlp:~$
chmod 600 ~/keystonerc debian@dlp:~$ source ~/keystonerc debian@dlp ~(keystone)$ echo "source ~/keystonerc " >> ~/.bash_profile
# 利用可能な [flavor] 確認 debian@dlp ~(keystone)$ openstack flavor list +----+-----------+------+------+-----------+-------+-----------+ | ID | Name | RAM | Disk | Ephemeral | VCPUs | Is Public | +----+-----------+------+------+-----------+-------+-----------+ | 1 | m1.small | 2048 | 10 | 0 | 1 | True | | 2 | m1.medium | 4096 | 10 | 0 | 2 | True | | 3 | m2.large | 8192 | 10 | 10 | 4 | True | +----+-----------+------+------+-----------+-------+-----------+ # 利用可能なイメージ確認 debian@dlp ~(keystone)$ openstack image list +--------------------------------------+----------+--------+ | ID | Name | Status | +--------------------------------------+----------+--------+ | 9e7f953f-9918-453d-aeeb-def892492966 | Debian12 | active | +--------------------------------------+----------+--------+ # 利用可能なネットワーク確認 debian@dlp ~(keystone)$ openstack network list +--------------------------------------+------------+--------------------------------------+ | ID | Name | Subnets | +--------------------------------------+------------+--------------------------------------+ | 69962e3a-3e00-41b8-866b-d67cc50b11b9 | sharednet1 | 2af9e60c-505e-439d-80af-61636d4266ca | +--------------------------------------+------------+--------------------------------------+ # インスタンス用のセキュリティグループを作成 debian@dlp ~(keystone)$ openstack security group create secgroup01 +-----------------+-----------------------------------------------------------------------------+ | Field | Value | +-----------------+-----------------------------------------------------------------------------+ | created_at | 2023-06-27T02:43:45Z | | description | secgroup01 | | id | dfc47032-e1bd-4283-b156-faf9d19591d2 | | name | secgroup01 | | project_id | 1c2f5dc8c4f9494fbaaa4217c8e3585a | | revision_number | 1 | | rules | created_at='2023-06-27T02:43:45Z', direction='egress', ethertype='IPv4',... | | | created_at='2023-06-27T02:43:45Z', direction='egress', ethertype='IPv6',... | | stateful | True | | tags | [] | | updated_at | 2023-06-27T02:43:45Z | +-----------------+-----------------------------------------------------------------------------+debian@dlp ~(keystone)$ openstack security group list +--------------------------------------+------------+------------------------+----------------------------------+------+ | ID | Name | Description | Project | Tags | +--------------------------------------+------------+------------------------+----------------------------------+------+ | 75505dff-0fa3-4737-be7e-5ebee1984d5f | default | Default security group | 1c2f5dc8c4f9494fbaaa4217c8e3585a | [] | | dfc47032-e1bd-4283-b156-faf9d19591d2 | secgroup01 | secgroup01 | 1c2f5dc8c4f9494fbaaa4217c8e3585a | [] | +--------------------------------------+------------+------------------------+----------------------------------+------+ # インスタンス接続用の SSH キーペア作成 debian@dlp ~(keystone)$ ssh-keygen -q -N "" Enter file in which to save the key (/home/debian/.ssh/id_rsa): # 公開鍵登録 debian@dlp ~(keystone)$ openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey +-------------+-------------------------------------------------+ | Field | Value | +-------------+-------------------------------------------------+ | created_at | None | | fingerprint | 0a:f8:20:15:58:6c:03:4b:6e:69:f0:9e:36:2a:9d:36 | | id | mykey | | is_deleted | None | | name | mykey | | type | ssh | | user_id | de51d5f0ee2c485885877d21f5b424e0 | +-------------+-------------------------------------------------+debian@dlp ~(keystone)$ openstack keypair list +-------+-------------------------------------------------+------+ | Name | Fingerprint | Type | +-------+-------------------------------------------------+------+ | mykey | 0a:f8:20:15:58:6c:03:4b:6e:69:f0:9e:36:2a:9d:36 | ssh | +-------+-------------------------------------------------+------+
debian@dlp ~(keystone)$
netID=$(openstack network list | grep sharednet1 | awk '{ print $2 }') # インスタンス作成/起動 debian@dlp ~(keystone)$ openstack server create --flavor m1.medium --image Debian12 --security-group secgroup01 --nic net-id=$netID --key-name mykey Debian-12
+-----------------------------+-------------------------------------------------+ | 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 | 46jELXmPLZ3F | | config_drive | | | created | 2023-06-27T06:13:57Z | | flavor | m1.medium (2) | | hostId | | | id | 66f3eed0-9b19-4260-88ce-fb640ca55256 | | image | Debian12 (9e7f953f-9918-453d-aeeb-def892492966) | | key_name | mykey | | name | Debian-12 | | progress | 0 | | project_id | 1c2f5dc8c4f9494fbaaa4217c8e3585a | | properties | | | security_groups | name='dfc47032-e1bd-4283-b156-faf9d19591d2' | | status | BUILD | | updated | 2023-06-27T06:13:57Z | | user_id | de51d5f0ee2c485885877d21f5b424e0 | | volumes_attached | | +-----------------------------+-------------------------------------------------+ # 動作確認 (起動直後しばらくは [BUILD] ステータスとなっている) debian@dlp ~(keystone)$ openstack server list +--------------------------------------+-----------+--------+----------+----------+-----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-----------+--------+----------+----------+-----------+ | 66f3eed0-9b19-4260-88ce-fb640ca55256 | Debian-12 | BUILD | | Debian12 | m1.medium | +--------------------------------------+-----------+--------+----------+----------+-----------+ # 正常に起動すると [ACTIVE] ステータスとなる debian@dlp ~(keystone)$ openstack server list +--------------------------------------+-----------+--------+-----------------------+----------+-----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-----------+--------+-----------------------+----------+-----------+ | 66f3eed0-9b19-4260-88ce-fb640ca55256 | Debian-12 | ACTIVE | sharednet1=10.0.0.252 | Debian12 | m1.medium | +--------------------------------------+-----------+--------+-----------------------+----------+-----------+ |
[2] | 起動した仮想マシンインスタンスに SSH 接続できるように、先に作成したセキュリティグループにポート許可の設定を追加します。 |
# ICMP 許可 debian@dlp ~(keystone)$ openstack security group rule create --protocol icmp --ingress secgroup01 +-------------------------+--------------------------------------+ | Field | Value | +-------------------------+--------------------------------------+ | created_at | 2023-06-27T02:49:49Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 71d9a4fb-43f3-49c3-824c-640bd104f8b9 | | name | None | | port_range_max | None | | port_range_min | None | | project_id | 1c2f5dc8c4f9494fbaaa4217c8e3585a | | 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 | dfc47032-e1bd-4283-b156-faf9d19591d2 | | tags | [] | | updated_at | 2023-06-27T02:49:49Z | +-------------------------+--------------------------------------+ # SSH 許可 debian@dlp ~(keystone)$ openstack security group rule create --protocol tcp --dst-port 22:22 secgroup01 +-------------------------+--------------------------------------+ | Field | Value | +-------------------------+--------------------------------------+ | created_at | 2023-06-27T02:50:09Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 35284802-7475-4a38-bf2f-ff75c16b5f60 | | name | None | | port_range_max | 22 | | port_range_min | 22 | | project_id | 1c2f5dc8c4f9494fbaaa4217c8e3585a | | 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 | dfc47032-e1bd-4283-b156-faf9d19591d2 | | tags | [] | | updated_at | 2023-06-27T02:50:09Z | +-------------------------+--------------------------------------+debian@dlp ~(keystone)$ openstack security group rule list secgroup01 +--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+ | ID | IP Protocol | Ethertype | IP Range | Port Range | Direction | Remote Security Group | Remote Address Group | +--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+ | 0e6d64ec-54b0-4ffc-89b5-579a62c0e848 | None | IPv4 | 0.0.0.0/0 | | egress | None | None | | 35284802-7475-4a38-bf2f-ff75c16b5f60 | tcp | IPv4 | 0.0.0.0/0 | 22:22 | ingress | None | None | | 71d9a4fb-43f3-49c3-824c-640bd104f8b9 | icmp | IPv4 | 0.0.0.0/0 | | ingress | None | None | | b8efed4d-e612-4151-ad2b-1fc33cfb17b4 | None | IPv6 | ::/0 | | egress | None | None | +--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+ |
[3] | 起動した仮想マシンインスタンスに SSH ログインします。 |
debian@dlp ~(keystone)$ openstack server list +--------------------------------------+-----------+--------+-----------------------+----------+-----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-----------+--------+-----------------------+----------+-----------+ | 66f3eed0-9b19-4260-88ce-fb640ca55256 | Debian-12 | ACTIVE | sharednet1=10.0.0.252 | Debian12 | m1.medium | +--------------------------------------+-----------+--------+-----------------------+----------+-----------+ # ping 応答が返ってくれば OK debian@dlp ~(keystone)$ ping 10.0.0.252 -c3 PING 10.0.0.252 (10.0.0.252) 56(84) bytes of data. 64 bytes from 10.0.0.252: icmp_seq=1 ttl=64 time=0.670 ms 64 bytes from 10.0.0.252: icmp_seq=2 ttl=64 time=0.494 ms 64 bytes from 10.0.0.252: icmp_seq=3 ttl=64 time=0.421 ms --- 10.0.0.252 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms rtt min/avg/max/mdev = 0.421/0.528/0.670/0.104 ms # SSH でログイン debian@dlp ~(keystone)$ ssh debian@10.0.0.252
The authenticity of host '10.0.0.252 (10.0.0.252)' can't be established. ED25519 key fingerprint is SHA256:2XW5Ha2H1FT9/+py7+4ZPGL3MFOYEZaruk+iPK908+M. 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.252' (ED25519) to the list of known hosts. Linux debian-12 6.1.0-9-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.27-1 (2023-05-08) x86_64 The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. debian@debian-12:~$ # ログインできた |
[4] | 一旦作成して起動した仮想マシンインスタンスを停止/起動する場合は、以下のように [start/stop] コマンドで制御できます。 |
debian@dlp ~(keystone)$ openstack server list +--------------------------------------+-----------+--------+-----------------------+----------+-----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-----------+--------+-----------------------+----------+-----------+ | 66f3eed0-9b19-4260-88ce-fb640ca55256 | Debian-12 | ACTIVE | sharednet1=10.0.0.252 | Debian12 | m1.medium | +--------------------------------------+-----------+--------+-----------------------+----------+-----------+ # インスタンス停止 debian@dlp ~(keystone)$ openstack server stop debian-2004 debian@dlp ~(keystone)$ openstack server list +--------------------------------------+-----------+---------+-----------------------+----------+-----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-----------+---------+-----------------------+----------+-----------+ | 66f3eed0-9b19-4260-88ce-fb640ca55256 | Debian-12 | SHUTOFF | sharednet1=10.0.0.252 | Debian12 | m1.medium | +--------------------------------------+-----------+---------+-----------------------+----------+-----------+ # インスタンスを起動する debian@dlp ~(keystone)$ openstack server start debian-2004 debian@dlp ~(keystone)$ openstack server list +--------------------------------------+-----------+--------+-----------------------+----------+-----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-----------+--------+-----------------------+----------+-----------+ | 66f3eed0-9b19-4260-88ce-fb640ca55256 | Debian-12 | ACTIVE | sharednet1=10.0.0.252 | Debian12 | m1.medium | +--------------------------------------+-----------+--------+-----------------------+----------+-----------+ |
[5] | VNC コンソールを取得して Web ブラウザーでのアクセスも可能です。 |
debian@dlp ~(keystone)$ openstack server list +--------------------------------------+-----------+--------+-----------------------+----------+-----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-----------+--------+-----------------------+----------+-----------+ | 66f3eed0-9b19-4260-88ce-fb640ca55256 | Debian-12 | ACTIVE | sharednet1=10.0.0.252 | Debian12 | m1.medium | +--------------------------------------+-----------+--------+-----------------------+----------+-----------+debian@dlp ~(keystone)$ openstack console url show Debian-12 +----------+-----------------------------------------------------------------------------------------------+ | Field | Value | +----------+-----------------------------------------------------------------------------------------------+ | protocol | vnc | | type | novnc | | url | https://dlp.srv.world:6080/vnc_auto.html?path=%3Ftoken%3D7a111e85-d19f-4b2c-bf9c-e908f7ae5111 | +----------+-----------------------------------------------------------------------------------------------+ |
[6] | 上記コマンドで表示された URL に Web アクセスすると、インスタンスに接続され、操作が可能となります。 |
Sponsored Link |
|