Ubuntu 22.04
Sponsored Link

OpenStack Zed : インスタンスを起動する2022/10/07

 
仮想マシンインスタンスを起動します。
[1] Openstack を利用したい任意のユーザーでログインし、Openstack 認証用の設定ファイルを作成して、仮想マシンインスタンスを作成/起動します。
認証ファイル中のプロジェクト名やユーザー名/パスワードは Keystone に登録したものを指定します
ubuntu@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)\$ '
ubuntu@dlp:~$
chmod 600 ~/keystonerc

ubuntu@dlp:~$
source ~/keystonerc

ubuntu@dlp ~(keystone)$
echo "source ~/keystonerc " >> ~/.bash_profile
# 利用可能な [flavor] 確認

ubuntu@dlp ~(keystone)$
openstack flavor list

+----+----------+------+------+-----------+-------+-----------+
| ID | Name     |  RAM | Disk | Ephemeral | VCPUs | Is Public |
+----+----------+------+------+-----------+-------+-----------+
| 0  | m1.small | 2048 |   10 |         0 |     1 | True      |
+----+----------+------+------+-----------+-------+-----------+

# 利用可能なイメージ確認

ubuntu@dlp ~(keystone)$
openstack image list

+--------------------------------------+------------+--------+
| ID                                   | Name       | Status |
+--------------------------------------+------------+--------+
| 126bc335-fc00-478d-b84a-a9e79eba2574 | Ubuntu2204 | active |
+--------------------------------------+------------+--------+

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

ubuntu@dlp ~(keystone)$
openstack network list

+--------------------------------------+------------+--------------------------------------+
| ID                                   | Name       | Subnets                              |
+--------------------------------------+------------+--------------------------------------+
| 2f087f65-3ecd-4e56-9e44-556a9e3378a2 | sharednet1 | 4e5b97b0-961f-4310-bf6f-07e733db961e |
+--------------------------------------+------------+--------------------------------------+

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

ubuntu@dlp ~(keystone)$
openstack security group create secgroup01

+-----------------+-------------------------------------------------------------------------+
| Field           | Value                                                                   |
+-----------------+-------------------------------------------------------------------------+
| created_at      | 2022-10-07T02:21:20Z                                                    |
| description     | secgroup01                                                              |
| id              | 076d3907-3e28-4b1a-8a72-e61fdbe0ecad                                    |
| name            | secgroup01                                                              |
| project_id      | 4dd1e1f6bac441ff9c77002c3ab4c58a                                        |
| revision_number | 1                                                                       |
| rules           | created_at='2022-10-07T02:21:20Z', direction='egress', ethertype='..... |
|                 | created_at='2022-10-07T02:21:20Z', direction='egress', ethertype='..... |
| stateful        | True                                                                    |
| tags            | []                                                                      |
| updated_at      | 2022-10-07T02:21:20Z                                                    |
+-----------------+-------------------------------------------------------------------------+

ubuntu@dlp ~(keystone)$
openstack security group list

+--------------------------------------+------------+------------------------+----------------------------------+------+
| ID                                   | Name       | Description            | Project                          | Tags |
+--------------------------------------+------------+------------------------+----------------------------------+------+
| 076d3907-3e28-4b1a-8a72-e61fdbe0ecad | secgroup01 | secgroup01             | 4dd1e1f6bac441ff9c77002c3ab4c58a | []   |
| 846a6368-fdbb-43a2-8a80-ef98c00f0f93 | default    | Default security group | 4dd1e1f6bac441ff9c77002c3ab4c58a | []   |
+--------------------------------------+------------+------------------------+----------------------------------+------+

# インスタンス接続用の SSH キーペア作成

ubuntu@dlp ~(keystone)$
ssh-keygen -q -N ""

Enter file in which to save the key (/home/ubuntu/.ssh/id_rsa):
# 公開鍵登録

ubuntu@dlp ~(keystone)$
openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey

+-------------+-------------------------------------------------+
| Field       | Value                                           |
+-------------+-------------------------------------------------+
| created_at  | None                                            |
| fingerprint | d5:5d:67:8b:e1:ae:8e:fc:1b:2e:14:26:4f:89:62:42 |
| id          | mykey                                           |
| is_deleted  | None                                            |
| name        | mykey                                           |
| type        | ssh                                             |
| user_id     | 9345b7f4de21427abf31ad308cf952f8                |
+-------------+-------------------------------------------------+

ubuntu@dlp ~(keystone)$
openstack keypair list

+-------+-------------------------------------------------+------+
| Name  | Fingerprint                                     | Type |
+-------+-------------------------------------------------+------+
| mykey | d5:5d:67:8b:e1:ae:8e:fc:1b:2e:14:26:4f:89:62:42 | ssh  |
+-------+-------------------------------------------------+------+

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

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

ubuntu@dlp ~(keystone)$
openstack server create --flavor m1.small --image Ubuntu2204 --security-group secgroup01 --nic net-id=$netID --key-name mykey Ubuntu-2204
+-----------------------------+---------------------------------------------------+
| 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                   | nPZ5SGDqwuxH                                      |
| config_drive                |                                                   |
| created                     | 2022-10-07T03:27:54Z                              |
| flavor                      | m1.small (0)                                      |
| hostId                      |                                                   |
| id                          | 011f21eb-14c7-446e-8a00-18f3b6424c8a              |
| image                       | Ubuntu2204 (126bc335-fc00-478d-b84a-a9e79eba2574) |
| key_name                    | mykey                                             |
| name                        | Ubuntu-2204                                       |
| progress                    | 0                                                 |
| project_id                  | 4dd1e1f6bac441ff9c77002c3ab4c58a                  |
| properties                  |                                                   |
| security_groups             | name='076d3907-3e28-4b1a-8a72-e61fdbe0ecad'       |
| status                      | BUILD                                             |
| updated                     | 2022-10-07T03:27:54Z                              |
| user_id                     | 9345b7f4de21427abf31ad308cf952f8                  |
| volumes_attached            |                                                   |
+-----------------------------+---------------------------------------------------+

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

ubuntu@dlp ~(keystone)$
openstack server list

+--------------------------------------+-------------+--------+----------+------------+----------+
| ID                                   | Name        | Status | Networks | Image      | Flavor   |
+--------------------------------------+-------------+--------+----------+------------+----------+
| 011f21eb-14c7-446e-8a00-18f3b6424c8a | Ubuntu-2204 | BUILD  |          | Ubuntu2204 | m1.small |
+--------------------------------------+-------------+--------+----------+------------+----------+

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

ubuntu@dlp ~(keystone)$
openstack server list

+--------------------------------------+-------------+--------+-----------------------+------------+----------+
| ID                                   | Name        | Status | Networks              | Image      | Flavor   |
+--------------------------------------+-------------+--------+-----------------------+------------+----------+
| 011f21eb-14c7-446e-8a00-18f3b6424c8a | Ubuntu-2204 | ACTIVE | sharednet1=10.0.0.231 | Ubuntu2204 | m1.small |
+--------------------------------------+-------------+--------+-----------------------+------------+----------+
[2] 起動した仮想マシンインスタンスに SSH 接続できるように、先に作成したセキュリティグループにポート許可の設定を追加します。
# ICMP 許可

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

+-------------------------+--------------------------------------+
| Field                   | Value                                |
+-------------------------+--------------------------------------+
| created_at              | 2022-10-07T03:30:28Z                 |
| description             |                                      |
| direction               | ingress                              |
| ether_type              | IPv4                                 |
| id                      | 4aa72abe-0488-471b-ae1e-3a6ceb59d3dd |
| name                    | None                                 |
| port_range_max          | None                                 |
| port_range_min          | None                                 |
| project_id              | 4dd1e1f6bac441ff9c77002c3ab4c58a     |
| 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       | 076d3907-3e28-4b1a-8a72-e61fdbe0ecad |
| tags                    | []                                   |
| updated_at              | 2022-10-07T03:30:28Z                 |
+-------------------------+--------------------------------------+

# SSH 許可

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

+-------------------------+--------------------------------------+
| Field                   | Value                                |
+-------------------------+--------------------------------------+
| created_at              | 2022-10-07T03:31:17Z                 |
| description             |                                      |
| direction               | ingress                              |
| ether_type              | IPv4                                 |
| id                      | 1c451d33-16f0-4f3f-924c-eb78eb3ca0ca |
| name                    | None                                 |
| port_range_max          | 22                                   |
| port_range_min          | 22                                   |
| project_id              | 4dd1e1f6bac441ff9c77002c3ab4c58a     |
| 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       | 076d3907-3e28-4b1a-8a72-e61fdbe0ecad |
| tags                    | []                                   |
| updated_at              | 2022-10-07T03:31:17Z                 |
+-------------------------+--------------------------------------+

ubuntu@dlp ~(keystone)$
openstack security group rule list secgroup01

+--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+
| ID                                   | IP Protocol | Ethertype | IP Range  | Port Range | Direction | Remote Security Group | Remote Address Group |
+--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+
| 08025712-205a-46bb-97c9-3cd3fe65f617 | None        | IPv6      | ::/0      |            | egress    | None                  | None                 |
| 1c451d33-16f0-4f3f-924c-eb78eb3ca0ca | tcp         | IPv4      | 0.0.0.0/0 | 22:22      | ingress   | None                  | None                 |
| 3e784209-6a4d-4b86-9a14-b40451844ee6 | None        | IPv4      | 0.0.0.0/0 |            | egress    | None                  | None                 |
| 4aa72abe-0488-471b-ae1e-3a6ceb59d3dd | icmp        | IPv4      | 0.0.0.0/0 |            | ingress   | None                  | None                 |
+--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+
[3] 起動した仮想マシンインスタンスに SSH ログインします。
ubuntu@dlp ~(keystone)$
openstack server list

+--------------------------------------+-------------+--------+-----------------------+------------+----------+
| ID                                   | Name        | Status | Networks              | Image      | Flavor   |
+--------------------------------------+-------------+--------+-----------------------+------------+----------+
| 011f21eb-14c7-446e-8a00-18f3b6424c8a | Ubuntu-2204 | ACTIVE | sharednet1=10.0.0.231 | Ubuntu2204 | m1.small |
+--------------------------------------+-------------+--------+-----------------------+------------+----------+

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

ubuntu@dlp ~(keystone)$
ping 10.0.0.231 -c3

PING 10.0.0.231 (10.0.0.231) 56(84) bytes of data.
64 bytes from 10.0.0.231: icmp_seq=1 ttl=64 time=1.40 ms
64 bytes from 10.0.0.231: icmp_seq=2 ttl=64 time=0.596 ms
64 bytes from 10.0.0.231: icmp_seq=3 ttl=64 time=0.452 ms

--- 10.0.0.231 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2032ms
rtt min/avg/max/mdev = 0.452/0.816/1.400/0.417 ms

# SSH でログイン

ubuntu@dlp ~(keystone)$
ssh ubuntu@10.0.0.231
The authenticity of host '10.0.0.231 (10.0.0.231)' can't be established.
ED25519 key fingerprint is SHA256:EVRRkgLha4YBph81zyrVSOKIXzax6oHZol3PVHJRmPg.
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.231' (ED25519) to the list of known hosts.
Welcome to Ubuntu 22.04.1 LTS (GNU/Linux 5.15.0-48-generic x86_64)

.....
.....

To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

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

+--------------------------------------+-------------+--------+-----------------------+------------+----------+
| ID                                   | Name        | Status | Networks              | Image      | Flavor   |
+--------------------------------------+-------------+--------+-----------------------+------------+----------+
| 011f21eb-14c7-446e-8a00-18f3b6424c8a | Ubuntu-2204 | ACTIVE | sharednet1=10.0.0.231 | Ubuntu2204 | m1.small |
+--------------------------------------+-------------+--------+-----------------------+------------+----------+

# インスタンス停止

ubuntu@dlp ~(keystone)$
openstack server stop Ubuntu-2004

ubuntu@dlp ~(keystone)$
openstack server list

+--------------------------------------+-------------+---------+-----------------------+------------+----------+
| ID                                   | Name        | Status  | Networks              | Image      | Flavor   |
+--------------------------------------+-------------+---------+-----------------------+------------+----------+
| 011f21eb-14c7-446e-8a00-18f3b6424c8a | Ubuntu-2204 | SHUTOFF | sharednet1=10.0.0.231 | Ubuntu2204 | m1.small |
+--------------------------------------+-------------+---------+-----------------------+------------+----------+

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

ubuntu@dlp ~(keystone)$
openstack server start Ubuntu-2004

ubuntu@dlp ~(keystone)$
openstack server list

+--------------------------------------+-------------+--------+-----------------------+------------+----------+
| ID                                   | Name        | Status | Networks              | Image      | Flavor   |
+--------------------------------------+-------------+--------+-----------------------+------------+----------+
| 011f21eb-14c7-446e-8a00-18f3b6424c8a | Ubuntu-2204 | ACTIVE | sharednet1=10.0.0.231 | Ubuntu2204 | m1.small |
+--------------------------------------+-------------+--------+-----------------------+------------+----------+
[5] VNC コンソールを取得して Web ブラウザーでのアクセスも可能です。
ubuntu@dlp ~(keystone)$
openstack server list

+--------------------------------------+-------------+--------+-----------------------+------------+----------+
| ID                                   | Name        | Status | Networks              | Image      | Flavor   |
+--------------------------------------+-------------+--------+-----------------------+------------+----------+
| 011f21eb-14c7-446e-8a00-18f3b6424c8a | Ubuntu-2204 | ACTIVE | sharednet1=10.0.0.231 | Ubuntu2204 | m1.small |
+--------------------------------------+-------------+--------+-----------------------+------------+----------+

ubuntu@dlp ~(keystone)$
openstack console url show Ubuntu-2204

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