OpenStack Ocata : インスタンスを起動する2017/03/12 |
仮想マシンインスタンスを起動します。
|
|
[1] | 仮想マシンインスタンスに割り当てるメモリ容量やストレージ容量等々の定義 (flavor) を作成し、インスタンスを作成して起動します。 |
# flavor 作成 root@dlp ~(keystone)# openstack flavor create --id 0 --vcpus 1 --ram 2048 --disk 10 m1.small +----------------------------+----------+ | Field | Value | +----------------------------+----------+ | OS-FLV-DISABLED:disabled | False | | OS-FLV-EXT-DATA:ephemeral | 0 | | disk | 10 | | id | 0 | | name | m1.small | | os-flavor-access:is_public | True | | properties | | | ram | 2048 | | rxtx_factor | 1.0 | | swap | | | vcpus | 1 | +----------------------------+----------+root@dlp ~(keystone)# openstack flavor list +----+----------+------+------+-----------+-------+-----------+ | ID | Name | RAM | Disk | Ephemeral | VCPUs | Is Public | +----+----------+------+------+-----------+-------+-----------+ | 0 | m1.small | 2048 | 10 | 0 | 1 | True | +----+----------+------+------+-----------+-------+-----------+ # 利用可能なイメージ root@dlp ~(keystone)# openstack image list +--------------------------------------+------------+--------+ | ID | Name | Status | +--------------------------------------+------------+--------+ | 3e88d891-e286-426b-ad6b-4c97920d16be | Ubuntu1604 | active | +--------------------------------------+------------+--------+ # 利用可能なネットワーク root@dlp ~(keystone)# openstack network list +--------------------------------+------------+--------------------------------+ | ID | Name | Subnets | +--------------------------------+------------+--------------------------------+ | ef38f7e8-439e- | sharednet1 | 749b6df4-6bcd-4d10-a01e- | | 44d0-b4c3-c9eff3c2c819 | | 634348a76cb2 | +--------------------------------+------------+--------------------------------+
root@dlp ~(keystone)#
netID=`openstack network list | grep sharednet1 | awk '{ print $2 }'` # インスタンス作成・起動 root@dlp ~(keystone)# openstack server create --flavor m1.small --image Ubuntu1604 --security-group default --nic net-id=$netID Ubuntu_1604 +-------------------------------------+------------------------------------------------+ | Field | Value | +-------------------------------------+------------------------------------------------+ | OS-DCF:diskConfig | MANUAL | | OS-EXT-AZ:availability_zone | | | OS-EXT-SRV-ATTR:host | None | | OS-EXT-SRV-ATTR:hypervisor_hostname | None | | OS-EXT-SRV-ATTR:instance_name | | | 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 | 4PkvwmeLorP2 | | config_drive | | | created | 2017-02-28T07:47:14Z | | flavor | m1.small (0) | | hostId | | | id | 2903f050-6871-475a-a0b8-714e5952bd93 | | image | Ubuntu1604 (c8f1484e-b877-4447-b6ce-f1baa6be5) | | key_name | None | | name | Ubuntu_1604 | | progress | 0 | | project_id | c654e2e098b14356b97b6e613775cc54 | | properties | | | security_groups | name='default' | | status | BUILD | | updated | 2017-02-28T07:47:15Z | | user_id | cf3c5cbcdd214707b91d322a69af038e | | volumes_attached | | +-------------------------------------+------------------------------------------------+ # 動作確認 (起動直後しばらくは [BUILD] ステータスとなっている) root@dlp ~(keystone)# openstack server list +--------------------+-------------+--------+---------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------+-------------+--------+---------------------+------------+ | 2903f050-6871 | Ubuntu_1604 | BUILD | sharednet1=10.0.0.2 | Ubuntu1604 | | -475a- | | | 04 | | | a0b8-714e5952bd93 | | | | | +--------------------+-------------+--------+---------------------+------------+ # 正常に起動すると [ACTIVE] ステータスとなる root@dlp ~(keystone)# openstack server list +--------------------+-------------+--------+---------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------+-------------+--------+---------------------+------------+ | 2903f050-6871 | Ubuntu_1604 | ACTIVE | sharednet1=10.0.0.2 | Ubuntu1604 | | -475a- | | | 04 | | | a0b8-714e5952bd93 | | | | | +--------------------+-------------+--------+---------------------+------------+ |
[2] | 起動した仮想マシンインスタンスに SSH 接続できるように、デフォルトセキュリティグループにポート許可の設定を追加します。 |
# ICMP 許可 root@dlp ~(keystone)# openstack security group rule create --protocol icmp --ingress default +-------------------+--------------------------------------+ | Field | Value | +-------------------+--------------------------------------+ | created_at | 2017-03-10T06:45:14Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | faf40532-ceea-41ad-a5fb-11b857c022ce | | name | None | | port_range_max | None | | port_range_min | None | | project_id | 763d3fd7411e4b42982d4d7022f1e335 | | protocol | icmp | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 1 | | security_group_id | cb6894d3-846b-4135-8cc6-25842b67c6a6 | | updated_at | 2017-03-10T06:45:14Z | +-------------------+--------------------------------------+ # SSH 許可 root@dlp ~(keystone)# openstack security group rule create --protocol tcp --dst-port 22:22 default +-------------------+--------------------------------------+ | Field | Value | +-------------------+--------------------------------------+ | created_at | 2017-03-10T06:45:31Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 15421d61-0343-40f9-8086-2e53e526248d | | name | None | | port_range_max | 22 | | port_range_min | 22 | | project_id | 763d3fd7411e4b42982d4d7022f1e335 | | protocol | tcp | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 1 | | security_group_id | cb6894d3-846b-4135-8cc6-25842b67c6a6 | | updated_at | 2017-03-10T06:45:31Z | +-------------------+--------------------------------------+root@dlp ~(keystone)# openstack security group rule list +------------+-------------+-----------+------------+-----------------------+----------------+ | ID | IP Protocol | IP Range | Port Range | Remote Security Group | Security Group | +------------+-------------+-----------+------------+-----------------------+----------------+ | 15421d61-0 | tcp | 0.0.0.0/0 | 22:22 | None | cb6894d3-846b- | | 343-40f9-8 | | | | | 4135-8cc6-2584 | | 086-2e53e5 | | | | | 2b67c6a6 | | 26248d | | | | | | | 9928f5fc-8 | None | None | | None | cb6894d3-846b- | | c94-4458-8 | | | | | 4135-8cc6-2584 | | 3a6-9a8678 | | | | | 2b67c6a6 | | 8fb5ee | | | | | | | bce04897-a | None | None | | cb6894d3-846b-4135-8c | cb6894d3-846b- | | 9b2-4b80-8 | | | | c6-25842b67c6a6 | 4135-8cc6-2584 | | 709-6fbcbf | | | | | 2b67c6a6 | | 459ef7 | | | | | | | faf40532 | icmp | 0.0.0.0/0 | | None | cb6894d3-846b- | | -ceea- | | | | | 4135-8cc6-2584 | | 41ad-a5fb- | | | | | 2b67c6a6 | | 11b857c022 | | | | | | | ce | | | | | | | fba7a2cb- | None | None | | cb6894d3-846b-4135-8c | cb6894d3-846b- | | 03fa-4c11 | | | | c6-25842b67c6a6 | 4135-8cc6-2584 | | -aadd-ebab | | | | | 2b67c6a6 | | 85838be9 | | | | | | | fe1ae047 | None | None | | None | cb6894d3-846b- | | -9bdd-43b1 | | | | | 4135-8cc6-2584 | | -b6bd-62fa | | | | | 2b67c6a6 | | 17442d87 | | | | | | +------------+-------------+-----------+------------+-----------------------+----------------+ |
[3] | 起動した仮想マシンインスタンスに SSH ログインします。 |
root@dlp ~(keystone)# openstack server list +--------------------+-------------+--------+---------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------+-------------+--------+---------------------+------------+ | 2903f050-6871 | Ubuntu_1604 | ACTIVE | sharednet1=10.0.0.2 | Ubuntu1604 | | -475a- | | | 04 | | | a0b8-714e5952bd93 | | | | | +--------------------+-------------+--------+---------------------+------------+ # ping 応答が返ってくれば OK root@dlp ~(keystone)# ping 10.0.0.204 PING 10.0.0.204 (10.0.0.204) 56(84) bytes of data. 64 bytes from 10.0.0.204: icmp_seq=1 ttl=64 time=1.21 ms 64 bytes from 10.0.0.204: icmp_seq=2 ttl=64 time=0.760 ms --- 10.0.0.204 ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1001ms rtt min/avg/max/mdev = 0.760/0.986/1.213/0.228 ms # SSH ログイン root@dlp ~(keystone)# ssh ubuntu@10.0.0.204 The authenticity of host '10.0.0.204 (10.0.0.204)' can't be established. ECDSA key fingerprint is SHA256:BnZk5iNzs2VZS+y3ndB48MptWfnMlGRgpk5aohhe5qo. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '10.0.0.204' (ECDSA) to the list of known hosts. ubuntu@10.0.0.204's password: # イメージ作成時に設定したパスワード Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-66-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage Last login: Fri Mar 10 14:40:17 2017ubuntu@ubuntu-1604:~$ # ログインできた |
[4] | インターネットから取得した仮想マシンイメージを利用中でパスワードが不明な場合は、SSH 鍵を登録することでログイン可能です。 自身で作成したイメージの場合は、前もって仮想マシンイメージに「cloud-init」パッケージをインストールし、「cloud-init」サービスを有効にしておくことで、SSH 鍵でのログインが可能となります。ちなみに、cloud-init のデフォルト設定は「ubuntu」が SSH 接続ユーザーとなっています。 |
# キーペア作成 root@dlp ~(keystone)# ssh-keygen -q -N "" Enter file in which to save the key (/root/.ssh/id_rsa): # 公開鍵登録 root@dlp ~(keystone)# openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey +-------------+-------------------------------------------------+ | Field | Value | +-------------+-------------------------------------------------+ | fingerprint | 0c:6e:65:b7:59:f5:8c:1a:54:5a:5c:dc:2e:3f:72:11 | | name | mykey | | user_id | 9f3b26c5924a4bc78025e9a8453b2553 | +-------------+-------------------------------------------------+root@dlp ~(keystone)# openstack keypair list +-------+-------------------------------------------------+ | Name | Fingerprint | +-------+-------------------------------------------------+ | mykey | 0c:6e:65:b7:59:f5:8c:1a:54:5a:5c:dc:2e:3f:72:11 | +-------+-------------------------------------------------+ # キーを指定してインスタンス作成・起動 root@dlp ~(keystone)# openstack server create --flavor m1.small --image Ubuntu1604 --security-group default --nic net-id=$netID --key-name mykey Ubuntu_1604
openstack server list +--------------------+-------------+--------+---------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------+-------------+--------+---------------------+------------+ | 22001099-3c0d-4211 | Ubuntu_1604 | ACTIVE | sharednet1=10.0.0.2 | Ubuntu1604 | | -8b5a-2cc12ccb29d5 | | | 06 | | +--------------------+-------------+--------+---------------------+------------+ # キーを指定してログイン root@dlp ~(keystone)# ssh -i mykey ubuntu@10.0.0.206
Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-66-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage Last login: Fri Mar 10 14:40:17 2017ubuntu@ubuntu-1604:~$ # ログインできた
|
[5] | 一旦作成して起動した仮想マシンインスタンスを停止/起動する場合は、以下のように start/stop コマンドで制御できます。 |
root@dlp ~(keystone)# openstack server list +--------------------+-------------+--------+---------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------+-------------+--------+---------------------+------------+ | 22001099-3c0d-4211 | Ubuntu_1604 | ACTIVE | sharednet1=10.0.0.2 | Ubuntu1604 | | -8b5a-2cc12ccb29d5 | | | 06 | | +--------------------+-------------+--------+---------------------+------------+ # インスタンス停止 root@dlp ~(keystone)# openstack server stop Ubuntu_1604 root@dlp ~(keystone)# openstack server list +--------------------+-------------+---------+--------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------+-------------+---------+--------------------+------------+ | 22001099-3c0d-4211 | Ubuntu_1604 | SHUTOFF | sharednet1=10.0.0. | Ubuntu1604 | | -8b5a-2cc12ccb29d5 | | | 206 | | +--------------------+-------------+---------+--------------------+------------+ # インスタンスを起動する root@dlp ~(keystone)# openstack server start Ubuntu_1604 root@dlp ~(keystone)# openstack server list +--------------------+-------------+--------+---------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------+-------------+--------+---------------------+------------+ | 22001099-3c0d-4211 | Ubuntu_1604 | ACTIVE | sharednet1=10.0.0.2 | Ubuntu1604 | | -8b5a-2cc12ccb29d5 | | | 06 | | +--------------------+-------------+--------+---------------------+------------+ |
[6] | VNC コンソールを取得して Web ブラウザでのアクセスも可能です。 |
root@dlp ~(keystone)# openstack server list +--------------------+-------------+--------+---------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------+-------------+--------+---------------------+------------+ | 22001099-3c0d-4211 | Ubuntu_1604 | ACTIVE | sharednet1=10.0.0.2 | Ubuntu1604 | | -8b5a-2cc12ccb29d5 | | | 06 | | +--------------------+-------------+--------+---------------------+------------+root@dlp ~(keystone)# openstack console url show Ubuntu_1604 +-------+----------------------------------------------------------------------+ | Field | Value | +-------+----------------------------------------------------------------------+ | type | novnc | | url | http://10.0.0.30:6080/vnc_auto.html?token=9fc940fb-a680-4bbe- | | | 92c1-883a50c4fc0e | +-------+----------------------------------------------------------------------+ |
[7] | 上記コマンドで表示された URL にアクセスすると、インスタンスにアクセスして操作可能です。 |
Sponsored Link |
|