OpenStack Rocky : インスタンスを起動する2019/08/19 |
仮想マシンインスタンスを起動します。
|
|
[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 " >> ~/.bash_profile
# 利用可能な 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 | +--------------------------------------+----------+--------+ | 2f489eea-ca80-471d-b450-31664cd284b1 | Debian10 | active | +--------------------------------------+----------+--------+ # 利用可能なネットワーク確認 debian@dlp ~(keystone)$ openstack network list +--------------------------------------+------------+--------------------------------------+ | ID | Name | Subnets | +--------------------------------------+------------+--------------------------------------+ | 5f6060b5-0023-4026-9ffe-57868cf75eac | sharednet1 | 724c38e8-cdef-443a-9b9f-0c8f2f530577 | +--------------------------------------+------------+--------------------------------------+ # インスタンス用のセキュリティグループを作成 debian@dlp ~(keystone)$ openstack security group create secgroup01 +-----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+ | Field | Value | +-----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+ | created_at | 2019-08-19T07:23:49Z | | description | secgroup01 | | id | 7935708a-9c11-45be-9e54-25144d962d9a | | name | secgroup01 | | project_id | 6de0ab5f5ae24824820df0ab890bd84f | | revision_number | 1 | | rules | created_at='2019-08-19T07:23:49Z', direction='egress', ethertype='IPv6', id='b34407fc-eab0-4d1b-9cfd-629bed707950', updated_at='2019-08-19T07:23:49Z' | | | created_at='2019-08-19T07:23:49Z', direction='egress', ethertype='IPv4', id='e3722fbd-71b6-4e07-9a50-81d7d10b9284', updated_at='2019-08-19T07:23:49Z' | | tags | [] | | updated_at | 2019-08-19T07:23:49Z | +-----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+debian@dlp ~(keystone)$ openstack security group list +--------------------------------------+------------+------------------------+----------------------------------+------+ | ID | Name | Description | Project | Tags | +--------------------------------------+------------+------------------------+----------------------------------+------+ | 08081af4-773a-40f7-9fe3-5fe879204fdb | default | Default security group | 6de0ab5f5ae24824820df0ab890bd84f | [] | | 7935708a-9c11-45be-9e54-25144d962d9a | secgroup01 | secgroup01 | 6de0ab5f5ae24824820df0ab890bd84f | [] | +--------------------------------------+------------+------------------------+----------------------------------+------+ # インスタンス接続用の 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 | 50:2d:14:08:67:83:cb:ca:60:1e:c7:32:24:17:1f:c7 | | name | mykey | | user_id | 2af053ff367b47fc9e1a9139c29340b6 | +-------------+-------------------------------------------------+debian@dlp ~(keystone)$ openstack keypair list +-------+-------------------------------------------------+ | Name | Fingerprint | +-------+-------------------------------------------------+ | mykey | 50:2d:14:08:67:83:cb:ca:60:1e:c7:32:24:17:1f:c7 | +-------+-------------------------------------------------+
debian@dlp ~(keystone)$
netID=$(openstack network list | grep sharednet1 | awk '{ print $2 }') # インスタンス作成・起動 debian@dlp ~(keystone)$ openstack server create --flavor m1.small --image Debian10 --security-group secgroup01 --nic net-id=$netID --key-name mykey Debian_10
+-----------------------------+-------------------------------------------------+ | 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 | mv7n8sLCKCkp | | config_drive | | | created | 2019-08-19T07:25:25Z | | flavor | m1.small (0) | | hostId | | | id | 1f07a74a-643f-483c-8f79-007d9d716461 | | image | Debian10 (2f489eea-ca80-471d-b450-31664cd284b1) | | key_name | mykey | | name | Debian_10 | | progress | 0 | | project_id | 6de0ab5f5ae24824820df0ab890bd84f | | properties | | | security_groups | name='7935708a-9c11-45be-9e54-25144d962d9a' | | status | BUILD | | updated | 2019-08-19T07:25:25Z | | user_id | 2af053ff367b47fc9e1a9139c29340b6 | | volumes_attached | | +-----------------------------+-------------------------------------------------+ # 動作確認 (起動直後しばらくは [BUILD] ステータスとなっている) debian@dlp ~(keystone)$ openstack server list +--------------------------------------+-----------+--------+----------+----------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-----------+--------+----------+----------+----------+ | 1f07a74a-643f-483c-8f79-007d9d716461 | Debian_10 | BUILD | | Debian10 | m1.small | +--------------------------------------+-----------+--------+----------+----------+----------+ # 正常に起動すると [ACTIVE] ステータスとなる debian@dlp ~(keystone)$ openstack server list +--------------------------------------+-----------+--------+-----------------------+----------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-----------+--------+-----------------------+----------+----------+ | 1f07a74a-643f-483c-8f79-007d9d716461 | Debian_10 | ACTIVE | sharednet1=10.0.0.213 | Debian10 | m1.small | +--------------------------------------+-----------+--------+-----------------------+----------+----------+ |
[2] | 起動した仮想マシンインスタンスに SSH 接続できるように、先に作成したセキュリティグループにポート許可の設定を追加します。 |
# ICMP 許可 debian@dlp ~(keystone)$ openstack security group rule create --protocol icmp --ingress secgroup01 +-------------------+--------------------------------------+ | Field | Value | +-------------------+--------------------------------------+ | created_at | 2019-08-19T07:26:48Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 40c03b51-b0e9-4af4-845c-22d1f3f8e6a9 | | name | None | | port_range_max | None | | port_range_min | None | | project_id | 6de0ab5f5ae24824820df0ab890bd84f | | protocol | icmp | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 0 | | security_group_id | 7935708a-9c11-45be-9e54-25144d962d9a | | updated_at | 2019-08-19T07:26:48Z | +-------------------+--------------------------------------+ # SSH 許可 debian@dlp ~(keystone)$ openstack security group rule create --protocol tcp --dst-port 22:22 secgroup01 +-------------------+--------------------------------------+ | Field | Value | +-------------------+--------------------------------------+ | created_at | 2019-08-19T07:27:15Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 333fc7f0-13b8-4282-9c6d-0dc32e291e4e | | name | None | | port_range_max | 22 | | port_range_min | 22 | | project_id | 6de0ab5f5ae24824820df0ab890bd84f | | protocol | tcp | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 0 | | security_group_id | 7935708a-9c11-45be-9e54-25144d962d9a | | updated_at | 2019-08-19T07:27:15Z | +-------------------+--------------------------------------+debian@dlp ~(keystone)$ openstack security group rule list +--------------------------------------+-------------+-----------+------------+--------------------------------------+--------------------------------------+ | ID | IP Protocol | IP Range | Port Range | Remote Security Group | Security Group | +--------------------------------------+-------------+-----------+------------+--------------------------------------+--------------------------------------+ | 333fc7f0-13b8-4282-9c6d-0dc32e291e4e | tcp | 0.0.0.0/0 | 22:22 | None | 7935708a-9c11-45be-9e54-25144d962d9a | | 40c03b51-b0e9-4af4-845c-22d1f3f8e6a9 | icmp | 0.0.0.0/0 | | None | 7935708a-9c11-45be-9e54-25144d962d9a | | 7d1ddb63-83c2-47e0-a207-c769f8d36aa9 | None | None | | None | 08081af4-773a-40f7-9fe3-5fe879204fdb | | 7dda3c5c-669d-4880-aa66-bd7611707100 | None | None | | None | 08081af4-773a-40f7-9fe3-5fe879204fdb | | 91cf0dd6-f82a-4c4a-899d-910a2ceb369e | None | None | | 08081af4-773a-40f7-9fe3-5fe879204fdb | 08081af4-773a-40f7-9fe3-5fe879204fdb | | b34407fc-eab0-4d1b-9cfd-629bed707950 | None | None | | None | 7935708a-9c11-45be-9e54-25144d962d9a | | d4d90b90-1566-4ce3-ab0d-0a0151571f83 | None | None | | 08081af4-773a-40f7-9fe3-5fe879204fdb | 08081af4-773a-40f7-9fe3-5fe879204fdb | | e3722fbd-71b6-4e07-9a50-81d7d10b9284 | None | None | | None | 7935708a-9c11-45be-9e54-25144d962d9a | +--------------------------------------+-------------+-----------+------------+--------------------------------------+--------------------------------------+ |
[3] | 起動した仮想マシンインスタンスに SSH ログインします。 |
debian@dlp ~(keystone)$ openstack server list +--------------------------------------+-----------+--------+-----------------------+----------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-----------+--------+-----------------------+----------+----------+ | 1f07a74a-643f-483c-8f79-007d9d716461 | Debian_10 | ACTIVE | sharednet1=10.0.0.213 | Debian10 | m1.small | +--------------------------------------+-----------+--------+-----------------------+----------+----------+ # ping 応答が返ってくれば OK debian@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.02 ms 64 bytes from 10.0.0.213: icmp_seq=2 ttl=64 time=0.692 ms 64 bytes from 10.0.0.213: icmp_seq=3 ttl=64 time=0.851 ms --- 10.0.0.213 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 5ms rtt min/avg/max/mdev = 0.692/0.853/1.018/0.137 ms # SSHでログイン debian@dlp ~(keystone)$ ssh debian@10.0.0.213
The authenticity of host '10.0.0.213 (10.0.0.213)' can't be established.
ECDSA key fingerprint is SHA256:p8Woyk+PDqPXtfd651Wc1TALWydbkdiUnOh8h9b4cd8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.213' (ECDSA) to the list of known hosts.
Linux debian-10 4.19.0-5-amd64 #1 SMP Debian 4.19.37-5+deb10u2 (2019-08-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-10:~$ # ログインできた |
[4] | 一旦作成して起動した仮想マシンインスタンスを停止/起動する場合は、以下のように start/stop コマンドで制御できます。 |
debian@dlp ~(keystone)$ openstack server list +--------------------------------------+-----------+--------+-----------------------+----------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-----------+--------+-----------------------+----------+----------+ | 1f07a74a-643f-483c-8f79-007d9d716461 | Debian_10 | ACTIVE | sharednet1=10.0.0.213 | Debian10 | m1.small | +--------------------------------------+-----------+--------+-----------------------+----------+----------+ # インスタンス停止 debian@dlp ~(keystone)$ openstack server stop debian_1804 debian@dlp ~(keystone)$ openstack server list +--------------------------------------+-----------+---------+-----------------------+----------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-----------+---------+-----------------------+----------+----------+ | 1f07a74a-643f-483c-8f79-007d9d716461 | Debian_10 | SHUTOFF | sharednet1=10.0.0.213 | Debian10 | m1.small | +--------------------------------------+-----------+---------+-----------------------+----------+----------+ # インスタンスを起動する debian@dlp ~(keystone)$ openstack server start debian_1804 debian@dlp ~(keystone)$ openstack server list +--------------------------------------+-----------+--------+-----------------------+----------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-----------+--------+-----------------------+----------+----------+ | 1f07a74a-643f-483c-8f79-007d9d716461 | Debian_10 | ACTIVE | sharednet1=10.0.0.213 | Debian10 | m1.small | +--------------------------------------+-----------+--------+-----------------------+----------+----------+ |
[5] | VNC コンソールを取得して Web ブラウザでのアクセスも可能です。 |
debian@dlp ~(keystone)$ openstack server list +--------------------------------------+-----------+--------+-----------------------+----------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-----------+--------+-----------------------+----------+----------+ | 1f07a74a-643f-483c-8f79-007d9d716461 | Debian_10 | ACTIVE | sharednet1=10.0.0.213 | Debian10 | m1.small | +--------------------------------------+-----------+--------+-----------------------+----------+----------+debian@dlp ~(keystone)$ openstack console url show Debian_10 +-------+--------------------------------------------------------------------------------+ | Field | Value | +-------+--------------------------------------------------------------------------------+ | type | novnc | | url | http://10.0.0.30:6080/vnc_auto.html?token=5e06d1b1-9b3c-4fbc-9571-5aa2e2e11c29 | +-------+--------------------------------------------------------------------------------+ |
[6] | 上記コマンドで表示された URL に Web アクセスすると、インスタンスに接続され、操作が可能となります。 |
Sponsored Link |
|