CentOS Stream 8
Sponsored Link

OpenStack Xena : インスタンスを起動する2021/11/22

 
仮想マシンインスタンスを起動します。
[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 |
+--------------------------------------+-----------------+--------+
| cfce605e-151b-43dd-b743-2c7988d69e96 | CentOS-Stream-8 | active |
+--------------------------------------+-----------------+--------+

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

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

+--------------------------------------+------------+--------------------------------------+
| ID                                   | Name       | Subnets                              |
+--------------------------------------+------------+--------------------------------------+
| e2ac29e8-55e4-4111-8a2f-14e250288440 | sharednet1 | 0918f78c-3a45-485f-834f-93d1e9982a40 |
+--------------------------------------+------------+--------------------------------------+

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

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

+-----------------+---------------------------------------------------------------------------+
| Field           | Value                                                                     |
+-----------------+---------------------------------------------------------------------------+
| created_at      | 2021-11-22T03:50:24Z                                                      |
| description     | secgroup01                                                                |
| id              | ea02f1bb-3244-4465-bd45-21ea7024d901                                      |
| name            | secgroup01                                                                |
| project_id      | 2decda8bcd724687a1cf05064ab21fdf                                          |
| revision_number | 1                                                                         |
| rules           | created_at='2021-11-22T03:50:24Z', direction='egress', ethertype='IPv6... |
|                 | created_at='2021-11-22T03:50:24Z', direction='egress', ethertype='IPv4... |
| stateful        | True                                                                      |
| tags            | []                                                                        |
| updated_at      | 2021-11-22T03:50:24Z                                                      |
+-----------------+---------------------------------------------------------------------------+

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

+--------------------------------------+------------+------------------------+----------------------------------+------+
| ID                                   | Name       | Description            | Project                          | Tags |
+--------------------------------------+------------+------------------------+----------------------------------+------+
| 8e8803dd-42be-45c5-8070-533b6f4e7f47 | default    | Default security group | 2decda8bcd724687a1cf05064ab21fdf | []   |
| ea02f1bb-3244-4465-bd45-21ea7024d901 | secgroup01 | secgroup01             | 2decda8bcd724687a1cf05064ab21fdf | []   |
+--------------------------------------+------------+------------------------+----------------------------------+------+

# インスタンス接続用の 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                                           |
+-------------+-------------------------------------------------+
| created_at  | None                                            |
| fingerprint | 1f:1e:c1:75:27:6e:5d:6f:ef:f5:01:3b:d2:31:2b:a4 |
| id          | mykey                                           |
| is_deleted  | None                                            |
| name        | mykey                                           |
| type        | ssh                                             |
| user_id     | 6a517543654044e8b4ea9e0eea0adaa4                |
+-------------+-------------------------------------------------+

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

+-------+-------------------------------------------------+------+
| Name  | Fingerprint                                     | Type |
+-------+-------------------------------------------------+------+
| mykey | 1f:1e:c1:75:27:6e:5d:6f:ef:f5:01:3b:d2:31:2b:a4 | ssh  |
+-------+-------------------------------------------------+------+

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

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

[cent@dlp ~(keystone)]$
openstack server create --flavor m1.small --image CentOS-Stream-8 --security-group secgroup01 --nic net-id=$netID --key-name mykey CentOS-St-8
+-----------------------------+--------------------------------------------------------+
| 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                   | CHF6Cfp4SHnB                                           |
| config_drive                |                                                        |
| created                     | 2021-11-22T03:52:35Z                                   |
| flavor                      | m1.small (0)                                           |
| hostId                      |                                                        |
| id                          | 892c46a7-0472-44b9-95d0-b81273129caf                   |
| image                       | CentOS-Stream-8 (cfce605e-151b-43dd-b743-2c7988d69e96) |
| key_name                    | mykey                                                  |
| name                        | CentOS-St-8                                            |
| progress                    | 0                                                      |
| project_id                  | 2decda8bcd724687a1cf05064ab21fdf                       |
| properties                  |                                                        |
| security_groups             | name='ea02f1bb-3244-4465-bd45-21ea7024d901'            |
| status                      | BUILD                                                  |
| updated                     | 2021-11-22T03:52:35Z                                   |
| user_id                     | 6a517543654044e8b4ea9e0eea0adaa4                       |
| volumes_attached            |                                                        |
+-----------------------------+--------------------------------------------------------+

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

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

+--------------------------------------+-------------+--------+----------+-----------------+----------+
| ID                                   | Name        | Status | Networks | Image           | Flavor   |
+--------------------------------------+-------------+--------+----------+-----------------+----------+
| 892c46a7-0472-44b9-95d0-b81273129caf | CentOS-St-8 | BUILD  |          | CentOS-Stream-8 | m1.small |
+--------------------------------------+-------------+--------+----------+-----------------+----------+

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

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

+--------------------------------------+-------------+--------+-----------------------+-----------------+----------+
| ID                                   | Name        | Status | Networks              | Image           | Flavor   |
+--------------------------------------+-------------+--------+-----------------------+-----------------+----------+
| 892c46a7-0472-44b9-95d0-b81273129caf | CentOS-St-8 | ACTIVE | sharednet1=10.0.0.219 | CentOS-Stream-8 | m1.small |
+--------------------------------------+-------------+--------+-----------------------+-----------------+----------+
[2] 起動した仮想マシンインスタンスに SSH 接続できるように、先に作成したセキュリティグループにポート許可の設定を追加します。
# ICMP 許可

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

+-------------------------+--------------------------------------+
| Field                   | Value                                |
+-------------------------+--------------------------------------+
| created_at              | 2021-11-22T03:53:50Z                 |
| description             |                                      |
| direction               | ingress                              |
| ether_type              | IPv4                                 |
| id                      | 154172ea-e18c-44e8-90b2-eda7a665cd54 |
| name                    | None                                 |
| port_range_max          | None                                 |
| port_range_min          | None                                 |
| project_id              | 2decda8bcd724687a1cf05064ab21fdf     |
| protocol                | icmp                                 |
| remote_address_group_id | None                                 |
| remote_group_id         | None                                 |
| remote_ip_prefix        | 0.0.0.0/0                            |
| revision_number         | 0                                    |
| security_group_id       | ea02f1bb-3244-4465-bd45-21ea7024d901 |
| tags                    | []                                   |
| updated_at              | 2021-11-22T03:53:50Z                 |
+-------------------------+--------------------------------------+

# SSH 許可

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

+-------------------------+--------------------------------------+
| Field                   | Value                                |
+-------------------------+--------------------------------------+
| created_at              | 2021-11-22T03:54:03Z                 |
| description             |                                      |
| direction               | ingress                              |
| ether_type              | IPv4                                 |
| id                      | ac473670-1693-405e-9eca-70b1b20465ec |
| name                    | None                                 |
| port_range_max          | 22                                   |
| port_range_min          | 22                                   |
| project_id              | 2decda8bcd724687a1cf05064ab21fdf     |
| protocol                | tcp                                  |
| remote_address_group_id | None                                 |
| remote_group_id         | None                                 |
| remote_ip_prefix        | 0.0.0.0/0                            |
| revision_number         | 0                                    |
| security_group_id       | ea02f1bb-3244-4465-bd45-21ea7024d901 |
| tags                    | []                                   |
| updated_at              | 2021-11-22T03:54:03Z                 |
+-------------------------+--------------------------------------+

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

+--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+
| ID                                   | IP Protocol | Ethertype | IP Range  | Port Range | Direction | Remote Security Group | Remote Address Group |
+--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+
| 154172ea-e18c-44e8-90b2-eda7a665cd54 | icmp        | IPv4      | 0.0.0.0/0 |            | ingress   | None                  | None                 |
| 5add4ebf-3d5d-4a79-a017-ffa7d6c24610 | None        | IPv6      | ::/0      |            | egress    | None                  | None                 |
| 7bc37284-d2f5-486f-8d70-8d0c44c8d1af | None        | IPv4      | 0.0.0.0/0 |            | egress    | None                  | None                 |
| ac473670-1693-405e-9eca-70b1b20465ec | tcp         | IPv4      | 0.0.0.0/0 | 22:22      | ingress   | None                  | None                 |
+--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+
[3] 起動した仮想マシンインスタンスに SSH ログインします。
[cent@dlp ~(keystone)]$
openstack server list

+--------------------------------------+-------------+--------+-----------------------+-----------------+----------+
| ID                                   | Name        | Status | Networks              | Image           | Flavor   |
+--------------------------------------+-------------+--------+-----------------------+-----------------+----------+
| 892c46a7-0472-44b9-95d0-b81273129caf | CentOS-St-8 | ACTIVE | sharednet1=10.0.0.219 | CentOS-Stream-8 | m1.small |
+--------------------------------------+-------------+--------+-----------------------+-----------------+----------+

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

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

PING 10.0.0.219 (10.0.0.219) 56(84) bytes of data.
64 bytes from 10.0.0.219: icmp_seq=1 ttl=64 time=1.58 ms
64 bytes from 10.0.0.219: icmp_seq=2 ttl=64 time=0.789 ms
64 bytes from 10.0.0.219: icmp_seq=3 ttl=64 time=0.637 ms

--- 10.0.0.219 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 0.637/1.002/1.580/0.413 ms

# SSH でログイン

[cent@dlp ~(keystone)]$
ssh centos@10.0.0.219
The authenticity of host '10.0.0.219 (10.0.0.219)' can't be established.
ECDSA key fingerprint is SHA256:3gLFosEgnUDvIjrOiWL+J17ZA8vor0cu45t8Ea/VR5Q.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.0.0.219' (ECDSA) to the list of known hosts.
Activate the web console with: systemctl enable --now cockpit.socket

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

+--------------------------------------+-------------+--------+-----------------------+-----------------+----------+
| ID                                   | Name        | Status | Networks              | Image           | Flavor   |
+--------------------------------------+-------------+--------+-----------------------+-----------------+----------+
| 892c46a7-0472-44b9-95d0-b81273129caf | CentOS-St-8 | ACTIVE | sharednet1=10.0.0.219 | CentOS-Stream-8 | m1.small |
+--------------------------------------+-------------+--------+-----------------------+-----------------+----------+

# インスタンス停止

[cent@dlp ~(keystone)]$
openstack server stop CentOS-St-8

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

+--------------------------------------+-------------+---------+-----------------------+-----------------+----------+
| ID                                   | Name        | Status  | Networks              | Image           | Flavor   |
+--------------------------------------+-------------+---------+-----------------------+-----------------+----------+
| 892c46a7-0472-44b9-95d0-b81273129caf | CentOS-St-8 | SHUTOFF | sharednet1=10.0.0.219 | CentOS-Stream-8 | m1.small |
+--------------------------------------+-------------+---------+-----------------------+-----------------+----------+

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

[cent@dlp ~(keystone)]$
openstack server start CentOS-St-8

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

+--------------------------------------+-------------+--------+-----------------------+-----------------+----------+
| ID                                   | Name        | Status | Networks              | Image           | Flavor   |
+--------------------------------------+-------------+--------+-----------------------+-----------------+----------+
| 892c46a7-0472-44b9-95d0-b81273129caf | CentOS-St-8 | ACTIVE | sharednet1=10.0.0.219 | CentOS-Stream-8 | m1.small |
+--------------------------------------+-------------+--------+-----------------------+-----------------+----------+
[5] VNC コンソールを取得して Web ブラウザーでのアクセスも可能です。
[cent@dlp ~(keystone)]$
openstack server list

+--------------------------------------+-------------+--------+-----------------------+-----------------+----------+
| ID                                   | Name        | Status | Networks              | Image           | Flavor   |
+--------------------------------------+-------------+--------+-----------------------+-----------------+----------+
| 892c46a7-0472-44b9-95d0-b81273129caf | CentOS-St-8 | ACTIVE | sharednet1=10.0.0.219 | CentOS-Stream-8 | m1.small |
+--------------------------------------+-------------+--------+-----------------------+-----------------+----------+

[cent@dlp ~(keystone)]$
openstack console url show CentOS-St-8

+----------+------------------------------------------------------------------------------------------+
| Field    | Value                                                                                    |
+----------+------------------------------------------------------------------------------------------+
| protocol | vnc                                                                                      |
| type     | novnc                                                                                    |
| url      | http://10.0.0.30:6080/vnc_auto.html?path=%3Ftoken%3Dfc6e596b-3aa1-4168-bee2-d1f5e117b2e2 |
+----------+------------------------------------------------------------------------------------------+
[6] 上記コマンドで表示された URL に Web アクセスすると、インスタンスに接続され、操作が可能となります。
関連コンテンツ