OpenStack Rocky : インスタンスを起動する2018/09/12 |
仮想マシンインスタンスを起動します。
|
|
[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 | +--------------------------------------+------------+--------+ | 7df9e97e-96aa-45f9-8ffb-fa8685283a70 | Ubuntu1804 | active | +--------------------------------------+------------+--------+ # 利用可能なネットワーク確認 ubuntu@dlp ~(keystone)$ openstack network list +--------------------------------------+------------+--------------------------------------+ | ID | Name | Subnets | +--------------------------------------+------------+--------------------------------------+ | 7c3d229f-7cfb-4451-af6b-b77f9b2ad1e1 | sharednet1 | c3f4a8f5-b8fa-4b6e-8286-fcf4428ec477 | +--------------------------------------+------------+--------------------------------------+ # インスタンス用のセキュリティグループを作成 ubuntu@dlp ~(keystone)$ openstack security group create secgroup01 +-----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+ | Field | Value | +-----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+ | created_at | 2018-09-12T01:40:01Z | | description | secgroup01 | | id | cef9ebb4-0336-4a84-b994-fd2d577ff1e4 | | name | secgroup01 | | project_id | e8f6d97f3edb41fe827cb8b4cb471b95 | | revision_number | 1 | | rules | created_at='2018-09-12T01:40:01Z', direction='egress', ethertype='IPv4', id='6902fe4c-b2b8-4025-9576-8b120532ddfb', updated_at='2018-09-12T01:40:01Z' | | | created_at='2018-09-12T01:40:01Z', direction='egress', ethertype='IPv6', id='e08b65da-c523-411b-9092-29542b17606f', updated_at='2018-09-12T01:40:01Z' | | tags | [] | | updated_at | 2018-09-12T01:40:01Z | +-----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+ubuntu@dlp ~(keystone)$ openstack security group list +--------------------------------------+------------+------------------------+----------------------------------+------+ | ID | Name | Description | Project | Tags | +--------------------------------------+------------+------------------------+----------------------------------+------+ | 7748fd6c-d5fc-4e68-bd09-b3866128af9a | default | Default security group | e8f6d97f3edb41fe827cb8b4cb471b95 | [] | | cef9ebb4-0336-4a84-b994-fd2d577ff1e4 | secgroup01 | secgroup01 | e8f6d97f3edb41fe827cb8b4cb471b95 | [] | +--------------------------------------+------------+------------------------+----------------------------------+------+ # インスタンス接続用の 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 | e3:af:60:f4:bc:38:9e:0b:19:9f:61:be:91:88:72:bd | | name | mykey | | user_id | d05c0b9b4cb2488dbbc15e319c76c401 | +-------------+-------------------------------------------------+ubuntu@dlp ~(keystone)$ openstack keypair list +-------+-------------------------------------------------+ | Name | Fingerprint | +-------+-------------------------------------------------+ | mykey | e3:af:60:f4:bc:38:9e:0b:19:9f:61:be:91:88:72:bd | +-------+-------------------------------------------------+
ubuntu@dlp ~(keystone)$
netID=$(openstack network list | grep sharednet1 | awk '{ print $2 }') # インスタンス作成・起動 ubuntu@dlp ~(keystone)$ openstack server create --flavor m1.small --image Ubuntu1804 --security-group secgroup01 --nic net-id=$netID --key-name mykey Ubuntu_1804
+-----------------------------+---------------------------------------------------+ | 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 | X4YzyTpxYCmM | | config_drive | | | created | 2018-09-12T04:27:08Z | | flavor | m1.small (0) | | hostId | | | id | 87d3a97d-2acc-490a-b94c-d567e0b89317 | | image | Ubuntu1804 (7df9e97e-96aa-45f9-8ffb-fa8685283a70) | | key_name | mykey | | name | Ubuntu_1804 | | progress | 0 | | project_id | 42530f21bf47470ea9283b3ff9f26b5b | | properties | | | security_groups | name='84806096-7de0-4e95-8e50-68ca586c685e' | | status | BUILD | | updated | 2018-09-12T04:27:08Z | | user_id | a590047fbe8e4a8f9cc20b176a03f0b0 | | volumes_attached | | +-----------------------------+---------------------------------------------------+ # 動作確認 (起動直後しばらくは [BUILD] ステータスとなっている) ubuntu@dlp ~(keystone)$ openstack server list +--------------------------------------+-------------+--------+----------+------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-------------+--------+----------+------------+----------+ | 87d3a97d-2acc-490a-b94c-d567e0b89317 | Ubuntu_1804 | BUILD | | Ubuntu1804 | m1.small | +--------------------------------------+-------------+--------+----------+------------+----------+ # 正常に起動すると [ACTIVE] ステータスとなる ubuntu@dlp ~(keystone)$ openstack server list +--------------------------------------+-------------+--------+-----------------------+------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-------------+--------+-----------------------+------------+----------+ | 87d3a97d-2acc-490a-b94c-d567e0b89317 | Ubuntu_1804 | ACTIVE | sharednet1=10.0.0.203 | Ubuntu1804 | m1.small | +--------------------------------------+-------------+--------+-----------------------+------------+----------+ |
[2] | 起動した仮想マシンインスタンスに SSH 接続できるように、先に作成したセキュリティグループにポート許可の設定を追加します。 |
# ICMP 許可 ubuntu@dlp ~(keystone)$ openstack security group rule create --protocol icmp --ingress secgroup01 +-------------------+--------------------------------------+ | Field | Value | +-------------------+--------------------------------------+ | created_at | 2018-09-12T04:51:42Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | c719567b-d50b-4c49-be93-7c0c9f3aefff | | name | None | | port_range_max | None | | port_range_min | None | | project_id | 42530f21bf47470ea9283b3ff9f26b5b | | protocol | icmp | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 0 | | security_group_id | 84806096-7de0-4e95-8e50-68ca586c685e | | updated_at | 2018-09-12T04:51:42Z | +-------------------+--------------------------------------+ # SSH 許可 ubuntu@dlp ~(keystone)$ openstack security group rule create --protocol tcp --dst-port 22:22 secgroup01 +-------------------+--------------------------------------+ | Field | Value | +-------------------+--------------------------------------+ | created_at | 2018-09-12T04:51:57Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | d79df6f9-379f-419d-be40-e290c0fb5552 | | name | None | | port_range_max | 22 | | port_range_min | 22 | | project_id | 42530f21bf47470ea9283b3ff9f26b5b | | protocol | tcp | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 0 | | security_group_id | 84806096-7de0-4e95-8e50-68ca586c685e | | updated_at | 2018-09-12T04:51:57Z | +-------------------+--------------------------------------+ubuntu@dlp ~(keystone)$ openstack security group rule list +--------------------------------------+-------------+-----------+------------+--------------------------------------+--------------------------------------+ | ID | IP Protocol | IP Range | Port Range | Remote Security Group | Security Group | +--------------------------------------+-------------+-----------+------------+--------------------------------------+--------------------------------------+ | 096c82c4-3d27-4cdf-8080-fe91890a9395 | None | None | | None | 4e3708dc-0b32-479c-aa16-d3ea209784ce | | 0d1c865c-b7a5-4752-b78d-60bff2974f83 | None | None | | None | 84806096-7de0-4e95-8e50-68ca586c685e | | 0e9c60c1-cfe0-4fb5-8237-c363becc13a9 | None | None | | None | 84806096-7de0-4e95-8e50-68ca586c685e | | 426cd691-af75-4c9f-9eaf-8726a5376695 | None | None | | 4e3708dc-0b32-479c-aa16-d3ea209784ce | 4e3708dc-0b32-479c-aa16-d3ea209784ce | | 5688a833-5b5b-49a8-a02a-12ea32c7db27 | None | None | | None | 4e3708dc-0b32-479c-aa16-d3ea209784ce | | 5e81e02e-1218-4545-8bb5-16f4844e63e7 | None | None | | 4e3708dc-0b32-479c-aa16-d3ea209784ce | 4e3708dc-0b32-479c-aa16-d3ea209784ce | | c719567b-d50b-4c49-be93-7c0c9f3aefff | icmp | 0.0.0.0/0 | | None | 84806096-7de0-4e95-8e50-68ca586c685e | | d79df6f9-379f-419d-be40-e290c0fb5552 | tcp | 0.0.0.0/0 | 22:22 | None | 84806096-7de0-4e95-8e50-68ca586c685e | +--------------------------------------+-------------+-----------+------------+--------------------------------------+--------------------------------------+ |
[3] | 起動した仮想マシンインスタンスに SSH ログインします。 |
ubuntu@dlp ~(keystone)$ openstack server list +--------------------------------------+-------------+--------+-----------------------+------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-------------+--------+-----------------------+------------+----------+ | 87d3a97d-2acc-490a-b94c-d567e0b89317 | Ubuntu_1804 | ACTIVE | sharednet1=10.0.0.203 | Ubuntu1804 | m1.small | +--------------------------------------+-------------+--------+-----------------------+------------+----------+ # ping 応答が返ってくれば OK ubuntu@dlp ~(keystone)$ ping 10.0.0.203 -c3 PING 10.0.0.203 (10.0.0.203) 56(84) bytes of data. 64 bytes from 10.0.0.203: icmp_seq=1 ttl=64 time=2.54 ms 64 bytes from 10.0.0.203: icmp_seq=2 ttl=64 time=0.841 ms 64 bytes from 10.0.0.203: icmp_seq=3 ttl=64 time=0.690 ms --- 10.0.0.203 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2003ms rtt min/avg/max/mdev = 0.690/1.358/2.543/0.840 ms # SSHでログイン ubuntu@dlp ~(keystone)$ ssh ubuntu@10.0.0.203
The authenticity of host '10.0.0.203 (10.0.0.203)' can't be established.
ECDSA key fingerprint is SHA256:c3l1JE8mIGMuRXBveXOdNPYOKMwGvdtmbH07ryI6DVM.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.203' (ECDSA) to the list of known hosts.
Welcome to Ubuntu 18.04.1 LTS (GNU/Linux 4.15.0-34-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Wed Sep 12 13:54:02 JST 2018
System load: 0.0 Processes: 87
Usage of /: 19.7% of 8.80GB Users logged in: 0
Memory usage: 6% IP address for ens3: 10.0.0.203
Swap usage: 0%
* Read about Ubuntu updates for L1 Terminal Fault Vulnerabilities
(L1TF).
- https://ubu.one/L1TF
* Want to make a highly secure kiosk, smart display or touchscreen?
Here's a step-by-step tutorial for a rainy weekend, or a startup.
- https://bit.ly/secure-kiosk
0 packages can be updated.
0 updates are security updates.
Last login: Tue Sep 11 19:01:14 2018
ubuntu@ubuntu-1804:~$ # ログインできた |
[4] | 一旦作成して起動した仮想マシンインスタンスを停止/起動する場合は、以下のように start/stop コマンドで制御できます。 |
ubuntu@dlp ~(keystone)$ openstack server list +--------------------------------------+-------------+--------+-----------------------+------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-------------+--------+-----------------------+------------+----------+ | 87d3a97d-2acc-490a-b94c-d567e0b89317 | Ubuntu_1804 | ACTIVE | sharednet1=10.0.0.203 | Ubuntu1804 | m1.small | +--------------------------------------+-------------+--------+-----------------------+------------+----------+ # インスタンス停止 ubuntu@dlp ~(keystone)$ openstack server stop Ubuntu_1804 ubuntu@dlp ~(keystone)$ openstack server list +--------------------------------------+-------------+---------+-----------------------+------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-------------+---------+-----------------------+------------+----------+ | 87d3a97d-2acc-490a-b94c-d567e0b89317 | Ubuntu_1804 | SHUTOFF | sharednet1=10.0.0.203 | Ubuntu1804 | m1.small | +--------------------------------------+-------------+---------+-----------------------+------------+----------+ # インスタンスを起動する ubuntu@dlp ~(keystone)$ openstack server start Ubuntu_1804 ubuntu@dlp ~(keystone)$ openstack server list +--------------------------------------+-------------+--------+-----------------------+------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-------------+--------+-----------------------+------------+----------+ | 87d3a97d-2acc-490a-b94c-d567e0b89317 | Ubuntu_1804 | ACTIVE | sharednet1=10.0.0.203 | Ubuntu1804 | m1.small | +--------------------------------------+-------------+--------+-----------------------+------------+----------+ |
[5] | VNC コンソールを取得して Web ブラウザでのアクセスも可能です。 |
ubuntu@dlp ~(keystone)$ openstack server list +--------------------------------------+-------------+--------+-----------------------+------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-------------+--------+-----------------------+------------+----------+ | 87d3a97d-2acc-490a-b94c-d567e0b89317 | Ubuntu_1804 | ACTIVE | sharednet1=10.0.0.203 | Ubuntu1804 | m1.small | +--------------------------------------+-------------+--------+-----------------------+------------+----------+ubuntu@dlp ~(keystone)$ openstack console url show Ubuntu_1804 +-------+--------------------------------------------------------------------------------+ | Field | Value | +-------+--------------------------------------------------------------------------------+ | type | novnc | | url | http://10.0.0.30:6080/vnc_auto.html?token=52339a19-90fa-457a-a9c9-7a61abb8511b | +-------+--------------------------------------------------------------------------------+ |
[6] | 上記コマンドで表示された URL に Web アクセスすると、インスタンスに接続され、操作が可能となります。 |
Sponsored Link |