CentOS Stream 9
Sponsored Link

OpenStack Yoga : インスタンスを起動する2022/06/09

 
仮想マシンインスタンスを起動します。
[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 |
+--------------------------------------+----------------+--------+
| 1044ab46-c42b-4cf6-ab1f-aaeb011fb3b9 | CentOS-Stream9 | active |
+--------------------------------------+----------------+--------+

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

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

+--------------------------------------+------------+--------------------------------------+
| ID                                   | Name       | Subnets                              |
+--------------------------------------+------------+--------------------------------------+
| 93b750c0-06e2-496e-a619-cfe98bf5ac4f | sharednet1 | 091c5237-b632-4a63-a1a2-58f100c60416 |
+--------------------------------------+------------+--------------------------------------+

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

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

+-----------------+------------------------------------------------------------------------------+
| Field           | Value                                                                        |
+-----------------+------------------------------------------------------------------------------+
| created_at      | 2022-06-09T00:44:56Z                                                         |
| description     | secgroup01                                                                   |
| id              | 31b313e0-f26a-4b07-98a3-b0135d95f006                                         |
| name            | secgroup01                                                                   |
| project_id      | 911e5ff7686741c782d6acc6d7155db1                                             |
| revision_number | 1                                                                            |
| rules           | created_at='2022-06-09T00:44:56Z', direction='egress', ethertype='IPv6'..... |
|                 | created_at='2022-06-09T00:44:56Z', direction='egress', ethertype='IPv4'..... |
| stateful        | True                                                                         |
| tags            | []                                                                           |
| updated_at      | 2022-06-09T00:44:56Z                                                         |
+-----------------+------------------------------------------------------------------------------+

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

+--------------------------------------+------------+------------------------+----------------------------------+------+
| ID                                   | Name       | Description            | Project                          | Tags |
+--------------------------------------+------------+------------------------+----------------------------------+------+
| 31b313e0-f26a-4b07-98a3-b0135d95f006 | secgroup01 | secgroup01             | 911e5ff7686741c782d6acc6d7155db1 | []   |
| 743724ee-7033-4c0e-a833-be391619f39a | default    | Default security group | 911e5ff7686741c782d6acc6d7155db1 | []   |
+--------------------------------------+------------+------------------------+----------------------------------+------+

# インスタンス接続用の 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 | cc:37:b7:c0:72:56:3e:66:71:f8:b1:59:72:c6:88:57 |
| id          | mykey                                           |
| is_deleted  | None                                            |
| name        | mykey                                           |
| type        | ssh                                             |
| user_id     | 1ff4591a7f8140fcad38fd9f606a66a6                |
+-------------+-------------------------------------------------+

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

+-------+-------------------------------------------------+------+
| Name  | Fingerprint                                     | Type |
+-------+-------------------------------------------------+------+
| mykey | cc:37:b7:c0:72:56:3e:66:71:f8:b1:59:72:c6:88:57 | ssh  |
+-------+-------------------------------------------------+------+

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

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

[cent@dlp ~(keystone)]$
openstack server create --flavor m1.small --image CentOS-Stream9 --security-group secgroup01 --nic net-id=$netID --key-name mykey CentOS-St9
+-----------------------------+-------------------------------------------------------+
| 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                   | V8UBAjTqic5d                                          |
| config_drive                |                                                       |
| created                     | 2022-06-09T00:47:42Z                                  |
| flavor                      | m1.small (0)                                          |
| hostId                      |                                                       |
| id                          | 2799cc3a-affb-42d1-b48e-59f3e49a9902                  |
| image                       | CentOS-Stream9 (1044ab46-c42b-4cf6-ab1f-aaeb011fb3b9) |
| key_name                    | mykey                                                 |
| name                        | CentOS-St9                                            |
| progress                    | 0                                                     |
| project_id                  | 911e5ff7686741c782d6acc6d7155db1                      |
| properties                  |                                                       |
| security_groups             | name='31b313e0-f26a-4b07-98a3-b0135d95f006'           |
| status                      | BUILD                                                 |
| updated                     | 2022-06-09T00:47:43Z                                  |
| user_id                     | 1ff4591a7f8140fcad38fd9f606a66a6                      |
| volumes_attached            |                                                       |
+-----------------------------+-------------------------------------------------------+

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

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

+--------------------------------------+------------+--------+----------+----------------+----------+
| ID                                   | Name       | Status | Networks | Image          | Flavor   |
+--------------------------------------+------------+--------+----------+----------------+----------+
| 2799cc3a-affb-42d1-b48e-59f3e49a9902 | CentOS-St9 | BUILD  |          | CentOS-Stream9 | m1.small |
+--------------------------------------+------------+--------+----------+----------------+----------+

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

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

+--------------------------------------+------------+--------+-----------------------+----------------+----------+
| ID                                   | Name       | Status | Networks              | Image          | Flavor   |
+--------------------------------------+------------+--------+-----------------------+----------------+----------+
| 2799cc3a-affb-42d1-b48e-59f3e49a9902 | CentOS-St9 | ACTIVE | sharednet1=10.0.0.253 | CentOS-Stream9 | m1.small |
+--------------------------------------+------------+--------+-----------------------+----------------+----------+
[2] 起動した仮想マシンインスタンスに SSH 接続できるように、先に作成したセキュリティグループにポート許可の設定を追加します。
# ICMP 許可

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

+-------------------------+--------------------------------------+
| Field                   | Value                                |
+-------------------------+--------------------------------------+
| created_at              | 2022-06-09T00:49:04Z                 |
| description             |                                      |
| direction               | ingress                              |
| ether_type              | IPv4                                 |
| id                      | 89a8f669-789b-44d5-ba04-1df850bb7637 |
| name                    | None                                 |
| port_range_max          | None                                 |
| port_range_min          | None                                 |
| project_id              | 911e5ff7686741c782d6acc6d7155db1     |
| 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       | 31b313e0-f26a-4b07-98a3-b0135d95f006 |
| tags                    | []                                   |
| tenant_id               | 911e5ff7686741c782d6acc6d7155db1     |
| updated_at              | 2022-06-09T00:49:04Z                 |
+-------------------------+--------------------------------------+

# SSH 許可

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

+-------------------------+--------------------------------------+
| Field                   | Value                                |
+-------------------------+--------------------------------------+
| created_at              | 2022-06-09T00:49:31Z                 |
| description             |                                      |
| direction               | ingress                              |
| ether_type              | IPv4                                 |
| id                      | 9fe9c938-a281-42bf-9798-61288280845b |
| name                    | None                                 |
| port_range_max          | 22                                   |
| port_range_min          | 22                                   |
| project_id              | 911e5ff7686741c782d6acc6d7155db1     |
| 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       | 31b313e0-f26a-4b07-98a3-b0135d95f006 |
| tags                    | []                                   |
| tenant_id               | 911e5ff7686741c782d6acc6d7155db1     |
| updated_at              | 2022-06-09T00:49:31Z                 |
+-------------------------+--------------------------------------+

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

+--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+
| ID                                   | IP Protocol | Ethertype | IP Range  | Port Range | Direction | Remote Security Group | Remote Address Group |
+--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+
| 02d6b78e-3ed6-4699-8680-595a3296f3a0 | None        | IPv6      | ::/0      |            | egress    | None                  | None                 |
| 0f15d3d5-7e35-451f-9bdb-57a45c3c9e3c | None        | IPv4      | 0.0.0.0/0 |            | egress    | None                  | None                 |
| 89a8f669-789b-44d5-ba04-1df850bb7637 | icmp        | IPv4      | 0.0.0.0/0 |            | ingress   | None                  | None                 |
| 9fe9c938-a281-42bf-9798-61288280845b | 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   |
+--------------------------------------+------------+--------+-----------------------+----------------+----------+
| 2799cc3a-affb-42d1-b48e-59f3e49a9902 | CentOS-St9 | ACTIVE | sharednet1=10.0.0.253 | CentOS-Stream9 | m1.small |
+--------------------------------------+------------+--------+-----------------------+----------------+----------+

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

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

PING 10.0.0.253 (10.0.0.253) 56(84) bytes of data.
64 bytes from 10.0.0.253: icmp_seq=1 ttl=64 time=2.78 ms
64 bytes from 10.0.0.253: icmp_seq=2 ttl=64 time=0.951 ms
64 bytes from 10.0.0.253: icmp_seq=3 ttl=64 time=0.660 ms

--- 10.0.0.253 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 0.660/1.465/2.784/0.940 ms

# SSH でログイン

[cent@dlp ~(keystone)]$
ssh centos@10.0.0.253
The authenticity of host '10.0.0.253 (10.0.0.253)' can't be established.
ED25519 key fingerprint is SHA256:WG+DnlFIAvQSJ3dQnVlNuCb4Fupvbuc+F+D/Z7Al+30.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.0.0.253' (ED25519) to the list of known hosts.
[centos@centos-st9 ~]$     # ログインできた
[4] 一旦作成して起動した仮想マシンインスタンスを停止/起動する場合は、以下のように [start/stop] コマンドで制御できます。
[cent@dlp ~(keystone)]$
openstack server list

+--------------------------------------+------------+--------+-----------------------+----------------+----------+
| ID                                   | Name       | Status | Networks              | Image          | Flavor   |
+--------------------------------------+------------+--------+-----------------------+----------------+----------+
| 2799cc3a-affb-42d1-b48e-59f3e49a9902 | CentOS-St9 | ACTIVE | sharednet1=10.0.0.253 | CentOS-Stream9 | m1.small |
+--------------------------------------+------------+--------+-----------------------+----------------+----------+

# インスタンス停止

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

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

+--------------------------------------+------------+---------+-----------------------+----------------+----------+
| ID                                   | Name       | Status  | Networks              | Image          | Flavor   |
+--------------------------------------+------------+--------+-----------------------+----------------+----------+
| 2799cc3a-affb-42d1-b48e-59f3e49a9902 | CentOS-St9 | SHUTOFF | sharednet1=10.0.0.253 | CentOS-Stream9 | m1.small |
+--------------------------------------+------------+---------+-----------------------+----------------+----------+

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

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

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

+--------------------------------------+------------+--------+-----------------------+----------------+----------+
| ID                                   | Name       | Status | Networks              | Image          | Flavor   |
+--------------------------------------+------------+--------+-----------------------+----------------+----------+
| 2799cc3a-affb-42d1-b48e-59f3e49a9902 | CentOS-St9 | ACTIVE | sharednet1=10.0.0.253 | CentOS-Stream9 | m1.small |
+--------------------------------------+------------+--------+-----------------------+----------------+----------+
[5] VNC コンソールを取得して Web ブラウザーでのアクセスも可能です。
[cent@dlp ~(keystone)]$
openstack server list

+--------------------------------------+------------+--------+-----------------------+----------------+----------+
| ID                                   | Name       | Status | Networks              | Image          | Flavor   |
+--------------------------------------+------------+--------+-----------------------+----------------+----------+
| 2799cc3a-affb-42d1-b48e-59f3e49a9902 | CentOS-St9 | ACTIVE | sharednet1=10.0.0.253 | CentOS-Stream9 | m1.small |
+--------------------------------------+------------+--------+-----------------------+----------------+----------+

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

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