CentOS Stream 8
Sponsored Link

OpenStack Yoga : インスタンスを起動する2022/05/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=https://dlp.srv.world: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 |
+--------------------------------------+-----------------+--------+
| 7be5b7ab-36e8-43c7-95dd-34b4139a0e44 | CentOS-Stream-8 | active |
+--------------------------------------+-----------------+--------+

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

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

+--------------------------------------+------------+--------------------------------------+
| ID                                   | Name       | Subnets                              |
+--------------------------------------+------------+--------------------------------------+
| ed951532-0b6e-484e-8909-ba20007752c2 | sharednet1 | 863e41c2-48b8-4c27-9846-f00fd486f7e9 |
+--------------------------------------+------------+--------------------------------------+

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

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

+-----------------+----------------------------------------------------------------------------+
| Field           | Value                                                                      |
+-----------------+----------------------------------------------------------------------------+
| created_at      | 2022-05-31T05:04:14Z                                                       |
| description     | secgroup01                                                                 |
| id              | 86d9d627-fd49-490a-b0da-02ef925566fb                                       |
| name            | secgroup01                                                                 |
| project_id      | 3d85d1e79d654b3dade01eb5bfbf0679                                           |
| revision_number | 1                                                                          |
| rules           | created_at='2022-05-31T05:04:14Z', direction='egress', ethertype='IPv..... |
|                 | created_at='2022-05-31T05:04:14Z', direction='egress', ethertype='IPv..... |
| stateful        | True                                                                       |
| tags            | []                                                                         |
| updated_at      | 2022-05-31T05:04:14Z                                                       |
+-----------------+----------------------------------------------------------------------------+

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

+--------------------------------------+------------+------------------------+----------------------------------+------+
| ID                                   | Name       | Description            | Project                          | Tags |
+--------------------------------------+------------+------------------------+----------------------------------+------+
| 4e46aafd-178b-4476-8d4f-7e5bf0ef2599 | default    | Default security group | 3d85d1e79d654b3dade01eb5bfbf0679 | []   |
| 86d9d627-fd49-490a-b0da-02ef925566fb | secgroup01 | secgroup01             | 3d85d1e79d654b3dade01eb5bfbf0679 | []   |
+--------------------------------------+------------+------------------------+----------------------------------+------+

# インスタンス接続用の 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 | 00:74:cd:5c:68:56:f0:b6:f4:c4:de:e5:65:fd:ef:f8 |
| id          | mykey                                           |
| is_deleted  | None                                            |
| name        | mykey                                           |
| type        | ssh                                             |
| user_id     | ed0bc393ae81411fa1db0828e1d5e160                |
+-------------+-------------------------------------------------+

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

+-------+-------------------------------------------------+------+
| Name  | Fingerprint                                     | Type |
+-------+-------------------------------------------------+------+
| mykey | 00:74:cd:5c:68:56:f0:b6:f4:c4:de:e5:65:fd:ef:f8 | 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-St8
+-----------------------------+--------------------------------------------------------+
| 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                   | TsM2BcxzQ2gy                                           |
| config_drive                |                                                        |
| created                     | 2022-05-31T05:07:10Z                                   |
| flavor                      | m1.small (0)                                           |
| hostId                      |                                                        |
| id                          | d94d7fce-1321-45f7-b6a7-a2c03c5f8646                   |
| image                       | CentOS-Stream-8 (7be5b7ab-36e8-43c7-95dd-34b4139a0e44) |
| key_name                    | mykey                                                  |
| name                        | CentOS-St8                                             |
| progress                    | 0                                                      |
| project_id                  | 3d85d1e79d654b3dade01eb5bfbf0679                       |
| properties                  |                                                        |
| security_groups             | name='86d9d627-fd49-490a-b0da-02ef925566fb'            |
| status                      | BUILD                                                  |
| updated                     | 2022-05-31T05:07:10Z                                   |
| user_id                     | ed0bc393ae81411fa1db0828e1d5e160                       |
| volumes_attached            |                                                        |
+-----------------------------+--------------------------------------------------------+

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

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

+--------------------------------------+------------+--------+----------+-----------------+----------+
| ID                                   | Name       | Status | Networks | Image           | Flavor   |
+--------------------------------------+------------+--------+----------+-----------------+----------+
| d94d7fce-1321-45f7-b6a7-a2c03c5f8646 | CentOS-St8 | BUILD  |          | CentOS-Stream-8 | m1.small |
+--------------------------------------+------------+--------+----------+-----------------+----------+

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

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

+--------------------------------------+------------+--------+-----------------------+-----------------+----------+
| ID                                   | Name       | Status | Networks              | Image           | Flavor   |
+--------------------------------------+------------+--------+-----------------------+-----------------+----------+
| d94d7fce-1321-45f7-b6a7-a2c03c5f8646 | CentOS-St8 | ACTIVE | sharednet1=10.0.0.202 | CentOS-Stream-8 | m1.small |
+--------------------------------------+------------+--------+-----------------------+-----------------+----------+
[2] 起動した仮想マシンインスタンスに SSH 接続できるように、先に作成したセキュリティグループにポート許可の設定を追加します。
# ICMP 許可

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

+-------------------------+--------------------------------------+
| Field                   | Value                                |
+-------------------------+--------------------------------------+
| created_at              | 2022-05-31T05:08:29Z                 |
| description             |                                      |
| direction               | ingress                              |
| ether_type              | IPv4                                 |
| id                      | 2da9b1af-ef5e-40e5-9411-89f59001bec5 |
| name                    | None                                 |
| port_range_max          | None                                 |
| port_range_min          | None                                 |
| project_id              | 3d85d1e79d654b3dade01eb5bfbf0679     |
| 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       | 86d9d627-fd49-490a-b0da-02ef925566fb |
| tags                    | []                                   |
| tenant_id               | 3d85d1e79d654b3dade01eb5bfbf0679     |
| updated_at              | 2022-05-31T05:08:29Z                 |
+-------------------------+--------------------------------------+

# SSH 許可

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

+-------------------------+--------------------------------------+
| Field                   | Value                                |
+-------------------------+--------------------------------------+
| created_at              | 2022-05-31T05:08:43Z                 |
| description             |                                      |
| direction               | ingress                              |
| ether_type              | IPv4                                 |
| id                      | 31ca1b95-ddb8-475d-8086-e235470f6d94 |
| name                    | None                                 |
| port_range_max          | 22                                   |
| port_range_min          | 22                                   |
| project_id              | 3d85d1e79d654b3dade01eb5bfbf0679     |
| 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       | 86d9d627-fd49-490a-b0da-02ef925566fb |
| tags                    | []                                   |
| tenant_id               | 3d85d1e79d654b3dade01eb5bfbf0679     |
| updated_at              | 2022-05-31T05:08:43Z                 |
+-------------------------+--------------------------------------+

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

+--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+
| ID                                   | IP Protocol | Ethertype | IP Range  | Port Range | Direction | Remote Security Group | Remote Address Group |
+--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+
| 2da9b1af-ef5e-40e5-9411-89f59001bec5 | icmp        | IPv4      | 0.0.0.0/0 |            | ingress   | None                  | None                 |
| 31ca1b95-ddb8-475d-8086-e235470f6d94 | tcp         | IPv4      | 0.0.0.0/0 | 22:22      | ingress   | None                  | None                 |
| 4a7149f0-ae95-462a-83a0-e58c77078e44 | None        | IPv6      | ::/0      |            | egress    | None                  | None                 |
| 81c3b639-dead-4728-9a29-d66ed3deb9bf | None        | IPv4      | 0.0.0.0/0 |            | egress    | None                  | None                 |
+--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+
[3] 起動した仮想マシンインスタンスに SSH ログインします。
[cent@dlp ~(keystone)]$
openstack server list

+--------------------------------------+------------+--------+-----------------------+-----------------+----------+
| ID                                   | Name       | Status | Networks              | Image           | Flavor   |
+--------------------------------------+------------+--------+-----------------------+-----------------+----------+
| d94d7fce-1321-45f7-b6a7-a2c03c5f8646 | CentOS-St8 | ACTIVE | sharednet1=10.0.0.202 | CentOS-Stream-8 | 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=2.37 ms
64 bytes from 10.0.0.202: icmp_seq=2 ttl=64 time=1.03 ms
64 bytes from 10.0.0.202: icmp_seq=3 ttl=64 time=0.885 ms

--- 10.0.0.202 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 0.885/1.428/2.370/0.669 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:KLqoS54PfUBeH+H97tXUROOHgYz/O+aY9+lqc081yyk.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.0.0.202' (ECDSA) to the list of known hosts.
Activate the web console with: systemctl enable --now cockpit.socket

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

+--------------------------------------+------------+--------+-----------------------+-----------------+----------+
| ID                                   | Name       | Status | Networks              | Image           | Flavor   |
+--------------------------------------+------------+--------+-----------------------+-----------------+----------+
| d94d7fce-1321-45f7-b6a7-a2c03c5f8646 | CentOS-St8 | ACTIVE | sharednet1=10.0.0.202 | CentOS-Stream-8 | m1.small |
+--------------------------------------+------------+--------+-----------------------+-----------------+----------+

# インスタンス停止

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

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

+--------------------------------------+------------+---------+-----------------------+-----------------+----------+
| ID                                   | Name       | Status  | Networks              | Image           | Flavor   |
+--------------------------------------+------------+---------+-----------------------+-----------------+----------+
| d94d7fce-1321-45f7-b6a7-a2c03c5f8646 | CentOS-St8 | SHUTOFF | sharednet1=10.0.0.202 | CentOS-Stream-8 | m1.small |
+--------------------------------------+------------+---------+-----------------------+-----------------+----------+

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

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

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

+--------------------------------------+------------+--------+-----------------------+-----------------+----------+
| ID                                   | Name       | Status | Networks              | Image           | Flavor   |
+--------------------------------------+------------+--------+-----------------------+-----------------+----------+
| d94d7fce-1321-45f7-b6a7-a2c03c5f8646 | CentOS-St8 | ACTIVE | sharednet1=10.0.0.202 | CentOS-Stream-8 | m1.small |
+--------------------------------------+------------+--------+-----------------------+-----------------+----------+
[5] VNC コンソールを取得して Web ブラウザーでのアクセスも可能です。
[cent@dlp ~(keystone)]$
openstack server list

+--------------------------------------+------------+--------+-----------------------+-----------------+----------+
| ID                                   | Name       | Status | Networks              | Image           | Flavor   |
+--------------------------------------+------------+--------+-----------------------+-----------------+----------+
| d94d7fce-1321-45f7-b6a7-a2c03c5f8646 | CentOS-St8 | ACTIVE | sharednet1=10.0.0.202 | CentOS-Stream-8 | m1.small |
+--------------------------------------+------------+--------+-----------------------+-----------------+----------+

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

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