OpenStack Bobcat : インスタンスを起動する2023/10/24 |
仮想マシンインスタンスを起動します。
|
|
[1] | Openstack 用の環境変数を設定した任意のユーザーでログインして、仮想マシンインスタンスを作成/起動します。 |
# 利用可能な [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 | 10 | 0 | 4 | True | | 4 | m2.large | 8192 | 10 | 10 | 4 | True | | 5 | m3.large | 8192 | 50 | 0 | 4 | True | +----+-----------+------+------+-----------+-------+-----------+ # 利用可能なイメージ確認 [cent@dlp ~(keystone)]$ openstack image list +--------------------------------------+----------------+--------+ | ID | Name | Status | +--------------------------------------+----------------+--------+ | bcbaa323-2438-4f5e-9473-49f633bb8f9b | CentOS-Stream9 | active | +--------------------------------------+----------------+--------+ # 利用可能なネットワーク確認 [cent@dlp ~(keystone)]$ openstack network list +--------------------------------------+------------+--------------------------------------+ | ID | Name | Subnets | +--------------------------------------+------------+--------------------------------------+ | ec214091-7285-400b-8efe-5c4e566c51d7 | sharednet1 | 9544c8bf-c77b-4cee-a686-3a6cb1a39a8f | +--------------------------------------+------------+--------------------------------------+ # インスタンス用のセキュリティグループを作成 [cent@dlp ~(keystone)]$ openstack security group create secgroup01 +-----------------+------------------------------------------------------------------------------+ | Field | Value | +-----------------+------------------------------------------------------------------------------+ | created_at | 2023-10-24T03:25:27Z | | description | secgroup01 | | id | d295a858-1d51-4e15-a1e9-eb13adcf7861 | | name | secgroup01 | | project_id | f4598dfd3b8a47149234b6892d18d5a4 | | revision_number | 1 | | rules | created_at='2023-10-24T03:25:27Z', direction='egress', ethertype='IPv4', ... | | | created_at='2023-10-24T03:25:27Z', direction='egress', ethertype='IPv6', ... | | shared | False | | stateful | True | | tags | [] | | updated_at | 2023-10-24T03:25:27Z | +-----------------+------------------------------------------------------------------------------+[cent@dlp ~(keystone)]$ openstack security group list +--------------------------------------+------------+------------------------+----------------------------------+------+ | ID | Name | Description | Project | Tags | +--------------------------------------+------------+------------------------+----------------------------------+------+ | 163790db-7ca5-42e1-a6e7-70679409e2b3 | default | Default security group | f4598dfd3b8a47149234b6892d18d5a4 | [] | | d295a858-1d51-4e15-a1e9-eb13adcf7861 | secgroup01 | secgroup01 | f4598dfd3b8a47149234b6892d18d5a4 | [] | +--------------------------------------+------------+------------------------+----------------------------------+------+ # インスタンス接続用の 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 | 03:eb:ac:ca:38:90:ed:e6:35:8b:3f:45:e9:d5:62:ea | | id | mykey | | is_deleted | None | | name | mykey | | type | ssh | | user_id | d70a5f7908de4cd9aa8e189b725244a9 | +-------------+-------------------------------------------------+[cent@dlp ~(keystone)]$ openstack keypair list +-------+-------------------------------------------------+------+ | Name | Fingerprint | Type | +-------+-------------------------------------------------+------+ | mykey | 03:eb:ac:ca:38:90:ed:e6:35:8b:3f:45:e9:d5:62:ea | 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 | zyKdQtZAos2R | | config_drive | | | created | 2023-10-24T03:28:01Z | | flavor | m1.medium (2) | | hostId | | | id | 37f143ed-bd44-48eb-97cd-2062951f0806 | | image | CentOS-Stream9 (bcbaa323-2438-4f5e-9473-49f633bb8f9b) | | key_name | mykey | | name | CentOS-St9 | | progress | 0 | | project_id | f4598dfd3b8a47149234b6892d18d5a4 | | properties | | | security_groups | name='d295a858-1d51-4e15-a1e9-eb13adcf7861' | | status | BUILD | | updated | 2023-10-24T03:28:01Z | | user_id | d70a5f7908de4cd9aa8e189b725244a9 | | volumes_attached | | +-----------------------------+-------------------------------------------------------+ # 動作確認 (起動直後しばらくは [BUILD] ステータスとなっている) [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+------------+--------+----------+----------------+-----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+------------+--------+----------+----------------+-----------+ | 37f143ed-bd44-48eb-97cd-2062951f0806 | CentOS-St9 | BUILD | | CentOS-Stream9 | m1.medium | +--------------------------------------+------------+--------+----------+----------------+-----------+ # 正常に起動すると [ACTIVE] ステータスとなる [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+------------+--------+-----------------------+----------------+-----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+------------+--------+-----------------------+----------------+-----------+ | 37f143ed-bd44-48eb-97cd-2062951f0806 | CentOS-St9 | ACTIVE | sharednet1=10.0.0.210 | CentOS-Stream9 | m1.medium | +--------------------------------------+------------+--------+-----------------------+----------------+-----------+ |
[2] | 起動した仮想マシンインスタンスに SSH 接続できるように、先に作成したセキュリティグループにポート許可の設定を追加します。 |
# ICMP 許可 [cent@dlp ~(keystone)]$ openstack security group rule create --protocol icmp --ingress secgroup01 +-------------------------+--------------------------------------+ | Field | Value | +-------------------------+--------------------------------------+ | created_at | 2023-10-24T03:29:10Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | b6b85f1a-cf41-45dc-a239-de96fca08240 | | name | None | | normalized_cidr | 0.0.0.0/0 | | port_range_max | None | | port_range_min | None | | project_id | f4598dfd3b8a47149234b6892d18d5a4 | | 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 | d295a858-1d51-4e15-a1e9-eb13adcf7861 | | tags | [] | | updated_at | 2023-10-24T03:29:10Z | +-------------------------+--------------------------------------+ # SSH 許可 [cent@dlp ~(keystone)]$ openstack security group rule create --protocol tcp --dst-port 22:22 secgroup01 +-------------------------+--------------------------------------+ | Field | Value | +-------------------------+--------------------------------------+ | created_at | 2023-10-24T03:29:29Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 698a028e-5c35-44ad-aa61-88155a89d378 | | name | None | | normalized_cidr | 0.0.0.0/0 | | port_range_max | 22 | | port_range_min | 22 | | project_id | f4598dfd3b8a47149234b6892d18d5a4 | | 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 | d295a858-1d51-4e15-a1e9-eb13adcf7861 | | tags | [] | | updated_at | 2023-10-24T03:29:29Z | +-------------------------+--------------------------------------+[cent@dlp ~(keystone)]$ openstack security group rule list secgroup01 +--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+ | ID | IP Protocol | Ethertype | IP Range | Port Range | Direction | Remote Security Group | Remote Address Group | +--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+ | 1e253bec-8405-4bc7-9c2f-463fd1421065 | None | IPv4 | 0.0.0.0/0 | | egress | None | None | | 698a028e-5c35-44ad-aa61-88155a89d378 | tcp | IPv4 | 0.0.0.0/0 | 22:22 | ingress | None | None | | b6b85f1a-cf41-45dc-a239-de96fca08240 | icmp | IPv4 | 0.0.0.0/0 | | ingress | None | None | | bfaf112d-e4a6-4e4f-adc1-2365f0680713 | None | IPv6 | ::/0 | | egress | None | None | +--------------------------------------+-------------+-----------+-----------+------------+-----------+-----------------------+----------------------+ |
[3] | 起動した仮想マシンインスタンスに SSH ログインします。 |
[cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+------------+--------+-----------------------+----------------+-----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+------------+--------+-----------------------+----------------+-----------+ | 37f143ed-bd44-48eb-97cd-2062951f0806 | CentOS-St9 | ACTIVE | sharednet1=10.0.0.210 | CentOS-Stream9 | m1.medium | +--------------------------------------+------------+--------+-----------------------+----------------+-----------+ # ping 応答が返ってくれば OK [cent@dlp ~(keystone)]$ ping 10.0.0.210 -c3 PING 10.0.0.210 (10.0.0.210) 56(84) bytes of data. 64 bytes from 10.0.0.210: icmp_seq=1 ttl=64 time=1.02 ms 64 bytes from 10.0.0.210: icmp_seq=2 ttl=64 time=0.605 ms 64 bytes from 10.0.0.210: icmp_seq=3 ttl=64 time=0.456 ms --- 10.0.0.210 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2005ms rtt min/avg/max/mdev = 0.456/0.694/1.021/0.239 ms # SSH でログイン [cent@dlp ~(keystone)]$ ssh centos@10.0.0.210
The authenticity of host '10.0.0.210 (10.0.0.210)' can't be established. ED25519 key fingerprint is SHA256:X8VMxmPAD+pHBLZ4ZWoEe6opKQBR1PUPKxREIf3Z1to. 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.210' (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 | +--------------------------------------+------------+--------+-----------------------+----------------+-----------+ | 37f143ed-bd44-48eb-97cd-2062951f0806 | CentOS-St9 | ACTIVE | sharednet1=10.0.0.210 | CentOS-Stream9 | m1.medium | +--------------------------------------+------------+--------+-----------------------+----------------+-----------+ # インスタンス停止 [cent@dlp ~(keystone)]$ openstack server stop CentOS-St9 [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+------------+---------+-----------------------+----------------+-----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+------------+---------+-----------------------+----------------+-----------+ | 37f143ed-bd44-48eb-97cd-2062951f0806 | CentOS-St9 | SHUTOFF | sharednet1=10.0.0.210 | CentOS-Stream9 | m1.medium | +--------------------------------------+------------+---------+-----------------------+----------------+-----------+ # インスタンスを起動する [cent@dlp ~(keystone)]$ openstack server start CentOS-St9 [cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+------------+--------+-----------------------+----------------+-----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+------------+--------+-----------------------+----------------+-----------+ | 37f143ed-bd44-48eb-97cd-2062951f0806 | CentOS-St9 | ACTIVE | sharednet1=10.0.0.210 | CentOS-Stream9 | m1.medium | +--------------------------------------+------------+--------+-----------------------+----------------+-----------+ |
[5] | VNC コンソールを取得して Web ブラウザーでのアクセスも可能です。 |
[cent@dlp ~(keystone)]$ openstack server list +--------------------------------------+------------+--------+-----------------------+----------------+-----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+------------+--------+-----------------------+----------------+-----------+ | 37f143ed-bd44-48eb-97cd-2062951f0806 | CentOS-St9 | ACTIVE | sharednet1=10.0.0.210 | 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%3D328d84ce-6028-439b-aa97-2feacd0131d5 | +----------+-----------------------------------------------------------------------------------------------+ |
[6] | 上記コマンドで表示された URL に Web アクセスすると、インスタンスに接続され、操作が可能となります。 |
Sponsored Link |
|