CentOS 7
Sponsored Link

OpenStack Rocky : インスタンスを起動する
2018/08/31
 
仮想マシンインスタンスを起動します。
[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 |
+--------------------------------------+---------+--------+
| 05269b20-9625-46b6-8377-3893c70906bd | CentOS7 | active |
+--------------------------------------+---------+--------+

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

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

+--------------------------------------+------------+--------------------------------------+
| ID                                   | Name       | Subnets                              |
+--------------------------------------+------------+--------------------------------------+
| eaaf7e9b-a448-4827-b07c-e0c75dd2410c | sharednet1 | d3e3dca6-218a-405a-b115-70d5a257620e |
+--------------------------------------+------------+--------------------------------------+

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

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

+-----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field           | Value                                                                                                                                                 |
+-----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+
| created_at      | 2018-08-31T03:44:23Z                                                                                                                                  |
| description     | secgroup01                                                                                                                                            |
| id              | 504974ac-4389-4474-bd6b-499cad7de9a4                                                                                                                  |
| name            | secgroup01                                                                                                                                            |
| project_id      | 9c0848a6869b433f8c18c75a868ee8e0                                                                                                                      |
| revision_number | 1                                                                                                                                                     |
| rules           | created_at='2018-08-31T03:44:23Z', direction='egress', ethertype='IPv6', id='05ebbd23-a11a-4c7d-9e94-313b41224b1b', updated_at='2018-08-31T03:44:23Z' |
|                 | created_at='2018-08-31T03:44:23Z', direction='egress', ethertype='IPv4', id='5ebaa40e-1420-4831-802a-97233ab8afee', updated_at='2018-08-31T03:44:23Z' |
| tags            | []                                                                                                                                                    |
| updated_at      | 2018-08-31T03:44:23Z                                                                                                                                  |
+-----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+

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

+--------------------------------------+------------+------------------------+----------------------------------+------+
| ID                                   | Name       | Description            | Project                          | Tags |
+--------------------------------------+------------+------------------------+----------------------------------+------+
| 504974ac-4389-4474-bd6b-499cad7de9a4 | secgroup01 | secgroup01             | 9c0848a6869b433f8c18c75a868ee8e0 | []   |
| f4ecd970-95f3-4147-a532-2a41b7041dce | default    | Default security group | 9c0848a6869b433f8c18c75a868ee8e0 | []   |
+--------------------------------------+------------+------------------------+----------------------------------+------+

# インスタンス接続用の 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 | 74:04:ac:87:65:b0:1b:11:45:a1:ae:42:69:0d:1b:d5 |
| name        | mykey                                           |
| user_id     | 30089f6b629745c697ec11038c34d5df                |
+-------------+-------------------------------------------------+

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

+-------+-------------------------------------------------+
| Name  | Fingerprint                                     |
+-------+-------------------------------------------------+
| mykey | 74:04:ac:87:65:b0:1b:11:45:a1:ae:42:69:0d:1b:d5 |
+-------+-------------------------------------------------+

[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                   | VK93X24Ug2g7                                   |
| config_drive                |                                                |
| created                     | 2018-08-31T03:47:53Z                           |
| flavor                      | m1.small (0)                                   |
| hostId                      |                                                |
| id                          | e07e180f-3622-43f0-8477-01baf16e5267           |
| image                       | CentOS7 (05269b20-9625-46b6-8377-3893c70906bd) |
| key_name                    | mykey                                          |
| name                        | CentOS_7                                       |
| progress                    | 0                                              |
| project_id                  | 9c0848a6869b433f8c18c75a868ee8e0               |
| properties                  |                                                |
| security_groups             | name='504974ac-4389-4474-bd6b-499cad7de9a4'    |
| status                      | BUILD                                          |
| updated                     | 2018-08-31T03:47:53Z                           |
| user_id                     | 30089f6b629745c697ec11038c34d5df               |
| volumes_attached            |                                                |
+-----------------------------+------------------------------------------------+

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

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

+--------------------------------------+----------+--------+----------+---------+----------+
| ID                                   | Name     | Status | Networks | Image   | Flavor   |
+--------------------------------------+----------+--------+----------+---------+----------+
| e07e180f-3622-43f0-8477-01baf16e5267 | CentOS_7 | BUILD  |          | CentOS7 | m1.small |
+--------------------------------------+----------+--------+----------+---------+----------+

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

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

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

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

+-------------------+--------------------------------------+
| Field             | Value                                |
+-------------------+--------------------------------------+
| created_at        | 2018-08-31T03:48:51Z                 |
| description       |                                      |
| direction         | ingress                              |
| ether_type        | IPv4                                 |
| id                | db32dac3-ee3e-420f-b89e-00156753d68a |
| name              | None                                 |
| port_range_max    | None                                 |
| port_range_min    | None                                 |
| project_id        | 9c0848a6869b433f8c18c75a868ee8e0     |
| protocol          | icmp                                 |
| remote_group_id   | None                                 |
| remote_ip_prefix  | 0.0.0.0/0                            |
| revision_number   | 0                                    |
| security_group_id | 504974ac-4389-4474-bd6b-499cad7de9a4 |
| updated_at        | 2018-08-31T03:48:51Z                 |
+-------------------+--------------------------------------+

# SSH 許可

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

+-------------------+--------------------------------------+
| Field             | Value                                |
+-------------------+--------------------------------------+
| created_at        | 2018-08-31T03:49:06Z                 |
| description       |                                      |
| direction         | ingress                              |
| ether_type        | IPv4                                 |
| id                | 9ef85819-9fbc-4f4e-ada3-d085e3935b14 |
| name              | None                                 |
| port_range_max    | 22                                   |
| port_range_min    | 22                                   |
| project_id        | 9c0848a6869b433f8c18c75a868ee8e0     |
| protocol          | tcp                                  |
| remote_group_id   | None                                 |
| remote_ip_prefix  | 0.0.0.0/0                            |
| revision_number   | 0                                    |
| security_group_id | 504974ac-4389-4474-bd6b-499cad7de9a4 |
| updated_at        | 2018-08-31T03:49:06Z                 |
+-------------------+--------------------------------------+

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

+--------------------------------------+-------------+-----------+------------+--------------------------------------+--------------------------------------+
| ID                                   | IP Protocol | IP Range  | Port Range | Remote Security Group                | Security Group                       |
+--------------------------------------+-------------+-----------+------------+--------------------------------------+--------------------------------------+
| 05ebbd23-a11a-4c7d-9e94-313b41224b1b | None        | None      |            | None                                 | 504974ac-4389-4474-bd6b-499cad7de9a4 |
| 15c8a42c-3b5a-46f0-b743-3143ac46139e | None        | None      |            | f4ecd970-95f3-4147-a532-2a41b7041dce | f4ecd970-95f3-4147-a532-2a41b7041dce |
| 438565b4-d366-42db-b841-00bab90a6819 | None        | None      |            | None                                 | f4ecd970-95f3-4147-a532-2a41b7041dce |
| 5ebaa40e-1420-4831-802a-97233ab8afee | None        | None      |            | None                                 | 504974ac-4389-4474-bd6b-499cad7de9a4 |
| 9ef85819-9fbc-4f4e-ada3-d085e3935b14 | tcp         | 0.0.0.0/0 | 22:22      | None                                 | 504974ac-4389-4474-bd6b-499cad7de9a4 |
| db32dac3-ee3e-420f-b89e-00156753d68a | icmp        | 0.0.0.0/0 |            | None                                 | 504974ac-4389-4474-bd6b-499cad7de9a4 |
| f92e2d9d-a148-4385-a663-2be35da77ec0 | None        | None      |            | f4ecd970-95f3-4147-a532-2a41b7041dce | f4ecd970-95f3-4147-a532-2a41b7041dce |
| faccd4ae-b26a-4631-92a7-643d07686b21 | None        | None      |            | None                                 | f4ecd970-95f3-4147-a532-2a41b7041dce |
+--------------------------------------+-------------+-----------+------------+--------------------------------------+--------------------------------------+
[3] 起動した仮想マシンインスタンスに SSH ログインします。
[cent@dlp ~(keystone)]$
openstack server list

+--------------------------------------+----------+--------+-----------------------+---------+----------+
| ID                                   | Name     | Status | Networks              | Image   | Flavor   |
+--------------------------------------+----------+--------+-----------------------+---------+----------+
| e07e180f-3622-43f0-8477-01baf16e5267 | CentOS_7 | ACTIVE | sharednet1=10.0.0.228 | CentOS7 | m1.small |
+--------------------------------------+----------+--------+-----------------------+---------+----------+

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

[cent@dlp ~(keystone)]$
ping 10.0.0.228 -c3

PING 10.0.0.228 (10.0.0.228) 56(84) bytes of data.
64 bytes from 10.0.0.228: icmp_seq=1 ttl=64 time=5.12 ms
64 bytes from 10.0.0.228: icmp_seq=2 ttl=64 time=1.04 ms
64 bytes from 10.0.0.228: icmp_seq=3 ttl=64 time=1.58 ms

--- 10.0.0.228 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 1.049/2.588/5.127/1.809 ms

# SSH でログイン

[cent@dlp ~(keystone)]$
ssh centos@10.0.0.228
The authenticity of host '10.0.0.228 (10.0.0.228)' can't be established.
ECDSA key fingerprint is SHA256:a6aknOruK4Or1IjIZbgYgp+IswyON5L7gjQtGpG0SVw.
ECDSA key fingerprint is MD5:1f:b0:09:b7:eb:3b:54:ff:3f:e2:9d:b3:46:20:08:e7.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.228' (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   |
+--------------------------------------+----------+--------+-----------------------+---------+----------+
| e07e180f-3622-43f0-8477-01baf16e5267 | CentOS_7 | ACTIVE | sharednet1=10.0.0.228 | CentOS7 | m1.small |
+--------------------------------------+----------+--------+-----------------------+---------+----------+

# インスタンス停止

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

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

+--------------------------------------+----------+---------+-----------------------+---------+----------+
| ID                                   | Name     | Status  | Networks              | Image   | Flavor   |
+--------------------------------------+----------+---------+-----------------------+---------+----------+
| e07e180f-3622-43f0-8477-01baf16e5267 | CentOS_7 | SHUTOFF | sharednet1=10.0.0.228 | CentOS7 | m1.small |
+--------------------------------------+----------+---------+-----------------------+---------+----------+

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

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

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

+--------------------------------------+----------+--------+-----------------------+---------+----------+
| ID                                   | Name     | Status | Networks              | Image   | Flavor   |
+--------------------------------------+----------+--------+-----------------------+---------+----------+
| e07e180f-3622-43f0-8477-01baf16e5267 | CentOS_7 | ACTIVE | sharednet1=10.0.0.228 | CentOS7 | m1.small |
+--------------------------------------+----------+--------+-----------------------+---------+----------+
[5] VNC コンソールを取得して Web ブラウザでのアクセスも可能です。
[cent@dlp ~(keystone)]$
openstack server list

+--------------------------------------+----------+--------+-----------------------+---------+----------+
| ID                                   | Name     | Status | Networks              | Image   | Flavor   |
+--------------------------------------+----------+--------+-----------------------+---------+----------+
| e07e180f-3622-43f0-8477-01baf16e5267 | CentOS_7 | ACTIVE | sharednet1=10.0.0.228 | 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=d526c701-c3f5-4c24-8396-de53b15d9b3d |
+-------+--------------------------------------------------------------------------------+
[6] 上記コマンドで表示された URL に Web アクセスすると、インスタンスに接続され、操作が可能となります。
関連コンテンツ
 
Tweet