CentOS 7
Sponsored Link

OpenStack Pike : インスタンスを起動する2017/09/03

 
仮想マシンインスタンスを起動します。
[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 |
+--------------------------------------+---------+--------+
| 68132026-60aa-4afe-8976-398b0482cfd6 | CentOS7 | active |
+--------------------------------------+---------+--------+

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

[root@dlp ~(keystone)]#
openstack network list

+--------------------------------------+------------+--------------------------------------+
| ID                                   | Name       | Subnets                              |
+--------------------------------------+------------+--------------------------------------+
| fdb1468f-b479-4cbc-b82e-582719536cbc | sharednet1 | bd84f1db-6f15-4994-9f1c-54bbe9c79152 |
+--------------------------------------+------------+--------------------------------------+

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

# キーペア作成

[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 | b3:d6:64:1a:6f:4e:14:63:88:76:15:a4:bd:af:a6:34 |
| name        | mykey                                           |
| user_id     | 09d8dfa20e0f40eaae448d369943b195                |
+-------------+-------------------------------------------------+

[root@dlp ~(keystone)]#
openstack keypair list

+-------+-------------------------------------------------+
| Name  | Fingerprint                                     |
+-------+-------------------------------------------------+
| mykey | b3:d6:64:1a:6f:4e:14:63:88:76:15:a4:bd:af:a6:34 |
+-------+-------------------------------------------------+

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

[root@dlp ~(keystone)]#
openstack server create --flavor m1.small --image CentOS7 --security-group default --nic net-id=$netID --key-name mykey CentOS_7
+-------------------------------------+------------------------------------------------+
| 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                           | JQF2YtHUDhh3                                   |
| config_drive                        |                                                |
| created                             | 2017-09-04T08:19:03Z                           |
| flavor                              | m1.small (0)                                   |
| hostId                              |                                                |
| id                                  | 84ebd05f-971e-4d1a-9dd3-3c43a4ddf3f2           |
| image                               | CentOS7 (68132026-60aa-4afe-8976-398b0482cfd6) |
| key_name                            | mykey                                          |
| name                                | CentOS_7                                       |
| progress                            | 0                                              |
| project_id                          | 09158bee8c6441519bf3a3743d936566               |
| properties                          |                                                |
| security_groups                     | name='b8b67ada-379b-4c5f-8ac8-899e943dbbe0'    |
| status                              | BUILD                                          |
| updated                             | 2017-09-04T08:19:03Z                           |
| user_id                             | 09d8dfa20e0f40eaae448d369943b195               |
| volumes_attached                    |                                                |
+-------------------------------------+------------------------------------------------+

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

[root@dlp ~(keystone)]#
openstack server list

+--------------------------------------+----------+--------+-----------------------+---------+----------+
| ID                                   | Name     | Status | Networks              | Image   | Flavor   |
+--------------------------------------+----------+--------+-----------------------+---------+----------+
| 84ebd05f-971e-4d1a-9dd3-3c43a4ddf3f2 | CentOS_7 | BUILD  | sharednet1=10.0.0.202 | CentOS7 | m1.small |
+--------------------------------------+----------+--------+-----------------------+---------+----------+


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

[root@dlp ~(keystone)]#
openstack server list

+--------------------------------------+----------+--------+-----------------------+---------+----------+
| ID                                   | Name     | Status | Networks              | Image   | Flavor   |
+--------------------------------------+----------+--------+-----------------------+---------+----------+
| 84ebd05f-971e-4d1a-9dd3-3c43a4ddf3f2 | CentOS_7 | ACTIVE | sharednet1=10.0.0.202 | CentOS7 | m1.small |
+--------------------------------------+----------+--------+-----------------------+---------+----------+
[2] 起動した仮想マシンインスタンスに SSH 接続できるように、デフォルトセキュリティグループにポート許可の設定を追加します。
# ICMP 許可

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

+-------------------+--------------------------------------+
| Field             | Value                                |
+-------------------+--------------------------------------+
| created_at        | 2017-09-04T08:20:44Z                 |
| description       |                                      |
| direction         | ingress                              |
| ether_type        | IPv4                                 |
| id                | 6ef8160e-fd04-45cd-a569-93f068d0635f |
| name              | None                                 |
| port_range_max    | None                                 |
| port_range_min    | None                                 |
| project_id        | 09158bee8c6441519bf3a3743d936566     |
| protocol          | icmp                                 |
| remote_group_id   | None                                 |
| remote_ip_prefix  | 0.0.0.0/0                            |
| revision_number   | 0                                    |
| security_group_id | b8b67ada-379b-4c5f-8ac8-899e943dbbe0 |
| updated_at        | 2017-09-04T08:20:44Z                 |
+-------------------+--------------------------------------+

# SSH 許可

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

+-------------------+--------------------------------------+
| Field             | Value                                |
+-------------------+--------------------------------------+
| created_at        | 2017-09-04T08:21:04Z                 |
| description       |                                      |
| direction         | ingress                              |
| ether_type        | IPv4                                 |
| id                | 3ec427f4-9f9f-4ece-aced-1b4b2a4e14a7 |
| name              | None                                 |
| port_range_max    | 22                                   |
| port_range_min    | 22                                   |
| project_id        | 09158bee8c6441519bf3a3743d936566     |
| protocol          | tcp                                  |
| remote_group_id   | None                                 |
| remote_ip_prefix  | 0.0.0.0/0                            |
| revision_number   | 0                                    |
| security_group_id | b8b67ada-379b-4c5f-8ac8-899e943dbbe0 |
| updated_at        | 2017-09-04T08:21:04Z                 |
+-------------------+--------------------------------------+

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

+--------------+-------------+-----------+------------+--------------------------------------+-------------------+
| ID           | IP Protocol | IP Range  | Port Range | Remote Security Group                | Security Group    |
+--------------+-------------+-----------+------------+--------------------------------------+-------------------+
| 04544fda-... | None        | None      |            | None                                 | b8b67ada-379b-... |
| 0c1f30a4-... | None        | None      |            | b8b67ada-379b-4c5f-8ac8-899e943dbbe0 | b8b67ada-379b-... |
| 2c70e734-... | None        | None      |            | None                                 | b8b67ada-379b-... |
| 3ec427f4-... | tcp         | 0.0.0.0/0 | 22:22      | None                                 | b8b67ada-379b-... |
| 6ef8160e-... | icmp        | 0.0.0.0/0 |            | None                                 | b8b67ada-379b-... |
| a3745804-... | None        | None      |            | b8b67ada-379b-4c5f-8ac8-899e943dbbe0 | b8b67ada-379b-... |
+--------------+-------------+-----------+------------+--------------------------------------+-------------------+
[3] 起動した仮想マシンインスタンスに SSH ログインします。
[root@dlp ~(keystone)]#
openstack server list

+--------------------------------------+----------+--------+-----------------------+---------+----------+
| ID                                   | Name     | Status | Networks              | Image   | Flavor   |
+--------------------------------------+----------+--------+-----------------------+---------+----------+
| 84ebd05f-971e-4d1a-9dd3-3c43a4ddf3f2 | CentOS_7 | ACTIVE | sharednet1=10.0.0.202 | CentOS7 | m1.small |
+--------------------------------------+----------+--------+-----------------------+---------+----------+

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

[root@dlp ~(keystone)]#
ping 10.0.0.202 -c3

PING 10.0.0.202 (10.0.0.202) 56(84) bytes of data.
64 bytes from 10.0.0.202: icmp_seq=1 ttl=64 time=3.13 ms
64 bytes from 10.0.0.202: icmp_seq=2 ttl=64 time=0.833 ms
64 bytes from 10.0.0.202: icmp_seq=3 ttl=64 time=0.831 ms

--- 10.0.0.202 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 0.831/1.600/3.136/1.086 ms

# 作成したSSHキーを指定してログイン

[root@dlp ~(keystone)]#
ssh -i mykey centos@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 94:11:48:02:fa:62:ff:9c:c4:75:8f:eb:16:62:a9:ff.
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.
[centos@centos-7 ~]$    
# ログインできた

[4] 一旦作成して起動した仮想マシンインスタンスを停止/起動する場合は、以下のように start/stop コマンドで制御できます。
[root@dlp ~(keystone)]#
openstack server list

+--------------------------------------+----------+--------+-----------------------+---------+----------+
| ID                                   | Name     | Status | Networks              | Image   | Flavor   |
+--------------------------------------+----------+--------+-----------------------+---------+----------+
| 84ebd05f-971e-4d1a-9dd3-3c43a4ddf3f2 | CentOS_7 | ACTIVE | sharednet1=10.0.0.202 | CentOS7 | m1.small |
+--------------------------------------+----------+--------+-----------------------+---------+----------+

# インスタンス停止

[root@dlp ~(keystone)]#
openstack server stop CentOS_7

[root@dlp ~(keystone)]#
openstack server list

+--------------------------------------+----------+---------+-----------------------+---------+----------+
| ID                                   | Name     | Status  | Networks              | Image   | Flavor   |
+--------------------------------------+----------+---------+-----------------------+---------+----------+
| 84ebd05f-971e-4d1a-9dd3-3c43a4ddf3f2 | CentOS_7 | SHUTOFF | sharednet1=10.0.0.202 | CentOS7 | m1.small |
+--------------------------------------+----------+---------+-----------------------+---------+----------+

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

[root@dlp ~(keystone)]#
openstack server start CentOS_7

[root@dlp ~(keystone)]#
openstack server list

+--------------------------------------+----------+--------+-----------------------+---------+----------+
| ID                                   | Name     | Status | Networks              | Image   | Flavor   |
+--------------------------------------+----------+--------+-----------------------+---------+----------+
| 84ebd05f-971e-4d1a-9dd3-3c43a4ddf3f2 | CentOS_7 | ACTIVE | sharednet1=10.0.0.202 | CentOS7 | m1.small |
+--------------------------------------+----------+--------+-----------------------+---------+----------+
[5] VNC コンソールを取得して Web ブラウザでのアクセスも可能です。
[root@dlp ~(keystone)]#
openstack server list

+-----------+----------+--------+-----------------------+---------+----------+
| ID        | Name     | Status | Networks              | Image   | Flavor   |
+-----------+----------+--------+-----------------------+---------+----------+
| 84ebd0... | CentOS_7 | ACTIVE | sharednet1=10.0.0.202 | CentOS7 | m1.small |
+-----------+----------+--------+-----------------------+---------+----------+

[root@dlp ~(keystone)]#
openstack console url show CentOS_7

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