Debian 9 Stretch
Sponsored Link

OpenStack Newton : インスタンスを起動する2017/07/02

 
仮想マシンインスタンスを起動します。
[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 |
+--------------------------------------+---------+--------+
| 2a339775-723f-489d-ab6d-66308c750918 | Debian9 | active |
+--------------------------------------+---------+--------+

# 利用可能なネットワーク

root@dlp ~(keystone)#
openstack network list

+--------------------------------------+------------+--------------------------------------+
| ID                                   | Name       | Subnets                              |
+--------------------------------------+------------+--------------------------------------+
| ea530136-b1f8-4cd7-adc4-a6d91743b2ba | sharednet1 | 297b8142-70d1-4386-93f4-da04b12a6b74 |
+--------------------------------------+------------+--------------------------------------+

root@dlp ~(keystone)#
netID=`openstack network list | grep sharednet1 | awk '{ print $2 }'`

# インスタンス作成・起動

root@dlp ~(keystone)#
openstack server create --flavor m1.small --image Debian9 --security-group default --nic net-id=$netID Debian_9

+--------------------------------------+------------------------------------------------+
| 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                            | F2gU8piKq6Yt                                   |
| config_drive                         |                                                |
| created                              | 2017-07-03T06:16:33Z                           |
| flavor                               | m1.small (0)                                   |
| hostId                               |                                                |
| id                                   | 79c861f1-94ef-46ef-ad52-c063a9049993           |
| image                                | Debian9 (2a339775-723f-489d-ab6d-66308c750918) |
| key_name                             | None                                           |
| name                                 | Debian_9                                       |
| os-extended-volumes:volumes_attached | []                                             |
| progress                             | 0                                              |
| project_id                           | 5d0a67ea1741404aa057d1fdb6e4e1be               |
| properties                           |                                                |
| security_groups                      | [{u'name': u'default'}]                        |
| status                               | BUILD                                          |
| updated                              | 2017-07-03T06:16:34Z                           |
| user_id                              | 44ca10f3a8c440ca95487202b50eedbe               |
+--------------------------------------+------------------------------------------------+

# 動作確認 (起動直後しばらくは [BUILD] ステータスとなっている)

root@dlp ~(keystone)#
openstack server list

+--------------------------------------+----------+--------+-----------------------+------------+
| ID                                   | Name     | Status | Networks              | Image Name |
+--------------------------------------+----------+--------+-----------------------+------------+
| 79c861f1-94ef-46ef-ad52-c063a9049993 | Debian_9 | BUILD  | sharednet1=10.0.0.208 | Debian9    |
+--------------------------------------+----------+--------+-----------------------+------------+

# 正常に起動すると [ACTIVE] ステータスとなる

root@dlp ~(keystone)#
openstack server list

+--------------------------------------+----------+--------+-----------------------+------------+
| ID                                   | Name     | Status | Networks              | Image Name |
+--------------------------------------+----------+--------+-----------------------+------------+
| 79c861f1-94ef-46ef-ad52-c063a9049993 | Debian_9 | ACTIVE | sharednet1=10.0.0.208 | Debian9    |
+--------------------------------------+----------+--------+-----------------------+------------+
[2] 起動した仮想マシンインスタンスに SSH 接続できるように、デフォルトセキュリティグループにポート許可の設定を追加します。
# ICMP 許可

root@dlp ~(keystone)#
openstack security group rule create --protocol icmp --ingress default

+-------------------+--------------------------------------+
| Field             | Value                                |
+-------------------+--------------------------------------+
| created_at        | 2017-07-03T06:18:58Z                 |
| description       |                                      |
| direction         | ingress                              |
| ethertype         | IPv4                                 |
| headers           |                                      |
| id                | 3db99a54-9020-4fd7-a314-c88d14f8aee8 |
| port_range_max    | None                                 |
| port_range_min    | None                                 |
| project_id        | 5d0a67ea1741404aa057d1fdb6e4e1be     |
| project_id        | 5d0a67ea1741404aa057d1fdb6e4e1be     |
| protocol          | icmp                                 |
| remote_group_id   | None                                 |
| remote_ip_prefix  | 0.0.0.0/0                            |
| revision_number   | 1                                    |
| security_group_id | 68ceee9b-79e8-43c7-b3f8-94f338b41f97 |
| updated_at        | 2017-07-03T06:18:58Z                 |
+-------------------+--------------------------------------+

# SSH 許可

root@dlp ~(keystone)#
openstack security group rule create --protocol tcp --dst-port 22:22 default

+-------------------+--------------------------------------+
| Field             | Value                                |
+-------------------+--------------------------------------+
| created_at        | 2017-07-03T06:19:20Z                 |
| description       |                                      |
| direction         | ingress                              |
| ethertype         | IPv4                                 |
| headers           |                                      |
| id                | 40959fe3-67eb-4a40-9aad-7b6fcf97882c |
| port_range_max    | 22                                   |
| port_range_min    | 22                                   |
| project_id        | 5d0a67ea1741404aa057d1fdb6e4e1be     |
| project_id        | 5d0a67ea1741404aa057d1fdb6e4e1be     |
| protocol          | tcp                                  |
| remote_group_id   | None                                 |
| remote_ip_prefix  | 0.0.0.0/0                            |
| revision_number   | 1                                    |
| security_group_id | 68ceee9b-79e8-43c7-b3f8-94f338b41f97 |
| updated_at        | 2017-07-03T06:19:20Z                 |
+-------------------+--------------------------------------+

root@dlp ~(keystone)#
openstack security group rule list

+-----------+-------------+-----------+------------+--------------------------------------+-----------------+
| ID        | IP Protocol | IP Range  | Port Range | Remote Security Group                | Security Group  |
+-----------+-------------+-----------+------------+--------------------------------------+-----------------+
| 20b862df- | None        | None      |            | 68ceee9b-79e8-43c7-b3f8-94f338b41f97 | 68ceee9b-79e8-4 |
| 3db99a54- | icmp        | 0.0.0.0/0 |            | None                                 | 68ceee9b-79e8-4 |
| 40959fe3- | tcp         | 0.0.0.0/0 | 22:22      | None                                 | 68ceee9b-79e8-4 |
| 7f9525d6- | None        | None      |            | 68ceee9b-79e8-43c7-b3f8-94f338b41f97 | 68ceee9b-79e8-4 |
| 7fb6255b- | None        | None      |            | None                                 | 68ceee9b-79e8-4 |
| dc087e27- | None        | None      |            | None                                 | 68ceee9b-79e8-4 |
+-----------+-------------+-----------+------------+--------------------------------------+-----------------+
[3] 起動した仮想マシンインスタンスに SSH ログインします。
root@dlp ~(keystone)#
openstack server list

+--------------------------------------+----------+--------+-----------------------+------------+
| ID                                   | Name     | Status | Networks              | Image Name |
+--------------------------------------+----------+--------+-----------------------+------------+
| 79c861f1-94ef-46ef-ad52-c063a9049993 | Debian_9 | ACTIVE | sharednet1=10.0.0.208 | Debian9    |
+--------------------------------------+----------+--------+-----------------------+------------+

# ping 応答が返ってくれば OK

root@dlp ~(keystone)#
ping 10.0.0.208

PING 10.0.0.208 (10.0.0.208) 56(84) bytes of data.
64 bytes from 10.0.0.208: icmp_seq=1 ttl=64 time=1.33 ms
64 bytes from 10.0.0.208: icmp_seq=2 ttl=64 time=0.806 ms
64 bytes from 10.0.0.208: icmp_seq=3 ttl=64 time=0.780 ms
^C
--- 10.0.0.208 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 0.741/0.915/1.333/0.242 ms

# SSH ログイン

root@dlp ~(keystone)#
ssh debian@10.0.0.208

The authenticity of host '10.0.0.208 (10.0.0.208)' can't be established.
ECDSA key fingerprint is SHA256:bTg2kfBSCHnTgZ+ioacbzWvr010+mvRjCfigDgjeQVE.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.208' (ECDSA) to the list of known hosts.
debian@10.0.0.208's password:   # イメージ作成時に設定したパスワード 
Linux debian-9 4.9.0-3-amd64 #1 SMP Debian 4.9.30-2+deb9u2 (2017-06-26) 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-9:~$    
# ログインできた

[4] インターネットから取得した仮想マシンイメージを利用中でパスワードが不明な場合は、SSH 鍵を登録することでログイン可能です。 自身で作成したイメージの場合は、前もって仮想マシンイメージに [cloud-init] パッケージをインストールし、[cloud-init] サービスを有効にしておくことで、SSH 鍵でのログインが可能となります。ちなみに、cloud-init のデフォルト設定は [debian] が 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 | 83:c6:77:3f:c7:cd:59:5d:1b:e0:87:fa:b9:cf:df:c4 |
| name        | mykey                                           |
| user_id     | 44ca10f3a8c440ca95487202b50eedbe                |
+-------------+-------------------------------------------------+

root@dlp ~(keystone)#
openstack keypair list

+-------+-------------------------------------------------+
| Name  | Fingerprint                                     |
+-------+-------------------------------------------------+
| mykey | 83:c6:77:3f:c7:cd:59:5d:1b:e0:87:fa:b9:cf:df:c4 |
+-------+-------------------------------------------------+

# キーを指定してインスタンス作成・起動

root@dlp ~(keystone)#
openstack server create --flavor m1.small --image Debian9 --security-group default --nic net-id=$netID --key-name mykey Debian_90
root@dlp ~(keystone)#
openstack server list

+--------------------------------------+-----------+---------+-----------------------+------------+
| ID                                   | Name      | Status  | Networks              | Image Name |
+--------------------------------------+-----------+---------+-----------------------+------------+
| 1475f09e-6d22-4cae-9110-4e3172329ece | Debian_90 | ACTIVE  | sharednet1=10.0.0.202 | Debian9    |
| 79c861f1-94ef-46ef-ad52-c063a9049993 | Debian_9  | SHUTOFF | sharednet1=10.0.0.208 | Debian9    |
+--------------------------------------+-----------+---------+-----------------------+------------+

# キーを指定してログイン

root@dlp ~(keystone)#
ssh -i mykey debian@10.0.0.202
Warning: Identity file mykey not accessible: No such file or directory.
The authenticity of host '10.0.0.202 (10.0.0.202)' can't be established.
ECDSA key fingerprint is SHA256:2Ju1wWswMRawZsnnywRoAc9ueEcHbZLzRzVBuKzQIwQ.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.202' (ECDSA) to the list of known hosts.
Linux debian-90 4.9.0-3-amd64 #1 SMP Debian 4.9.30-2+deb9u2 (2017-06-26) 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-90:~$    
# ログインできた
[5] 一旦作成して起動した仮想マシンインスタンスを停止/起動する場合は、以下のように start/stop コマンドで制御できます。
root@dlp ~(keystone)#
openstack server list

+--------------------------------------+----------+--------+-----------------------+------------+
| ID                                   | Name     | Status | Networks              | Image Name |
+--------------------------------------+----------+--------+-----------------------+------------+
| 79c861f1-94ef-46ef-ad52-c063a9049993 | Debian_9 | ACTIVE | sharednet1=10.0.0.208 | Debian9    |
+--------------------------------------+----------+--------+-----------------------+------------+

# インスタンス停止

root@dlp ~(keystone)#
openstack server stop Debian_9

root@dlp ~(keystone)#
openstack server list

+--------------------------------------+----------+---------+-----------------------+------------+
| ID                                   | Name     | Status  | Networks              | Image Name |
+--------------------------------------+----------+---------+-----------------------+------------+
| 79c861f1-94ef-46ef-ad52-c063a9049993 | Debian_9 | SHUTOFF | sharednet1=10.0.0.208 | Debian9    |
+--------------------------------------+----------+---------+-----------------------+------------+

# インスタンスを起動する

root@dlp ~(keystone)#
openstack server start Debian_9

root@dlp ~(keystone)#
openstack server list

+--------------------------------------+----------+--------+-----------------------+------------+
| ID                                   | Name     | Status | Networks              | Image Name |
+--------------------------------------+----------+--------+-----------------------+------------+
| 79c861f1-94ef-46ef-ad52-c063a9049993 | Debian_9 | ACTIVE | sharednet1=10.0.0.208 | Debian9    |
+--------------------------------------+----------+--------+-----------------------+------------+
[6] VNC コンソールを取得して Web ブラウザでのアクセスも可能です。
root@dlp ~(keystone)#
openstack server list

+--------------------------------------+----------+--------+-----------------------+------------+
| ID                                   | Name     | Status | Networks              | Image Name |
+--------------------------------------+----------+--------+-----------------------+------------+
| 79c861f1-94ef-46ef-ad52-c063a9049993 | Debian_9 | ACTIVE | sharednet1=10.0.0.208 | Debian9    |
+--------------------------------------+----------+--------+-----------------------+------------+

root@dlp ~(keystone)#
openstack console url show Debian_9

+-------+--------------------------------------------------------------------------------+
| Field | Value                                                                          |
+-------+--------------------------------------------------------------------------------+
| type  | novnc                                                                          |
| url   | http://10.0.0.30:6080/vnc_auto.html?token=d5e4a94f-3a04-4caa-bba3-fd78b3035270 |
+-------+--------------------------------------------------------------------------------+
[7] 上記コマンドで表示された URL にアクセスすると、インスタンスにアクセスして操作可能です。
関連コンテンツ