Ubuntu 20.04
Sponsored Link

OpenStack Ussuri : インスタンスを起動する2020/06/05

 
仮想マシンインスタンスを起動します。
[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=http://10.0.0.30: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 |
+--------------------------------------+------------+--------+
| de51f2d9-aa58-4a34-87d6-857451599d9a | Ubuntu2004 | active |
+--------------------------------------+------------+--------+

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

ubuntu@dlp ~(keystone)$
openstack network list

+--------------------------------------+------------+--------------------------------------+
| ID                                   | Name       | Subnets                              |
+--------------------------------------+------------+--------------------------------------+
| 979324a4-6c15-4922-961d-22f01791690e | sharednet1 | cd384c9e-6285-4a6e-b280-d9ee74c21425 |
+--------------------------------------+------------+--------------------------------------+

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

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

+-----------------+--------------------------------------------------------------------------------+
| Field           | Value                                                                          |
+-----------------+--------------------------------------------------------------------------------+
| created_at      | 2020-06-04T05:32:16Z                                                           |
| description     | secgroup01                                                                     |
| id              | 0e5350ea-3985-4191-b11a-08da48820b1b                                           |
| location        | cloud='', project.domain_id=, project.domain_name='default', project.id='b0... |
| name            | secgroup01                                                                     |
| project_id      | b01d1469edbf4649ac1c41d63776373f                                               |
| revision_number | 1                                                                              |
| rules           | created_at='2020-06-04T05:32:16Z', direction='egress', ethertype='IPv6', id... |
|                 | created_at='2020-06-04T05:32:16Z', direction='egress', ethertype='IPv4', id... |
| stateful        | True                                                                           |
| tags            | []                                                                             |
| updated_at      | 2020-06-04T05:32:16Z                                                           |
+-----------------+--------------------------------------------------------------------------------+

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

+--------------------------------------+------------+------------------------+----------------------------------+------+
| ID                                   | Name       | Description            | Project                          | Tags |
+--------------------------------------+------------+------------------------+----------------------------------+------+
| 0e5350ea-3985-4191-b11a-08da48820b1b | secgroup01 | secgroup01             | b01d1469edbf4649ac1c41d63776373f | []   |
| 31bac83c-5d55-46c3-b405-4076e1f4bf93 | default    | Default security group | b01d1469edbf4649ac1c41d63776373f | []   |
+--------------------------------------+------------+------------------------+----------------------------------+------+

# インスタンス接続用の 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                                           |
+-------------+-------------------------------------------------+
| fingerprint | 19:28:9f:9f:61:3a:42:76:bb:9b:4b:7a:08:7f:59:3b |
| name        | mykey                                           |
| user_id     | be2276c43b2746299fae390339e9ccd3                |
+-------------+-------------------------------------------------+

ubuntu@dlp ~(keystone)$
openstack keypair list

+-------+-------------------------------------------------+
| Name  | Fingerprint                                     |
+-------+-------------------------------------------------+
| mykey | 19:28:9f:9f:61:3a:42:76:bb:9b:4b:7a:08:7f:59:3b |
+-------+-------------------------------------------------+

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

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

ubuntu@dlp ~(keystone)$
openstack server create --flavor m1.small --image Ubuntu2004 --security-group secgroup01 --nic net-id=$netID --key-name mykey Ubuntu_2004
+-----------------------------+---------------------------------------------------+
| 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                   | Ffo4GnVYojsP                                      |
| config_drive                |                                                   |
| created                     | 2020-06-04T05:45:13Z                              |
| flavor                      | m1.small (0)                                      |
| hostId                      |                                                   |
| id                          | 7798104b-cd3a-4612-b206-f45a2eb313b6              |
| image                       | Ubuntu2004 (de51f2d9-aa58-4a34-87d6-857451599d9a) |
| key_name                    | mykey                                             |
| name                        | Ubuntu_2004                                       |
| progress                    | 0                                                 |
| project_id                  | b01d1469edbf4649ac1c41d63776373f                  |
| properties                  |                                                   |
| security_groups             | name='0e5350ea-3985-4191-b11a-08da48820b1b'       |
| status                      | BUILD                                             |
| updated                     | 2020-06-04T05:45:13Z                              |
| user_id                     | be2276c43b2746299fae390339e9ccd3                  |
| volumes_attached            |                                                   |
+-----------------------------+---------------------------------------------------+

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

ubuntu@dlp ~(keystone)$
openstack server list

+--------------------------------------+-------------+--------+----------+------------+----------+
| ID                                   | Name        | Status | Networks | Image      | Flavor   |
+--------------------------------------+-------------+--------+----------+------------+----------+
| 7798104b-cd3a-4612-b206-f45a2eb313b6 | Ubuntu_2004 | BUILD  |          | Ubuntu2004 | m1.small |
+--------------------------------------+-------------+--------+----------+------------+----------+

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

ubuntu@dlp ~(keystone)$
openstack server list

+--------------------------------------+-------------+--------+-----------------------+------------+----------+
| ID                                   | Name        | Status | Networks              | Image      | Flavor   |
+--------------------------------------+-------------+--------+-----------------------+------------+----------+
| 7798104b-cd3a-4612-b206-f45a2eb313b6 | Ubuntu_2004 | ACTIVE | sharednet1=10.0.0.252 | Ubuntu2004 | m1.small |
+--------------------------------------+-------------+--------+-----------------------+------------+----------+
[2] 起動した仮想マシンインスタンスに SSH 接続できるように、先に作成したセキュリティグループにポート許可の設定を追加します。
# ICMP 許可

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

+-------------------+------------------------------------------------------------------------------+
| Field             | Value                                                                        |
+-------------------+------------------------------------------------------------------------------+
| created_at        | 2020-06-04T05:46:33Z                                                         |
| description       |                                                                              |
| direction         | ingress                                                                      |
| ether_type        | IPv4                                                                         |
| id                | 7dc0ee0b-7b28-40c7-8981-a1850abe9285                                         |
| location          | cloud='', project.domain_id=, project.domain_name='default', project.id='... |
| name              | None                                                                         |
| port_range_max    | None                                                                         |
| port_range_min    | None                                                                         |
| project_id        | b01d1469edbf4649ac1c41d63776373f                                             |
| protocol          | icmp                                                                         |
| remote_group_id   | None                                                                         |
| remote_ip_prefix  | 0.0.0.0/0                                                                    |
| revision_number   | 0                                                                            |
| security_group_id | 0e5350ea-3985-4191-b11a-08da48820b1b                                         |
| tags              | []                                                                           |
| updated_at        | 2020-06-04T05:46:33Z                                                         |
+-------------------+------------------------------------------------------------------------------+

# SSH 許可

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

+-------------------+-------------------------------------------------------------------------------+
| Field             | Value                                                                         |
+-------------------+-------------------------------------------------------------------------------+
| created_at        | 2020-06-04T05:47:12Z                                                          |
| description       |                                                                               |
| direction         | ingress                                                                       |
| ether_type        | IPv4                                                                          |
| id                | 1a4709c1-46f7-4a1e-9c95-12fa45c61cea                                          |
| location          | cloud='', project.domain_id=, project.domain_name='default', project.id='b... |
| name              | None                                                                          |
| port_range_max    | 22                                                                            |
| port_range_min    | 22                                                                            |
| project_id        | b01d1469edbf4649ac1c41d63776373f                                              |
| protocol          | tcp                                                                           |
| remote_group_id   | None                                                                          |
| remote_ip_prefix  | 0.0.0.0/0                                                                     |
| revision_number   | 0                                                                             |
| security_group_id | 0e5350ea-3985-4191-b11a-08da48820b1b                                          |
| tags              | []                                                                            |
| updated_at        | 2020-06-04T05:47:12Z                                                          |
+-------------------+-------------------------------------------------------------------------------+

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

+--------------------------------------+-------------+-----------+-----------+------------+--------------------------------------+--------------------------------------+
| ID                                   | IP Protocol | Ethertype | IP Range  | Port Range | Remote Security Group                | Security Group                       |
+--------------------------------------+-------------+-----------+-----------+------------+--------------------------------------+--------------------------------------+
| 03375b2c-f613-45e1-b152-92b7f9f4cc1f | None        | IPv4      | 0.0.0.0/0 |            | 31bac83c-5d55-46c3-b405-4076e1f4bf93 | 31bac83c-5d55-46c3-b405-4076e1f4bf93 |
| 18e861d8-4ff0-404b-87d5-e643fef2d302 | None        | IPv6      | ::/0      |            | None                                 | 0e5350ea-3985-4191-b11a-08da48820b1b |
| 1a4709c1-46f7-4a1e-9c95-12fa45c61cea | tcp         | IPv4      | 0.0.0.0/0 | 22:22      | None                                 | 0e5350ea-3985-4191-b11a-08da48820b1b |
| 4695eaa4-211f-4d86-b753-ca0c1d4a2019 | None        | IPv4      | 0.0.0.0/0 |            | None                                 | 0e5350ea-3985-4191-b11a-08da48820b1b |
| 7366e3e4-dcad-486e-9ab4-e5e845a3d66e | None        | IPv6      | ::/0      |            | 31bac83c-5d55-46c3-b405-4076e1f4bf93 | 31bac83c-5d55-46c3-b405-4076e1f4bf93 |
| 7dc0ee0b-7b28-40c7-8981-a1850abe9285 | icmp        | IPv4      | 0.0.0.0/0 |            | None                                 | 0e5350ea-3985-4191-b11a-08da48820b1b |
| b25c7441-24f2-4321-826b-e2f1849b4b94 | None        | IPv6      | ::/0      |            | None                                 | 31bac83c-5d55-46c3-b405-4076e1f4bf93 |
| c551a3c8-8e06-4397-8766-468fee7c788e | None        | IPv4      | 0.0.0.0/0 |            | None                                 | 31bac83c-5d55-46c3-b405-4076e1f4bf93 |
+--------------------------------------+-------------+-----------+-----------+------------+--------------------------------------+--------------------------------------+
[3] 起動した仮想マシンインスタンスに SSH ログインします。
ubuntu@dlp ~(keystone)$
openstack server list

+--------------------------------------+-------------+--------+-----------------------+------------+----------+
| ID                                   | Name        | Status | Networks              | Image      | Flavor   |
+--------------------------------------+-------------+--------+-----------------------+------------+----------+
| 7798104b-cd3a-4612-b206-f45a2eb313b6 | Ubuntu_2004 | ACTIVE | sharednet1=10.0.0.252 | Ubuntu2004 | m1.small |
+--------------------------------------+-------------+--------+-----------------------+------------+----------+

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

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

PING 10.0.0.252 (10.0.0.252) 56(84) bytes of data.
64 bytes from 10.0.0.252: icmp_seq=1 ttl=64 time=0.938 ms
64 bytes from 10.0.0.252: icmp_seq=2 ttl=64 time=0.644 ms
64 bytes from 10.0.0.252: icmp_seq=3 ttl=64 time=0.696 ms

--- 10.0.0.252 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2009ms
rtt min/avg/max/mdev = 0.644/0.759/0.938/0.128 ms

# SSH でログイン

ubuntu@dlp ~(keystone)$
ssh ubuntu@10.0.0.252
The authenticity of host '10.0.0.252 (10.0.0.252)' can't be established.
ECDSA key fingerprint is SHA256:xmbqXJ4HLFCIxoGZq83RtvltidqeMPpRdEqVOObqQLw.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.0.0.252' (ECDSA) to the list of known hosts.
Welcome to Ubuntu 20.04 LTS (GNU/Linux 5.4.0-33-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Thu 04 Jun 2020 02:49:03 PM JST

  System load:  0.1               Processes:             103
  Usage of /:   24.3% of 8.34GB   Users logged in:       0
  Memory usage: 7%                IPv4 address for ens3: 10.0.0.252
  Swap usage:   0%

 * MicroK8s gets a native Windows installer and command-line integration.

     https://ubuntu.com/blog/microk8s-installers-windows-and-macos

0 updates can be installed immediately.
0 of these updates are security updates.

ubuntu@ubuntu-2004:~$    
# ログインできた

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

+--------------------------------------+-------------+--------+-----------------------+------------+----------+
| ID                                   | Name        | Status | Networks              | Image      | Flavor   |
+--------------------------------------+-------------+--------+-----------------------+------------+----------+
| 7798104b-cd3a-4612-b206-f45a2eb313b6 | Ubuntu_2004 | ACTIVE | sharednet1=10.0.0.252 | Ubuntu2004 | m1.small |
+--------------------------------------+-------------+--------+-----------------------+------------+----------+

# インスタンス停止

ubuntu@dlp ~(keystone)$
openstack server stop Ubuntu_2004

ubuntu@dlp ~(keystone)$
openstack server list

+--------------------------------------+-------------+---------+-----------------------+------------+----------+
| ID                                   | Name        | Status  | Networks              | Image      | Flavor   |
+--------------------------------------+-------------+---------+-----------------------+------------+----------+
| 7798104b-cd3a-4612-b206-f45a2eb313b6 | Ubuntu_2004 | SHUTOFF | sharednet1=10.0.0.252 | Ubuntu2004 | m1.small |
+--------------------------------------+-------------+---------+-----------------------+------------+----------+

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

ubuntu@dlp ~(keystone)$
openstack server start Ubuntu_2004

ubuntu@dlp ~(keystone)$
openstack server list

+--------------------------------------+-------------+--------+-----------------------+------------+----------+
| ID                                   | Name        | Status | Networks              | Image      | Flavor   |
+--------------------------------------+-------------+--------+-----------------------+------------+----------+
| 7798104b-cd3a-4612-b206-f45a2eb313b6 | Ubuntu_2004 | ACTIVE | sharednet1=10.0.0.252 | Ubuntu2004 | m1.small |
+--------------------------------------+-------------+--------+-----------------------+------------+----------+
[5] VNC コンソールを取得して Web ブラウザでのアクセスも可能です。
ubuntu@dlp ~(keystone)$
openstack server list

+--------------------------------------+-------------+--------+-----------------------+------------+----------+
| ID                                   | Name        | Status | Networks              | Image      | Flavor   |
+--------------------------------------+-------------+--------+-----------------------+------------+----------+
| 7798104b-cd3a-4612-b206-f45a2eb313b6 | Ubuntu_2004 | ACTIVE | sharednet1=10.0.0.252 | Ubuntu2004 | m1.small |
+--------------------------------------+-------------+--------+-----------------------+------------+----------+

ubuntu@dlp ~(keystone)$
openstack console url show Ubuntu_2004

+-------+------------------------------------------------------------------------------------------+
| Field | Value                                                                                    |
+-------+------------------------------------------------------------------------------------------+
| type  | novnc                                                                                    |
| url   | http://10.0.0.30:6080/vnc_auto.html?path=%3Ftoken%3D2f6dd9ad-b1ed-40e1-8a52-4a0426d9ad7a |
+-------+------------------------------------------------------------------------------------------+
[6] 上記コマンドで表示された URL に Web アクセスすると、インスタンスに接続され、操作が可能となります。
関連コンテンツ