OpenStack Victoria : インスタンスを起動する2021/08/31 |
仮想マシンインスタンスを起動します。
|
|
[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=http://10.0.0.30: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 " >> ~/.bashrc
# 利用可能な [flavor] 確認 debian@dlp ~(keystone)$ openstack flavor list +----+----------+------+------+-----------+-------+-----------+ | ID | Name | RAM | Disk | Ephemeral | VCPUs | Is Public | +----+----------+------+------+-----------+-------+-----------+ | 0 | m1.small | 2048 | 10 | 0 | 1 | True | +----+----------+------+------+-----------+-------+-----------+ # 利用可能なイメージ確認 debian@dlp ~(keystone)$ openstack image list +--------------------------------------+----------+--------+ | ID | Name | Status | +--------------------------------------+----------+--------+ | 773971b3-b4be-4b07-aa06-fe8ca76b395d | Debian11 | active | +--------------------------------------+----------+--------+ # 利用可能なネットワーク確認 debian@dlp ~(keystone)$ openstack network list +--------------------------------------+------------+--------------------------------------+ | ID | Name | Subnets | +--------------------------------------+------------+--------------------------------------+ | 487dfa9b-0503-4b4f-be43-83b10853035b | sharednet1 | 823a48aa-5525-421e-b75b-1a1e72fb44c6 | +--------------------------------------+------------+--------------------------------------+ # インスタンス用のセキュリティグループを作成 debian@dlp ~(keystone)$ openstack security group create secgroup01 +-----------------+---------------------------------------------------------------------------+ | Field | Value | +-----------------+---------------------------------------------------------------------------+ | created_at | 2021-08-31T02:50:00Z | | description | secgroup01 | | id | 61304964-7245-48dd-ad73-25ed70d5bb8b | | name | secgroup01 | | project_id | b6ee2add98874535be40eb037884339d | | revision_number | 1 | | rules | created_at='2021-08-31T02:50:00Z', direction='egress', ethertype='I..... | | | created_at='2021-08-31T02:50:00Z', direction='egress', ethertype='I..... | | stateful | True | | tags | [] | | updated_at | 2021-08-31T02:50:00Z | +-----------------+---------------------------------------------------------------------------+debian@dlp ~(keystone)$ openstack security group list +--------------------------------------+------------+------------------------+----------------------------------+------+ | ID | Name | Description | Project | Tags | +--------------------------------------+------------+------------------------+----------------------------------+------+ | 61304964-7245-48dd-ad73-25ed70d5bb8b | secgroup01 | secgroup01 | b6ee2add98874535be40eb037884339d | [] | | 6b10e301-4dbc-4b3a-a443-e5d3330a1033 | default | Default security group | b6ee2add98874535be40eb037884339d | [] | +--------------------------------------+------------+------------------------+----------------------------------+------+ # インスタンス接続用の 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 | +-------------+-------------------------------------------------+ | fingerprint | 1a:66:c0:0d:88:2b:d2:58:49:e8:0e:77:3a:f7:8a:25 | | name | mykey | | user_id | 2a7dd329f1434536b12eb0784a9b3b98 | +-------------+-------------------------------------------------+debian@dlp ~(keystone)$ openstack keypair list +-------+-------------------------------------------------+ | Name | Fingerprint | +-------+-------------------------------------------------+ | mykey | 1a:66:c0:0d:88:2b:d2:58:49:e8:0e:77:3a:f7:8a:25 | +-------+-------------------------------------------------+
debian@dlp ~(keystone)$
netID=$(openstack network list | grep sharednet1 | awk '{ print $2 }') # インスタンス作成/起動 debian@dlp ~(keystone)$ openstack server create --flavor m1.small --image Debian11 --security-group secgroup01 --nic net-id=$netID --key-name mykey Debian-11
+-----------------------------+-------------------------------------------------+ | 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 | B6v5ChSF4qGk | | config_drive | | | created | 2021-08-31T02:52:33Z | | flavor | m1.small (0) | | hostId | | | id | 49b8a773-3df6-42c7-8c91-9a1b8146f50e | | image | Debian11 (773971b3-b4be-4b07-aa06-fe8ca76b395d) | | key_name | mykey | | name | Debian-11 | | progress | 0 | | project_id | b6ee2add98874535be40eb037884339d | | properties | | | security_groups | name='61304964-7245-48dd-ad73-25ed70d5bb8b' | | status | BUILD | | updated | 2021-08-31T02:52:33Z | | user_id | 2a7dd329f1434536b12eb0784a9b3b98 | | volumes_attached | | +-----------------------------+-------------------------------------------------+ # 動作確認 (起動直後しばらくは [BUILD] ステータスとなっている) debian@dlp ~(keystone)$ openstack server list +--------------------------------------+-----------+--------+----------+----------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-----------+--------+----------+----------+----------+ | 49b8a773-3df6-42c7-8c91-9a1b8146f50e | Debian-11 | BUILD | | Debian11 | m1.small | +--------------------------------------+-----------+--------+----------+----------+----------+ # 正常に起動すると [ACTIVE] ステータスとなる debian@dlp ~(keystone)$ openstack server list +--------------------------------------+-----------+--------+-----------------------+----------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-----------+--------+-----------------------+----------+----------+ | 49b8a773-3df6-42c7-8c91-9a1b8146f50e | Debian-11 | ACTIVE | sharednet1=10.0.0.205 | Debian11 | m1.small | +--------------------------------------+-----------+--------+-----------------------+----------+----------+ |
[2] | 起動した仮想マシンインスタンスに SSH 接続できるように、先に作成したセキュリティグループにポート許可の設定を追加します。 |
# ICMP 許可 debian@dlp ~(keystone)$ openstack security group rule create --protocol icmp --ingress secgroup01 +-------------------+--------------------------------------+ | Field | Value | +-------------------+--------------------------------------+ | created_at | 2021-08-31T02:57:46Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 2fba0220-0563-4584-9765-c624658198ef | | name | None | | port_range_max | None | | port_range_min | None | | project_id | b6ee2add98874535be40eb037884339d | | protocol | icmp | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 0 | | security_group_id | 61304964-7245-48dd-ad73-25ed70d5bb8b | | tags | [] | | updated_at | 2021-08-31T02:57:46Z | +-------------------+--------------------------------------+ # SSH 許可 debian@dlp ~(keystone)$ openstack security group rule create --protocol tcp --dst-port 22:22 secgroup01 +-------------------+--------------------------------------+ | Field | Value | +-------------------+--------------------------------------+ | created_at | 2021-08-31T02:58:01Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 1ee565f0-81da-4002-838f-60258578f712 | | name | None | | port_range_max | 22 | | port_range_min | 22 | | project_id | b6ee2add98874535be40eb037884339d | | protocol | tcp | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 0 | | security_group_id | 61304964-7245-48dd-ad73-25ed70d5bb8b | | tags | [] | | updated_at | 2021-08-31T02:58:01Z | +-------------------+--------------------------------------+debian@dlp ~(keystone)$ openstack security group rule list secgroup01 +--------------------------------------+-------------+-----------+-----------+------------+-----------------------+ | ID | IP Protocol | Ethertype | IP Range | Port Range | Remote Security Group | +--------------------------------------+-------------+-----------+-----------+------------+-----------------------+ | 1ee565f0-81da-4002-838f-60258578f712 | tcp | IPv4 | 0.0.0.0/0 | 22:22 | None | | 2fba0220-0563-4584-9765-c624658198ef | icmp | IPv4 | 0.0.0.0/0 | | None | | 325533f3-67a0-469e-aeac-8189bac78f7f | None | IPv6 | ::/0 | | None | | 545b4d84-b0c1-45d0-907c-a9bc4483558d | None | IPv4 | 0.0.0.0/0 | | None | +--------------------------------------+-------------+-----------+-----------+------------+-----------------------+ |
[3] | 起動した仮想マシンインスタンスに SSH ログインします。 |
debian@dlp ~(keystone)$ openstack server list +--------------------------------------+-----------+--------+-----------------------+----------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-----------+--------+-----------------------+----------+----------+ | 49b8a773-3df6-42c7-8c91-9a1b8146f50e | Debian-11 | ACTIVE | sharednet1=10.0.0.205 | Debian11 | m1.small | +--------------------------------------+-----------+--------+-----------------------+----------+----------+ # ping 応答が返ってくれば OK debian@dlp ~(keystone)$ ping 10.0.0.205 -c3 PING 10.0.0.205 (10.0.0.205) 56(84) bytes of data. 64 bytes from 10.0.0.205: icmp_seq=1 ttl=64 time=0.717 ms 64 bytes from 10.0.0.205: icmp_seq=2 ttl=64 time=0.666 ms 64 bytes from 10.0.0.205: icmp_seq=3 ttl=64 time=0.714 ms --- 10.0.0.205 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2003ms rtt min/avg/max/mdev = 0.666/0.699/0.717/0.023 ms # SSH でログイン debian@dlp ~(keystone)$ ssh debian@10.0.0.205
The authenticity of host '10.0.0.205 (10.0.0.205)' can't be established. ECDSA key fingerprint is SHA256:GvYC5JdZpM4+dYGVJ7EDetYHq9VkuR83F8eeaxaM0ZI. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '10.0.0.205' (ECDSA) to the list of known hosts. Linux debian-11 5.10.0-8-amd64 #1 SMP Debian 5.10.46-4 (2021-08-03) 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-11:~$ # ログインできた |
[4] | 一旦作成して起動した仮想マシンインスタンスを停止/起動する場合は、以下のように [start/stop] コマンドで制御できます。 |
debian@dlp ~(keystone)$ openstack server list +--------------------------------------+-----------+--------+-----------------------+----------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-----------+--------+-----------------------+----------+----------+ | 49b8a773-3df6-42c7-8c91-9a1b8146f50e | Debian-11 | ACTIVE | sharednet1=10.0.0.205 | Debian11 | m1.small | +--------------------------------------+-----------+--------+-----------------------+----------+----------+ # インスタンス停止 debian@dlp ~(keystone)$ openstack server stop Debian-11 debian@dlp ~(keystone)$ openstack server list +--------------------------------------+-----------+---------+-----------------------+----------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-----------+---------+-----------------------+----------+----------+ | 49b8a773-3df6-42c7-8c91-9a1b8146f50e | Debian-11 | SHUTOFF | sharednet1=10.0.0.205 | Debian11 | m1.small | +--------------------------------------+-----------+---------+-----------------------+----------+----------+ # インスタンスを起動する debian@dlp ~(keystone)$ openstack server start Debian-11 debian@dlp ~(keystone)$ openstack server list +--------------------------------------+-----------+--------+-----------------------+----------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-----------+--------+-----------------------+----------+----------+ | 49b8a773-3df6-42c7-8c91-9a1b8146f50e | Debian-11 | ACTIVE | sharednet1=10.0.0.205 | Debian11 | m1.small | +--------------------------------------+-----------+--------+-----------------------+----------+----------+ |
[5] | VNC コンソールを取得して Web ブラウザでのアクセスも可能です。 |
debian@dlp ~(keystone)$ openstack server list +--------------------------------------+-----------+--------+-----------------------+----------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-----------+--------+-----------------------+----------+----------+ | 49b8a773-3df6-42c7-8c91-9a1b8146f50e | Debian-11 | ACTIVE | sharednet1=10.0.0.205 | Debian11 | m1.small | +--------------------------------------+-----------+--------+-----------------------+----------+----------+debian@dlp ~(keystone)$ openstack console url show Debian-11 +-------+------------------------------------------------------------------------------------------+ | Field | Value | +-------+------------------------------------------------------------------------------------------+ | type | novnc | | url | http://10.0.0.30:6080/vnc_auto.html?path=%3Ftoken%3Dfa899197-4749-4849-a5e6-1ea53cb1d9ed | +-------+------------------------------------------------------------------------------------------+ |
[6] | 上記コマンドで表示された URL に Web アクセスすると、インスタンスに接続され、操作が可能となります。 |
Sponsored Link |