OpenStack Pike : インスタンスを起動する2017/09/01 |
仮想マシンインスタンスを起動します。
|
|
[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 | +--------------------------------------+------------+--------+ | b8b5a1f9-914e-4adc-b368-82eb7f573bec | Ubuntu1604 | active | +--------------------------------------+------------+--------+ # 利用可能なネットワーク root@dlp ~(keystone)# openstack network list +--------------------------------+------------+--------------------------------+ | ID | Name | Subnets | +--------------------------------+------------+--------------------------------+ | 8da7f4bc-0bd2-4e9f- | sharednet1 | ed6be86e-2fec- | | bf65-c667c587eff4 | | 498d-a250-b7243bd5ab69 | +--------------------------------+------------+--------------------------------+
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 | Ch85WniiXr3h | | config_drive | | | created | 2017-09-01T07:45:34Z | | flavor | m1.small (0) | | hostId | | | id | 852edd8d-f0d3-4366-8c13-da1a9ea45362 | | image | Ubuntu1604 (b8b5a1f9-914e- | | | 4adc-b368-82eb7f573bec) | | key_name | None | | name | Ubuntu_1604 | | progress | 0 | | project_id | 859896d22f074d16bc67fe7eef6f36db | | properties | | | security_groups | name='default' | | status | BUILD | | updated | 2017-09-01T07:45:34Z | | user_id | f73e3c2f9e7f4eb793a010f60d5b4674 | | volumes_attached | | +-------------------------------------+----------------------------------------+ # 動作確認 (起動直後しばらくは [BUILD] ステータスとなっている) root@dlp ~(keystone)# openstack server list +--------------------+-------------+--------+---------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------+-------------+--------+---------------------+------------+ | 852edd8d-f0d3-4366 | Ubuntu_1604 | BUILD | sharednet1=10.0.0.2 | Ubuntu1604 | | -8c13-da1a9ea45362 | | | 10 | | +--------------------+-------------+--------+---------------------+------------+ # 正常に起動すると [ACTIVE] ステータスとなる root@dlp ~(keystone)# openstack server list +--------------------+-------------+--------+---------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------+-------------+--------+---------------------+------------+ | 852edd8d-f0d3-4366 | Ubuntu_1604 | ACTIVE | sharednet1=10.0.0.2 | Ubuntu1604 | | -8c13-da1a9ea45362 | | | 10 | | +--------------------+-------------+--------+---------------------+------------+ |
[2] | 起動した仮想マシンインスタンスに SSH 接続できるように、デフォルトセキュリティグループにポート許可の設定を追加します。 |
# ICMP 許可 root@dlp ~(keystone)# openstack security group rule create --protocol icmp --ingress default +-------------------+--------------------------------------+ | Field | Value | +-------------------+--------------------------------------+ | created_at | 2017-09-01T05:17:52Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 035a5407-7d7c-4630-bc9d-7d8d16cac16c | | name | None | | port_range_max | None | | port_range_min | None | | project_id | 859896d22f074d16bc67fe7eef6f36db | | protocol | icmp | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 1 | | security_group_id | be5df507-29eb-4deb-8b43-3ce576dd070e | | updated_at | 2017-09-01T05:17:52Z | +-------------------+--------------------------------------+ # SSH 許可 root@dlp ~(keystone)# openstack security group rule create --protocol tcp --dst-port 22:22 default +-------------------+--------------------------------------+ | Field | Value | +-------------------+--------------------------------------+ | created_at | 2017-09-01T05:18:07Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 21c1dfa9-8705-4630-bc22-8c977dcb25ad | | name | None | | port_range_max | 22 | | port_range_min | 22 | | project_id | 859896d22f074d16bc67fe7eef6f36db | | protocol | tcp | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 1 | | security_group_id | be5df507-29eb-4deb-8b43-3ce576dd070e | | updated_at | 2017-09-01T05:18:07Z | +-------------------+--------------------------------------+root@dlp ~(keystone)# openstack security group rule list +------------+-------------+-----------+------------+-----------------------+----------------+ | ID | IP Protocol | IP Range | Port Range | Remote Security Group | Security Group | +------------+-------------+-----------+------------+-----------------------+----------------+ | 035a5407-7 | icmp | 0.0.0.0/0 | | None | be5df507-29eb- | | d7c-4630 | | | | | 4deb-8b43-3ce5 | | -bc9d-7d8d | | | | | 76dd070e | | 16cac16c | | | | | | | 21c1dfa9-8 | tcp | 0.0.0.0/0 | 22:22 | None | be5df507-29eb- | | 705-4630-b | | | | | 4deb-8b43-3ce5 | | c22-8c977d | | | | | 76dd070e | | cb25ad | | | | | | | 27fdafb0-f | None | None | | be5df507-29eb-4deb- | be5df507-29eb- | | 4f6-4ddc- | | | | 8b43-3ce576dd070e | 4deb-8b43-3ce5 | | b31c-fdee8 | | | | | 76dd070e | | 94fb48d | | | | | | | 3479a490-0 | None | None | | be5df507-29eb-4deb- | be5df507-29eb- | | 766-4eb5 | | | | 8b43-3ce576dd070e | 4deb-8b43-3ce5 | | -aa7e-34a2 | | | | | 76dd070e | | 33c19aa1 | | | | | | | 5f9ae2d4-1 | None | None | | None | be5df507-29eb- | | 366-46b5-9 | | | | | 4deb-8b43-3ce5 | | c51-2ec356 | | | | | 76dd070e | | 8635ac | | | | | | | d8ba5c56-3 | None | None | | None | be5df507-29eb- | | 647-475a-8 | | | | | 4deb-8b43-3ce5 | | 375-5e202d | | | | | 76dd070e | | 838333 | | | | | | +------------+-------------+-----------+------------+-----------------------+----------------+ |
[3] | 起動した仮想マシンインスタンスに SSH ログインします。 |
root@dlp ~(keystone)# openstack server list +--------------------+-------------+--------+---------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------+-------------+--------+---------------------+------------+ | 852edd8d-f0d3-4366 | Ubuntu_1604 | ACTIVE | sharednet1=10.0.0.2 | Ubuntu1604 | | -8c13-da1a9ea45362 | | | 10 | | +--------------------+-------------+--------+---------------------+------------+ # ping 応答が返ってくれば OK root@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=1.46 ms 64 bytes from 10.0.0.210: icmp_seq=2 ttl=64 time=0.661 ms 64 bytes from 10.0.0.210: icmp_seq=3 ttl=64 time=0.573 ms --- 10.0.0.210 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2003ms rtt min/avg/max/mdev = 0.573/0.899/1.464/0.401 ms # SSH ログイン root@dlp ~(keystone)# ssh ubuntu@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:wFP0dngojZ8YTSEmWlq0dpIs/UfSveGbeS0wYyztqF0. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '10.0.0.210' (ECDSA) to the list of known hosts. ubuntu@10.0.0.210's password: # イメージ作成時に設定したパスワード Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-93-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage Last login: Fri Sep 1 12:34:38 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 | 7c:99:60:16:6e:79:a5:11:fc:71:f5:c2:77:8c:77:77 | | name | mykey | | user_id | f73e3c2f9e7f4eb793a010f60d5b4674 | +-------------+-------------------------------------------------+root@dlp ~(keystone)# openstack keypair list +-------+-------------------------------------------------+ | Name | Fingerprint | +-------+-------------------------------------------------+ | mykey | 7c:99:60:16:6e:79:a5:11:fc:71:f5:c2:77:8c:77:77 | +-------+-------------------------------------------------+ # キーを指定してインスタンス作成・起動 root@dlp ~(keystone)# openstack server create --flavor m1.small --image Ubuntu1604 --security-group default --nic net-id=$netID --key-name mykey Ubuntu_1604_3
openstack server list +------------------+---------------+--------+------------------+------------+ | ID | Name | Status | Networks | Image Name | +------------------+---------------+--------+------------------+------------+ | 4d3ad582-e200-49 | Ubuntu_1604_3 | ACTIVE | sharednet1=10.0. | Ubuntu1604 | | 24-a636-ea86f167 | | | 0.211 | | | b3bf | | | | | +------------------+---------------+--------+------------------+------------+ # キーを指定してログイン root@dlp ~(keystone)# ssh -i mykey ubuntu@10.0.0.211
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-93-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage Last login: Fri Sep 1 12:34:38 2017ubuntu@ubuntu-1604:~$ # ログインできた
|
[5] | 一旦作成して起動した仮想マシンインスタンスを停止/起動する場合は、以下のように start/stop コマンドで制御できます。 |
root@dlp ~(keystone)# openstack server list +--------------------+-------------+--------+---------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------+-------------+--------+---------------------+------------+ | 852edd8d-f0d3-4366 | Ubuntu_1604 | ACTIVE | sharednet1=10.0.0.2 | Ubuntu1604 | | -8c13-da1a9ea45362 | | | 10 | | +--------------------+-------------+--------+---------------------+------------+ # インスタンス停止 root@dlp ~(keystone)# openstack server stop Ubuntu_1604 root@dlp ~(keystone)# openstack server list +--------------------+-------------+---------+---------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------+-------------+---------+---------------------+------------+ | 852edd8d-f0d3-4366 | Ubuntu_1604 | SHUTOFF | sharednet1=10.0.0.2 | Ubuntu1604 | | -8c13-da1a9ea45362 | | | 10 | | +--------------------+-------------+---------+---------------------+------------+ # インスタンスを起動する root@dlp ~(keystone)# openstack server start Ubuntu_1604 root@dlp ~(keystone)# openstack server list +--------------------+-------------+--------+---------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------+-------------+--------+---------------------+------------+ | 852edd8d-f0d3-4366 | Ubuntu_1604 | ACTIVE | sharednet1=10.0.0.2 | Ubuntu1604 | | -8c13-da1a9ea45362 | | | 10 | | +--------------------+-------------+--------+---------------------+------------+ |
[6] | VNC コンソールを取得して Web ブラウザでのアクセスも可能です。 |
root@dlp ~(keystone)# openstack server list +--------------------+-------------+--------+---------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------+-------------+--------+---------------------+------------+ | 852edd8d-f0d3-4366 | Ubuntu_1604 | ACTIVE | sharednet1=10.0.0.2 | Ubuntu1604 | | -8c13-da1a9ea45362 | | | 10 | | +--------------------+-------------+--------+---------------------+------------+root@dlp ~(keystone)# openstack console url show Ubuntu_1604 +-------+----------------------------------------------------------------------+ | Field | Value | +-------+----------------------------------------------------------------------+ | type | novnc | | url | http://10.0.0.30:6080/vnc_auto.html?token=6e4da98f-e773-4060-ba2b- | | | 89f578083392 | +-------+----------------------------------------------------------------------+ |
[7] | 上記コマンドで表示された URL にアクセスすると、インスタンスにアクセスして操作可能です。 |
Sponsored Link |