CentOS 7
Sponsored Link

OpenStack Queens : インスタンスを起動する2018/03/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 |
+--------------------------------------+---------+--------+
| 88551fbc-ce7e-4719-a67a-dd7cad478019 | CentOS7 | active |
+--------------------------------------+---------+--------+

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

[cent@dlp ~(keystone)]$
openstack network list

+--------------------------------------+------------+--------------------------------------+
| ID                                   | Name       | Subnets                              |
+--------------------------------------+------------+--------------------------------------+
| 535194ec-9acd-4132-bfe7-0979d908f145 | sharednet1 | d3c17a00-d3ff-4bf2-8d98-03cd6b95c57a |
+--------------------------------------+------------+--------------------------------------+

# インスタンス用のセキュリティグループを作成

[cent@dlp ~(keystone)]$
openstack security group create secgroup01

+-----------------+------------------------------------------------------------+
| Field           | Value                                                      |
+-----------------+------------------------------------------------------------+
| created_at      | 2018-03-07T02:46:41Z                                       |
| description     | secgroup01                                                 |
| id              | 531679bf-6f46-40ca-805a-328da125198b                       |
| name            | secgroup01                                                 |
| project_id      | a3c3e533531c48c48dcd643d13d307e5                           |
| revision_number | 2                                                          |
| rules           | created_at='2018-03-07T02:46:41Z', direction='egress',...' |
|                 | created_at='2018-03-07T02:46:41Z', direction='egress',...' |
| updated_at      | 2018-03-07T02:46:41Z                                       |
+-----------------+------------------------------------------------------------+

[cent@dlp ~(keystone)]$
openstack security group list

+--------------+------------+------------------------+----------------------------------+
| ID           | Name       | Description            | Project                          |
+--------------+------------+------------------------+----------------------------------+
| 531679bf-... | secgroup01 | secgroup01             | a3c3e533531c48c48dcd643d13d307e5 |
| f074c601-... | default    | Default security group | a3c3e533531c48c48dcd643d13d307e5 |
+--------------+------------+------------------------+----------------------------------+

# インスタンス接続用の 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 | 36:fe:4c:e4:7f:a3:27:1a:f7:a3:4f:fa:b9:a6:16:92 |
| name        | mykey                                           |
| user_id     | a1ecf467167542bdb615ba4311f4bf0a                |
+-------------+-------------------------------------------------+

[cent@dlp ~(keystone)]$
openstack keypair list

+-------+-------------------------------------------------+
| Name  | Fingerprint                                     |
+-------+-------------------------------------------------+
| mykey | 36:fe:4c:e4:7f:a3:27:1a:f7:a3:4f:fa:b9:a6:16:92 |
+-------+-------------------------------------------------+

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

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

[cent@dlp ~(keystone)]$
openstack server create --flavor m1.small --image CentOS7 --security-group secgroup01 --nic net-id=$netID --key-name mykey CentOS_7
+-----------------------------+------------------------------------------------+
| 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                   | 7zEPamrpKwTN                                   |
| config_drive                |                                                |
| created                     | 2018-03-07T02:52:05Z                           |
| flavor                      | m1.small (0)                                   |
| hostId                      |                                                |
| id                          | a4974dee-7791-4dec-81d9-d348ee7e1ebd           |
| image                       | CentOS7 (88551fbc-ce7e-4719-a67a-dd7cad478019) |
| key_name                    | mykey                                          |
| name                        | CentOS_7                                       |
| progress                    | 0                                              |
| project_id                  | a3c3e533531c48c48dcd643d13d307e5               |
| properties                  |                                                |
| security_groups             | name='531679bf-6f46-40ca-805a-328da125198b'    |
| status                      | BUILD                                          |
| updated                     | 2018-03-07T02:52:05Z                           |
| user_id                     | a1ecf467167542bdb615ba4311f4bf0a               |
| volumes_attached            |                                                |
+-----------------------------+------------------------------------------------+

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

[cent@dlp ~(keystone)]$
openstack server list

+--------------------------------------+----------+--------+-----------------------+---------+----------+
| ID                                   | Name     | Status | Networks              | Image   | Flavor   |
+--------------------------------------+----------+--------+-----------------------+---------+----------+
| a4974dee-7791-4dec-81d9-d348ee7e1ebd | CentOS_7 | BUILD  | sharednet1=10.0.0.202 | CentOS7 | m1.small |
+--------------------------------------+----------+--------+-----------------------+---------+----------+

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

[cent@dlp ~(keystone)]$
openstack server list

+--------------------------------------+----------+--------+-----------------------+---------+----------+
| ID                                   | Name     | Status | Networks              | Image   | Flavor   |
+--------------------------------------+----------+--------+-----------------------+---------+----------+
| a4974dee-7791-4dec-81d9-d348ee7e1ebd | CentOS_7 | ACTIVE | sharednet1=10.0.0.202 | CentOS7 | m1.small |
+--------------------------------------+----------+--------+-----------------------+---------+----------+
[2] 起動した仮想マシンインスタンスに SSH 接続できるように、先に作成したセキュリティグループにポート許可の設定を追加します。
# ICMP 許可

[cent@dlp ~(keystone)]$
openstack security group rule create --protocol icmp --ingress secgroup01

+-------------------+--------------------------------------+
| Field             | Value                                |
+-------------------+--------------------------------------+
| created_at        | 2018-03-07T03:41:24Z                 |
| description       |                                      |
| direction         | ingress                              |
| ether_type        | IPv4                                 |
| id                | fcd9c723-99f3-4b34-9621-46bdc4a78fd3 |
| name              | None                                 |
| port_range_max    | None                                 |
| port_range_min    | None                                 |
| project_id        | a3c3e533531c48c48dcd643d13d307e5     |
| protocol          | icmp                                 |
| remote_group_id   | None                                 |
| remote_ip_prefix  | 0.0.0.0/0                            |
| revision_number   | 0                                    |
| security_group_id | 531679bf-6f46-40ca-805a-328da125198b |
| updated_at        | 2018-03-07T03:41:24Z                 |
+-------------------+--------------------------------------+

# SSH 許可

[cent@dlp ~(keystone)]$
openstack security group rule create --protocol tcp --dst-port 22:22 secgroup01

+-------------------+--------------------------------------+
| Field             | Value                                |
+-------------------+--------------------------------------+
| created_at        | 2018-03-07T03:41:41Z                 |
| description       |                                      |
| direction         | ingress                              |
| ether_type        | IPv4                                 |
| id                | a80efaec-1f24-423f-ba99-c90b4c5b9046 |
| name              | None                                 |
| port_range_max    | 22                                   |
| port_range_min    | 22                                   |
| project_id        | a3c3e533531c48c48dcd643d13d307e5     |
| protocol          | tcp                                  |
| remote_group_id   | None                                 |
| remote_ip_prefix  | 0.0.0.0/0                            |
| revision_number   | 0                                    |
| security_group_id | 531679bf-6f46-40ca-805a-328da125198b |
| updated_at        | 2018-03-07T03:41:41Z                 |
+-------------------+--------------------------------------+

[cent@dlp ~(keystone)]$
openstack security group rule list

+--------------+-------------+-----------+------------+-----------------------------+---------------------+
| ID           | IP Protocol | IP Range  | Port Range | Remote Security Group       | Security Group      |
+--------------+-------------+-----------+------------+-----------------------------+---------------------+
| 073e7f63-... | None        | None      |            | f074c601-6177-4bd8-bcac-... | f074c601-6177-43... |
| 4ae961ff-... | None        | None      |            | None                        | 531679bf-6f46-41... |
| 4d1df410-... | None        | None      |            | None                        | f074c601-6177-43... |
| a80efaec-... | tcp         | 0.0.0.0/0 | 22:22      | None                        | 531679bf-6f46-41... |
| da9cdf72-... | None        | None      |            | f074c601-6177-4bd8-bcac-... | f074c601-6177-43... |
| e2d26251-... | None        | None      |            | None                        | f074c601-6177-43... |
| e6f25123-... | None        | None      |            | None                        | 531679bf-6f46-41... |
| fcd9c723-... | icmp        | 0.0.0.0/0 |            | None                        | 531679bf-6f46-41... |
+--------------+-------------+-----------+------------+-----------------------------+---------------------+
[3] 起動した仮想マシンインスタンスに SSH ログインします。
[cent@dlp ~(keystone)]$
openstack server list

+--------------------------------------+----------+--------+-----------------------+---------+----------+
| ID                                   | Name     | Status | Networks              | Image   | Flavor   |
+--------------------------------------+----------+--------+-----------------------+---------+----------+
| a4974dee-7791-4dec-81d9-d348ee7e1ebd | CentOS_7 | ACTIVE | sharednet1=10.0.0.202 | CentOS7 | m1.small |
+--------------------------------------+----------+--------+-----------------------+---------+----------+

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

[cent@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.94 ms
64 bytes from 10.0.0.202: icmp_seq=2 ttl=64 time=1.24 ms
64 bytes from 10.0.0.202: icmp_seq=3 ttl=64 time=1.21 ms

--- 10.0.0.202 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 1.214/2.134/3.948/1.283 ms

# SSH でログイン

[cent@dlp ~(keystone)]$
ssh centos@10.0.0.202
The authenticity of host '10.0.0.202 (10.0.0.202)' can't be established.
ECDSA key fingerprint is SHA256:xHIBEd/rhh5IPJGv7rXS/VmbM+4i2FJMA6UWPA0UUT8.
ECDSA key fingerprint is MD5:5b:01:d5:5a:40:c5:1a:d7:05:40:f6:96:0a:db:52:6d.
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 コマンドで制御できます。
[cent@dlp ~(keystone)]$
openstack server list

+--------------------------------------+----------+--------+-----------------------+---------+----------+
| ID                                   | Name     | Status | Networks              | Image   | Flavor   |
+--------------------------------------+----------+--------+-----------------------+---------+----------+
| a4974dee-7791-4dec-81d9-d348ee7e1ebd | CentOS_7 | ACTIVE | sharednet1=10.0.0.202 | CentOS7 | m1.small |
+--------------------------------------+----------+--------+-----------------------+---------+----------+

# インスタンス停止

[cent@dlp ~(keystone)]$
openstack server stop CentOS_7

[cent@dlp ~(keystone)]$
openstack server list

+--------------------------------------+----------+---------+-----------------------+---------+----------+
| ID                                   | Name     | Status  | Networks              | Image   | Flavor   |
+--------------------------------------+----------+---------+-----------------------+---------+----------+
| a4974dee-7791-4dec-81d9-d348ee7e1ebd | CentOS_7 | SHUTOFF | sharednet1=10.0.0.202 | CentOS7 | m1.small |
+--------------------------------------+----------+---------+-----------------------+---------+----------+

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

[cent@dlp ~(keystone)]$
openstack server start CentOS_7

[cent@dlp ~(keystone)]$
openstack server list

+--------------------------------------+----------+--------+-----------------------+---------+----------+
| ID                                   | Name     | Status | Networks              | Image   | Flavor   |
+--------------------------------------+----------+--------+-----------------------+---------+----------+
| a4974dee-7791-4dec-81d9-d348ee7e1ebd | CentOS_7 | ACTIVE | sharednet1=10.0.0.202 | CentOS7 | m1.small |
+--------------------------------------+----------+--------+-----------------------+---------+----------+
[5] VNC コンソールを取得して Web ブラウザでのアクセスも可能です。
[cent@dlp ~(keystone)]$
openstack server list

+--------------------------------------+----------+--------+-----------------------+---------+----------+
| ID                                   | Name     | Status | Networks              | Image   | Flavor   |
+--------------------------------------+----------+--------+-----------------------+---------+----------+
| a4974dee-7791-4dec-81d9-d348ee7e1ebd | CentOS_7 | ACTIVE | sharednet1=10.0.0.202 | CentOS7 | m1.small |
+--------------------------------------+----------+--------+-----------------------+---------+----------+

[cent@dlp ~(keystone)]$
openstack console url show CentOS_7

+-------+--------------------------------------------------------------------------------+
| Field | Value                                                                          |
+-------+--------------------------------------------------------------------------------+
| type  | novnc                                                                          |
| url   | http://10.0.0.30:6080/vnc_auto.html?token=37a06156-b9d7-469d-932d-ac88a9fae1ea |
+-------+--------------------------------------------------------------------------------+
[6] 上記コマンドで表示された URL に Web アクセスすると、インスタンスに接続され、操作が可能となります。
関連コンテンツ