OpenStack Ussuri : インスタンスを起動する2020/06/05 |
仮想マシンインスタンスを起動します。
|
|
[1] | Openstack を利用したい任意のユーザーでログインし、Openstack 認証用の設定ファイルを作成して、仮想マシンインスタンスを作成/起動します。 認証ファイル中のプロジェクト名やユーザー名/パスワードは Keystone に登録したものを指定します。 |
[cent@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)]\$ '
[cent@dlp ~]$
chmod 600 ~/keystonerc [cent@dlp ~]$ source ~/keystonerc [cent@dlp ~(keystone)]$ echo "source ~/keystonerc " >> ~/.bash_profile
# 利用可能な [flavor] 確認 [cent@dlp ~(keystone)]$ openstack flavor list +----+----------+------+------+-----------+-------+-----------+ | ID | Name | RAM | Disk | Ephemeral | VCPUs | Is Public | +----+----------+------+------+-----------+-------+-----------+ | 0 | m1.small | 2048 | 10 | 0 | 1 | True | +----+----------+------+------+-----------+-------+-----------+ # 利用可能なイメージ確認 [cent@dlp ~(keystone)]$ openstack image list +--------------------------------------+---------+--------+ | ID | Name | Status | +--------------------------------------+---------+--------+ | 9e7034a0-c825-4990-8834-4a01ee920cf5 | CentOS8 | active | +--------------------------------------+---------+--------+ # 利用可能なネットワーク確認 [cent@dlp ~(keystone)]$ openstack network list +--------------------------------------+------------+--------------------------------------+ | ID | Name | Subnets | +--------------------------------------+------------+--------------------------------------+ | fbb016c6-aabc-47d9-bc06-045b7d6d14bf | sharednet1 | 23b96535-fe37-4b92-aeed-8bb54fe18792 | +--------------------------------------+------------+--------------------------------------+ # インスタンス用のセキュリティグループを作成 [cent@dlp ~(keystone)]$ openstack security group create secgroup01 +-----------------+---------------------------------------------------------------------------------+ | Field | Value | +-----------------+---------------------------------------------------------------------------------+ | created_at | 2020-06-05T02:35:52Z | | description | secgroup01 | | id | 635d78f2-80b9-4f37-8e69-8100d3fcb0ed | | location | cloud='', project.domain_id=, project.domain_name='default', project.id='d9c... | | name | secgroup01 | | project_id | d9c8c215499949cfb249b28bdaba848a | | revision_number | 1 | | rules | created_at='2020-06-05T02:35:52Z', direction='egress', ethertype='IPv4', id=... | | | created_at='2020-06-05T02:35:52Z', direction='egress', ethertype='IPv6', id=... | | stateful | True | | tags | [] | | updated_at | 2020-06-05T02:35:52Z | +-----------------+---------------------------------------------------------------------------------+[cent@dlp ~(keystone)]$ openstack security group list +--------------------------------------+------------+------------------------+----------------------------------+------+ | ID | Name | Description | Project | Tags | +--------------------------------------+------------+------------------------+----------------------------------+------+ | 635d78f2-80b9-4f37-8e69-8100d3fcb0ed | secgroup01 | secgroup01 | d9c8c215499949cfb249b28bdaba848a | [] | | 7f6ca7c0-eb9c-40c6-9c0b-9182572257ce | default | Default security group | d9c8c215499949cfb249b28bdaba848a | [] | +--------------------------------------+------------+------------------------+----------------------------------+------+ # インスタンス接続用の SSH キーペア作成 [cent@dlp ~(keystone)]$ ssh-keygen -q -N "" Enter file in which to save the key (/home/cent/.ssh/id_rsa): # 公開鍵登録 [cent@dlp ~(keystone)]$ openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey +-------------+-------------------------------------------------+ | Field | Value | +-------------+-------------------------------------------------+ | fingerprint | 4a:08:86:84:05:b1:74:73:21:ba:24:d3:4e:82:7c:ff | | name | mykey | | user_id | 0e4117de456a4bbaa5aac2cc6507be91 | +-------------+-------------------------------------------------+[cent@dlp ~(keystone)]$ openstack keypair list +-------+-------------------------------------------------+ | Name | Fingerprint | +-------+-------------------------------------------------+ | mykey | 4a:08:86:84:05:b1:74:73:21:ba:24:d3:4e:82:7c:ff | +-------+-------------------------------------------------+
[cent@dlp ~(keystone)]$
netID=$(openstack network list | grep sharednet1 | awk '{ print $2 }') # インスタンス作成/起動 [cent@dlp ~(keystone)]$ openstack server create --flavor m1.small --image CentOS8 --security-group secgroup01 --nic net-id=$netID --key-name mykey CentOS_8
+-----------------------------+------------------------------------------------+ | 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 | NM84nigLGotv | | config_drive | | | created | 2020-06-05T02:53:36Z | | flavor | m1.small (0) | | hostId | | | id | e35c9e4f-1c1e-4a0c-80ce-21b74673dc58 | | image | CentOS8 (9e7034a0-c825-4990-8834-4a01ee920cf5) | | key_name | mykey | | name | CentOS_8 | | progress | 0 | | project_id | d9c8c215499949cfb249b28bdaba848a | | properties | | | security_groups | name='635d78f2-80b9-4f37-8e69-8100d3fcb0ed' | | status | BUILD | | updated | 2020-06-05T02:53:36Z | | user_id | 0e4117de456a4bbaa5aac2cc6507be91 | | volumes_attached | | +-----------------------------+------------------------------------------------+ # 動作確認 (起動直後しばらくは [BUILD] ステータスとなっている) [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+----------+--------+----------+---------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+----------+--------+----------+---------+----------+ | e35c9e4f-1c1e-4a0c-80ce-21b74673dc58 | CentOS_8 | BUILD | | CentOS8 | m1.small | +--------------------------------------+----------+--------+----------+---------+----------+ # 正常に起動すると [ACTIVE] ステータスとなる [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+----------+--------+-----------------------+---------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+----------+--------+-----------------------+---------+----------+ | e35c9e4f-1c1e-4a0c-80ce-21b74673dc58 | CentOS_8 | ACTIVE | sharednet1=10.0.0.210 | CentOS8 | m1.small | +--------------------------------------+----------+--------+-----------------------+---------+----------+ |
[2] | 起動した仮想マシンインスタンスに SSH 接続できるように、先に作成したセキュリティグループにポート許可の設定を追加します。 |
# ICMP 許可 [cent@dlp ~(keystone)]$ openstack security group rule create --protocol icmp --ingress secgroup01 +-------------------+-------------------------------------------------------------------------------+ | Field | Value | +-------------------+-------------------------------------------------------------------------------+ | created_at | 2020-06-05T02:55:09Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 6af3f4e0-cb5b-49aa-90ab-4aa1ca482f9a | | location | cloud='', project.domain_id=, project.domain_name='default', project.id='d... | | name | None | | port_range_max | None | | port_range_min | None | | project_id | d9c8c215499949cfb249b28bdaba848a | | protocol | icmp | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 0 | | security_group_id | 635d78f2-80b9-4f37-8e69-8100d3fcb0ed | | tags | [] | | updated_at | 2020-06-05T02:55:09Z | +-------------------+-------------------------------------------------------------------------------+ # SSH 許可 [cent@dlp ~(keystone)]$ openstack security group rule create --protocol tcp --dst-port 22:22 secgroup01 +-------------------+-------------------------------------------------------------------------------+ | Field | Value | +-------------------+-------------------------------------------------------------------------------+ | created_at | 2020-06-05T02:55:50Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 47aef992-8f32-47bd-91c0-2e61f06dd6cc | | location | cloud='', project.domain_id=, project.domain_name='default', project.id='d... | | name | None | | port_range_max | 22 | | port_range_min | 22 | | project_id | d9c8c215499949cfb249b28bdaba848a | | protocol | tcp | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 0 | | security_group_id | 635d78f2-80b9-4f37-8e69-8100d3fcb0ed | | tags | [] | | updated_at | 2020-06-05T02:55:50Z | +-------------------+-------------------------------------------------------------------------------+[cent@dlp ~(keystone)]$ openstack security group rule list +--------------------------------------+-------------+-----------+-----------+------------+---------+ | ID | IP Protocol | Ethertype | IP Range | Port Range | Remote | +--------------------------------------+-------------+-----------+-----------+------------+---------+ | 087eef8d-fca4-4875-9a62-4536fbc7a842 | None | IPv4 | 0.0.0.0/0 | | 7f6c... | | 2190dcb6-9918-4f5c-ac59-5fe601b0a7f5 | None | IPv6 | ::/0 | | 7f6c... | | 47aef992-8f32-47bd-91c0-2e61f06dd6cc | tcp | IPv4 | 0.0.0.0/0 | 22:22 | None | | 50a19ffc-cdbe-4547-a74c-e8c492fb642c | None | IPv4 | 0.0.0.0/0 | | None | | 68dacc85-dd4c-44ad-aa54-96c3b22d832c | None | IPv6 | ::/0 | | None | | 6af3f4e0-cb5b-49aa-90ab-4aa1ca482f9a | icmp | IPv4 | 0.0.0.0/0 | | None | | 8901f46d-f77c-4125-9578-ef02aaa613a8 | None | IPv4 | 0.0.0.0/0 | | None | | d0049fba-2691-42d7-a62c-1dc6662e0c15 | None | IPv6 | ::/0 | | None | +--------------------------------------+-------------+-----------+-----------+------------+---------+ |
[3] | 起動した仮想マシンインスタンスに SSH ログインします。 |
[cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+----------+--------+-----------------------+---------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+----------+--------+-----------------------+---------+----------+ | e35c9e4f-1c1e-4a0c-80ce-21b74673dc58 | CentOS_8 | ACTIVE | sharednet1=10.0.0.210 | CentOS8 | m1.small | +--------------------------------------+----------+--------+-----------------------+---------+----------+ # ping 応答が返ってくれば OK [cent@dlp ~(keystone)]$ ping 10.0.0.210 -c3 PING 10.0.0.210 (10.0.0.210) 56(84) bytes of data. 64 bytes from 10.0.0.210: icmp_seq=1 ttl=64 time=2.00 ms 64 bytes from 10.0.0.210: icmp_seq=2 ttl=64 time=0.999 ms 64 bytes from 10.0.0.210: icmp_seq=3 ttl=64 time=0.730 ms --- 10.0.0.210 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 4ms rtt min/avg/max/mdev = 0.730/1.243/2.001/0.547 ms # SSH でログイン [cent@dlp ~(keystone)]$ ssh centos@10.0.0.210
PING 10.0.0.210 (10.0.0.210) 56(84) bytes of data. 64 bytes from 10.0.0.210: icmp_seq=1 ttl=64 time=2.00 ms 64 bytes from 10.0.0.210: icmp_seq=2 ttl=64 time=0.999 ms 64 bytes from 10.0.0.210: icmp_seq=3 ttl=64 time=0.730 ms --- 10.0.0.210 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 4ms rtt min/avg/max/mdev = 0.730/1.243/2.001/0.547 ms [cent@dlp ~(keystone)]$ ssh centos@10.0.0.210 The authenticity of host '10.0.0.210 (10.0.0.210)' can't be established. ECDSA key fingerprint is SHA256:hD1ZD9t33s/u9T8QCNh0/mLP7PVSFsgdL62Z2PTFpq0. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '10.0.0.210' (ECDSA) to the list of known hosts. [centos@centos-8 ~]$ # ログインできた |
[4] | 一旦作成して起動した仮想マシンインスタンスを停止/起動する場合は、以下のように [start/stop] コマンドで制御できます。 |
[cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+----------+--------+-----------------------+---------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+----------+--------+-----------------------+---------+----------+ | e35c9e4f-1c1e-4a0c-80ce-21b74673dc58 | CentOS_8 | ACTIVE | sharednet1=10.0.0.210 | CentOS8 | m1.small | +--------------------------------------+----------+--------+-----------------------+---------+----------+ # インスタンス停止 [cent@dlp ~(keystone)]$ openstack server stop CentOS_8 [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+----------+---------+-----------------------+---------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+----------+---------+-----------------------+---------+----------+ | e35c9e4f-1c1e-4a0c-80ce-21b74673dc58 | CentOS_8 | SHUTOFF | sharednet1=10.0.0.210 | CentOS8 | m1.small | +--------------------------------------+----------+---------+-----------------------+---------+----------+ # インスタンスを起動する [cent@dlp ~(keystone)]$ openstack server start CentOS_8 [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+----------+--------+-----------------------+---------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+----------+--------+-----------------------+---------+----------+ | e35c9e4f-1c1e-4a0c-80ce-21b74673dc58 | CentOS_8 | ACTIVE | sharednet1=10.0.0.210 | CentOS8 | m1.small | +--------------------------------------+----------+--------+-----------------------+---------+----------+ |
[5] | VNC コンソールを取得して Web ブラウザでのアクセスも可能です。 |
[cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+----------+--------+-----------------------+---------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+----------+--------+-----------------------+---------+----------+ | e35c9e4f-1c1e-4a0c-80ce-21b74673dc58 | CentOS_8 | ACTIVE | sharednet1=10.0.0.210 | CentOS8 | m1.small | +--------------------------------------+----------+--------+-----------------------+---------+----------+[cent@dlp ~(keystone)]$ openstack console url show CentOS_8 +-------+------------------------------------------------------------------------------------------+ | Field | Value | +-------+------------------------------------------------------------------------------------------+ | type | novnc | | url | http://10.0.0.30:6080/vnc_auto.html?path=%3Ftoken%3D80ba2960-b83c-4cb7-923a-514e37da85e7 | +-------+------------------------------------------------------------------------------------------+ |
[6] | 上記コマンドで表示された URL に Web アクセスすると、インスタンスに接続され、操作が可能となります。 |
Sponsored Link |
|