OpenStack Antelope : インスタンスを起動する2023/04/14 |
仮想マシンインスタンスを起動します。
|
|
[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 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 | +----+-----------+------+------+-----------+-------+-----------+ | 1 | m1.small | 2048 | 10 | 0 | 1 | True | | 2 | m1.medium | 4096 | 10 | 0 | 2 | True | | 3 | m1.large | 8192 | 20 | 0 | 4 | True | +----+-----------+------+------+-----------+-------+-----------+ # 利用可能なイメージ確認 [cent@dlp ~(keystone)]$ openstack image list +--------------------------------------+----------------+--------+ | ID | Name | Status | +--------------------------------------+----------------+--------+ | 6afab1f1-c2e0-42c5-9c86-659f56174b9d | CentOS-Stream9 | active | +--------------------------------------+----------------+--------+ # 利用可能なネットワーク確認 [cent@dlp ~(keystone)]$ openstack network list +--------------------------------------+------------+--------------------------------------+ | ID | Name | Subnets | +--------------------------------------+------------+--------------------------------------+ | b176d051-6a33-4b77-9cfd-13d86b51f657 | sharednet1 | 0a491127-28f7-4c9c-b7d3-8b8f449912a0 | +--------------------------------------+------------+--------------------------------------+ # インスタンス用のセキュリティグループを作成 [cent@dlp ~(keystone)]$ openstack security group create secgroup01 +-----------------+--------------------------------------------------------------------------------+ | Field | Value | +-----------------+--------------------------------------------------------------------------------+ | created_at | 2023-04-14T02:22:35Z | | description | secgroup01 | | id | c761c71b-265d-4802-9c7d-0b85e0680e06 | | name | secgroup01 | | project_id | 17b52bb0db9440549d400290cec02c1d | | revision_number | 1 | | rules | created_at='2023-04-14T02:22:35Z', direction='egress', ethertype='IPv6', ..... | | | created_at='2023-04-14T02:22:35Z', direction='egress', ethertype='IPv4', ..... | | shared | False | | stateful | True | | tags | [] | | updated_at | 2023-04-14T02:22:35Z | +-----------------+--------------------------------------------------------------------------------+[cent@dlp ~(keystone)]$ openstack security group list +--------------------------------------+------------+------------------------+----------------------------------+------+ | ID | Name | Description | Project | Tags | +--------------------------------------+------------+------------------------+----------------------------------+------+ | 340b7b87-9f3f-430c-8f22-267d1c663865 | default | Default security group | 17b52bb0db9440549d400290cec02c1d | [] | | c761c71b-265d-4802-9c7d-0b85e0680e06 | secgroup01 | secgroup01 | 17b52bb0db9440549d400290cec02c1d | [] | +--------------------------------------+------------+------------------------+----------------------------------+------+ # インスタンス接続用の 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 | 4c:9c:17:be:f5:e0:ea:db:fc:ec:29:e3:ca:20:1e:cb | | id | mykey | | is_deleted | None | | name | mykey | | type | ssh | | user_id | 1ed6032943cb4e5d907371a20adae1c0 | +-------------+-------------------------------------------------+[cent@dlp ~(keystone)]$ openstack keypair list +-------+-------------------------------------------------+------+ | Name | Fingerprint | Type | +-------+-------------------------------------------------+------+ | mykey | 4c:9c:17:be:f5:e0:ea:db:fc:ec:29:e3:ca:20:1e:cb | ssh | +-------+-------------------------------------------------+------+
[cent@dlp ~(keystone)]$
netID=$(openstack network list | grep sharednet1 | awk '{ print $2 }') # インスタンス作成/起動 [cent@dlp ~(keystone)]$ openstack server create --flavor m1.medium --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 | FyRmxN5UnZxi | | config_drive | | | created | 2023-04-14T02:25:52Z | | flavor | m1.medium (2) | | hostId | | | id | fbb05592-02fd-42a7-bc73-d9f526431d4e | | image | CentOS-Stream9 (6afab1f1-c2e0-42c5-9c86-659f56174b9d) | | key_name | mykey | | name | CentOS-St9 | | progress | 0 | | project_id | 17b52bb0db9440549d400290cec02c1d | | properties | | | security_groups | name='c761c71b-265d-4802-9c7d-0b85e0680e06' | | status | BUILD | | updated | 2023-04-14T02:25:52Z | | user_id | 1ed6032943cb4e5d907371a20adae1c0 | | volumes_attached | | +-----------------------------+-------------------------------------------------------+ # 動作確認 (起動直後しばらくは [BUILD] ステータスとなっている) [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+------------+--------+----------+----------------+-----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+------------+--------+----------+----------------+-----------+ | fbb05592-02fd-42a7-bc73-d9f526431d4e | CentOS-St9 | BUILD | | CentOS-Stream9 | m1.medium | +--------------------------------------+------------+--------+----------+----------------+-----------+ # 正常に起動すると [ACTIVE] ステータスとなる [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+------------+--------+-----------------------+----------------+-----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+------------+--------+-----------------------+----------------+-----------+ | fbb05592-02fd-42a7-bc73-d9f526431d4e | CentOS-St9 | ACTIVE | sharednet1=10.0.0.222 | CentOS-Stream9 | m1.medium | +--------------------------------------+------------+--------+-----------------------+----------------+-----------+ |
[2] | 起動した仮想マシンインスタンスに SSH 接続できるように、先に作成したセキュリティグループにポート許可の設定を追加します。 |
# ICMP 許可 [cent@dlp ~(keystone)]$ openstack security group rule create --protocol icmp --ingress secgroup01 +-------------------------+--------------------------------------+ | Field | Value | +-------------------------+--------------------------------------+ | created_at | 2023-04-14T02:27:38Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 788c37e3-3956-42b2-b21a-bf1c7a8e4a48 | | name | None | | normalized_cidr | 0.0.0.0/0 | | port_range_max | None | | port_range_min | None | | project_id | 17b52bb0db9440549d400290cec02c1d | | 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 | c761c71b-265d-4802-9c7d-0b85e0680e06 | | tags | [] | | updated_at | 2023-04-14T02:27:38Z | +-------------------------+--------------------------------------+ # SSH 許可 [cent@dlp ~(keystone)]$ openstack security group rule create --protocol tcp --dst-port 22:22 secgroup01 +-------------------------+--------------------------------------+ | Field | Value | +-------------------------+--------------------------------------+ | created_at | 2023-04-14T02:27:58Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | da45affc-603e-47b4-af3c-bbef588a3afa | | name | None | | normalized_cidr | 0.0.0.0/0 | | port_range_max | 22 | | port_range_min | 22 | | project_id | 17b52bb0db9440549d400290cec02c1d | | 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 | c761c71b-265d-4802-9c7d-0b85e0680e06 | | tags | [] | | updated_at | 2023-04-14T02:27:58Z | +-------------------------+--------------------------------------+[cent@dlp ~(keystone)]$ openstack security group rule list secgroup01 +--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+ | ID | IP Protocol | Ethertype | IP Range | Port Range | Direction | Remote Security Group | Remote Address Group | +--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+ | 788c37e3-3956-42b2-b21a-bf1c7a8e4a48 | icmp | IPv4 | 0.0.0.0/0 | | ingress | None | None | | 86d4925a-5622-4bb9-9eb3-1ee49540e23b | None | IPv6 | ::/0 | | egress | None | None | | d06ad67e-ddfc-40bd-8335-ed7d6f1ca9f4 | None | IPv4 | 0.0.0.0/0 | | egress | None | None | | da45affc-603e-47b4-af3c-bbef588a3afa | 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 | +--------------------------------------+------------+--------+-----------------------+----------------+-----------+ | fbb05592-02fd-42a7-bc73-d9f526431d4e | CentOS-St9 | ACTIVE | sharednet1=10.0.0.222 | CentOS-Stream9 | m1.medium | +--------------------------------------+------------+--------+-----------------------+----------------+-----------+ # ping 応答が返ってくれば OK [cent@dlp ~(keystone)]$ ping 10.0.0.222 -c3 PING 10.0.0.222 (10.0.0.222) 56(84) bytes of data. 64 bytes from 10.0.0.222: icmp_seq=1 ttl=64 time=0.908 ms 64 bytes from 10.0.0.222: icmp_seq=2 ttl=64 time=0.412 ms 64 bytes from 10.0.0.222: icmp_seq=3 ttl=64 time=0.461 ms --- 10.0.0.222 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2045ms rtt min/avg/max/mdev = 0.412/0.593/0.908/0.223 ms # SSH でログイン [cent@dlp ~(keystone)]$ ssh centos@10.0.0.222
The authenticity of host '10.0.0.222 (10.0.0.222)' can't be established. ED25519 key fingerprint is SHA256:A+hDHolX0kV5K6pOAHLr/RBY1dBuOp/9x8tTn0KBAq4. 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.222' (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 | +--------------------------------------+------------+--------+-----------------------+----------------+-----------+ | fbb05592-02fd-42a7-bc73-d9f526431d4e | CentOS-St9 | ACTIVE | sharednet1=10.0.0.222 | CentOS-Stream9 | m1.medium | +--------------------------------------+------------+--------+-----------------------+----------------+-----------+ # インスタンス停止 [cent@dlp ~(keystone)]$ openstack server stop CentOS-St9 [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+------------+---------+-----------------------+----------------+-----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+------------+---------+-----------------------+----------------+-----------+ | fbb05592-02fd-42a7-bc73-d9f526431d4e | CentOS-St9 | SHUTOFF | sharednet1=10.0.0.222 | CentOS-Stream9 | m1.medium | +--------------------------------------+------------+---------+-----------------------+----------------+-----------+ # インスタンスを起動する [cent@dlp ~(keystone)]$ openstack server start CentOS-St9 [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+------------+--------+-----------------------+----------------+-----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+------------+--------+-----------------------+----------------+-----------+ | fbb05592-02fd-42a7-bc73-d9f526431d4e | CentOS-St9 | ACTIVE | sharednet1=10.0.0.222 | CentOS-Stream9 | m1.medium | +--------------------------------------+------------+--------+-----------------------+----------------+-----------+ |
[5] | VNC コンソールを取得して Web ブラウザーでのアクセスも可能です。 |
[cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+------------+--------+-----------------------+----------------+-----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+------------+--------+-----------------------+----------------+-----------+ | fbb05592-02fd-42a7-bc73-d9f526431d4e | CentOS-St9 | ACTIVE | sharednet1=10.0.0.222 | CentOS-Stream9 | m1.medium | +--------------------------------------+------------+--------+-----------------------+----------------+-----------+[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%3D871ed8f1-57b1-4278-afb5-dc4f27cea325 | +----------+-----------------------------------------------------------------------------------------------+ |
[6] | 上記コマンドで表示された URL に Web アクセスすると、インスタンスに接続され、操作が可能となります。 |
Sponsored Link |