OpenStack Stein : インスタンスを起動する2019/04/11 |
仮想マシンインスタンスを起動します。
|
|
[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 | +--------------------------------------+------------+--------+ | 7690a3c0-99f7-40fe-8cde-343824edc74a | Ubuntu1804 | active | +--------------------------------------+------------+--------+ # 利用可能なネットワーク確認 ubuntu@dlp ~(keystone)$ openstack network list +--------------------------------------+------------+--------------------------------------+ | ID | Name | Subnets | +--------------------------------------+------------+--------------------------------------+ | bc5a7936-cec8-448a-a909-849967870262 | sharednet1 | 39aeb6bb-9d79-4cf8-8aea-030960e70419 | +--------------------------------------+------------+--------------------------------------+ # インスタンス用のセキュリティグループを作成 ubuntu@dlp ~(keystone)$ openstack security group create secgroup01 +-----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Field | Value | +-----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | created_at | 2019-04-11T04:13:40Z | | description | secgroup01 | | id | 257f3400-74fd-4087-a349-b31b48855690 | | location | Munch({'project': Munch({'domain_name': 'default', 'domain_id': None, 'name': 'hiroshima', 'id': u'47bbc20de1664134814c07e4ff2b93df'}), 'cloud': '', 'region_name': '', 'zone': None}) | | name | secgroup01 | | project_id | 47bbc20de1664134814c07e4ff2b93df | | revision_number | 1 | | rules | created_at='2019-04-11T04:13:40Z', direction='egress', ethertype='IPv4', id='911ff2c1-9d18-41b8-92f5-da86c8777613', updated_at='2019-04-11T04:13:40Z' | | | created_at='2019-04-11T04:13:40Z', direction='egress', ethertype='IPv6', id='dfc1c19a-773c-42b8-be2f-8094fe53fe07', updated_at='2019-04-11T04:13:40Z' | | tags | [] | | updated_at | 2019-04-11T04:13:40Z | +-----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ubuntu@dlp ~(keystone)$ openstack security group list +--------------------------------------+------------+------------------------+----------------------------------+------+ | ID | Name | Description | Project | Tags | +--------------------------------------+------------+------------------------+----------------------------------+------+ | 257f3400-74fd-4087-a349-b31b48855690 | secgroup01 | secgroup01 | 47bbc20de1664134814c07e4ff2b93df | [] | | aa4c9504-2cab-404c-8f75-cca4fbfb4093 | default | Default security group | 47bbc20de1664134814c07e4ff2b93df | [] | +--------------------------------------+------------+------------------------+----------------------------------+------+ # インスタンス接続用の 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 | 52:32:e8:73:23:cc:4e:8a:15:4f:13:14:48:8f:2b:50 | | name | mykey | | user_id | 131ac57aad644676918e3dd628425447 | +-------------+-------------------------------------------------+ubuntu@dlp ~(keystone)$ openstack keypair list +-------+-------------------------------------------------+ | Name | Fingerprint | +-------+-------------------------------------------------+ | mykey | 52:32:e8:73:23:cc:4e:8a:15:4f:13:14:48:8f:2b:50 | +-------+-------------------------------------------------+
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 | Z7PUSwHoM4Nz | | config_drive | | | created | 2019-04-11T05:56:04Z | | flavor | m1.small (0) | | hostId | | | id | e933cf7c-9651-47d9-9a25-6a6879844a69 | | image | Ubuntu1804 (7690a3c0-99f7-40fe-8cde-343824edc74a) | | key_name | mykey | | name | Ubuntu_1804 | | progress | 0 | | project_id | 47bbc20de1664134814c07e4ff2b93df | | properties | | | security_groups | name='257f3400-74fd-4087-a349-b31b48855690' | | status | BUILD | | updated | 2019-04-11T05:56:05Z | | user_id | 131ac57aad644676918e3dd628425447 | | volumes_attached | | +-----------------------------+---------------------------------------------------+ # 動作確認 (起動直後しばらくは [BUILD] ステータスとなっている) ubuntu@dlp ~(keystone)$ openstack server list +--------------------------------------+-------------+--------+----------+------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-------------+--------+----------+------------+----------+ | e933cf7c-9651-47d9-9a25-6a6879844a69 | Ubuntu_1804 | BUILD | | Ubuntu1804 | m1.small | +--------------------------------------+-------------+--------+----------+------------+----------+ # 正常に起動すると [ACTIVE] ステータスとなる ubuntu@dlp ~(keystone)$ openstack server list +--------------------------------------+-------------+--------+-----------------------+------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-------------+--------+-----------------------+------------+----------+ | e933cf7c-9651-47d9-9a25-6a6879844a69 | Ubuntu_1804 | ACTIVE | sharednet1=10.0.0.232 | Ubuntu1804 | m1.small | +--------------------------------------+-------------+--------+-----------------------+------------+----------+ |
[2] | 起動した仮想マシンインスタンスに SSH 接続できるように、先に作成したセキュリティグループにポート許可の設定を追加します。 |
# ICMP 許可 ubuntu@dlp ~(keystone)$ openstack security group rule create --protocol icmp --ingress secgroup01 +-------------------+--------------------------------------------------------------------------------------------------------+ | Field | Value | +-------------------+--------------------------------------------------------------------------------------------------------+ | created_at | 2019-04-11T05:58:47Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 14e3675b-4bf8-454b-9a9f-0314e5909bb5 | | location | Munch({'project': Munch({'domain_name': 'default', 'domain_id': None, 'name': 'hiroshima', 'id': u...) | | name | None | | port_range_max | None | | port_range_min | None | | project_id | 47bbc20de1664134814c07e4ff2b93df | | protocol | icmp | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 0 | | security_group_id | 257f3400-74fd-4087-a349-b31b48855690 | | tags | [] | | updated_at | 2019-04-11T05:58:47Z | +-------------------+--------------------------------------------------------------------------------------------------------+ # SSH 許可 ubuntu@dlp ~(keystone)$ openstack security group rule create --protocol tcp --dst-port 22:22 secgroup01 +-------------------+--------------------------------------------------------------------------------------------------------+ | Field | Value | +-------------------+--------------------------------------------------------------------------------------------------------+ | created_at | 2019-04-11T05:59:22Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 53e4a27f-9eaf-4587-87d0-f06b640b6ef9 | | location | Munch({'project': Munch({'domain_name': 'default', 'domain_id': None, 'name': 'hiroshima', 'id': u...) | | name | None | | port_range_max | 22 | | port_range_min | 22 | | project_id | 47bbc20de1664134814c07e4ff2b93df | | protocol | tcp | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 0 | | security_group_id | 257f3400-74fd-4087-a349-b31b48855690 | | tags | [] | | updated_at | 2019-04-11T05:59:22Z | +-------------------+--------------------------------------------------------------------------------------------------------+ubuntu@dlp ~(keystone)$ openstack security group rule list +--------------------------------------+-------------+-----------+------------+--------------------------------------+--------------------------------------+ | ID | IP Protocol | IP Range | Port Range | Remote Security Group | Security Group | +--------------------------------------+-------------+-----------+------------+--------------------------------------+--------------------------------------+ | 0cd872cb-25e2-4383-842a-ac8c3a35eadf | None | None | | None | aa4c9504-2cab-404c-8f75-cca4fbfb4093 | | 14e3675b-4bf8-454b-9a9f-0314e5909bb5 | icmp | 0.0.0.0/0 | | None | 257f3400-74fd-4087-a349-b31b48855690 | | 382b1b1c-2619-415f-9118-deaeee3de546 | None | None | | None | aa4c9504-2cab-404c-8f75-cca4fbfb4093 | | 53e4a27f-9eaf-4587-87d0-f06b640b6ef9 | tcp | 0.0.0.0/0 | 22:22 | None | 257f3400-74fd-4087-a349-b31b48855690 | | 8731f52b-5025-463a-be51-8515912e4611 | None | None | | aa4c9504-2cab-404c-8f75-cca4fbfb4093 | aa4c9504-2cab-404c-8f75-cca4fbfb4093 | | 911ff2c1-9d18-41b8-92f5-da86c8777613 | None | None | | None | 257f3400-74fd-4087-a349-b31b48855690 | | deda7937-c710-4ae4-ab11-16876bf353de | None | None | | aa4c9504-2cab-404c-8f75-cca4fbfb4093 | aa4c9504-2cab-404c-8f75-cca4fbfb4093 | | dfc1c19a-773c-42b8-be2f-8094fe53fe07 | None | None | | None | 257f3400-74fd-4087-a349-b31b48855690 | +--------------------------------------+-------------+-----------+------------+--------------------------------------+--------------------------------------+ |
[3] | 起動した仮想マシンインスタンスに SSH ログインします。 |
ubuntu@dlp ~(keystone)$ openstack server list +--------------------------------------+-------------+--------+-----------------------+------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-------------+--------+-----------------------+------------+----------+ | e933cf7c-9651-47d9-9a25-6a6879844a69 | Ubuntu_1804 | ACTIVE | sharednet1=10.0.0.232 | Ubuntu1804 | m1.small | +--------------------------------------+-------------+--------+-----------------------+------------+----------+ # ping 応答が返ってくれば OK ubuntu@dlp ~(keystone)$ ping 10.0.0.232 -c3 PING 10.0.0.232 (10.0.0.232) 56(84) bytes of data. 64 bytes from 10.0.0.232: icmp_seq=1 ttl=64 time=2.07 ms 64 bytes from 10.0.0.232: icmp_seq=2 ttl=64 time=0.828 ms 64 bytes from 10.0.0.232: icmp_seq=3 ttl=64 time=0.827 ms --- 10.0.0.232 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2003ms rtt min/avg/max/mdev = 0.827/1.243/2.074/0.587 ms # SSHでログイン ubuntu@dlp ~(keystone)$ ssh ubuntu@10.0.0.232
The authenticity of host '10.0.0.232 (10.0.0.232)' can't be established.
ECDSA key fingerprint is SHA256:p8bYXVZZ3jp53OOcWOpYqDTP3l4qr7VgTSup0w47SA4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.232' (ECDSA) to the list of known hosts.
Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0-47-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Thu Apr 11 15:00:52 JST 2019
System load: 0.02 Processes: 88
Usage of /: 19.6% of 8.80GB Users logged in: 0
Memory usage: 6% IP address for ens3: 10.0.0.232
Swap usage: 0%
* Ubuntu's Kubernetes 1.14 distributions can bypass Docker and use containerd
directly, see https://bit.ly/ubuntu-containerd or try it now with
snap install microk8s --classic
2 packages can be updated.
0 updates are security updates.
ubuntu@ubuntu-1804:~$ # ログインできた |
[4] | 一旦作成して起動した仮想マシンインスタンスを停止/起動する場合は、以下のように start/stop コマンドで制御できます。 |
ubuntu@dlp ~(keystone)$ openstack server list +--------------------------------------+-------------+--------+-----------------------+------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-------------+--------+-----------------------+------------+----------+ | e933cf7c-9651-47d9-9a25-6a6879844a69 | Ubuntu_1804 | ACTIVE | sharednet1=10.0.0.232 | Ubuntu1804 | m1.small | +--------------------------------------+-------------+--------+-----------------------+------------+----------+ # インスタンス停止 ubuntu@dlp ~(keystone)$ openstack server stop Ubuntu_1804 ubuntu@dlp ~(keystone)$ openstack server list +--------------------------------------+-------------+---------+-----------------------+------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-------------+---------+-----------------------+------------+----------+ | e933cf7c-9651-47d9-9a25-6a6879844a69 | Ubuntu_1804 | SHUTOFF | sharednet1=10.0.0.232 | Ubuntu1804 | m1.small | +--------------------------------------+-------------+---------+-----------------------+------------+----------+ # インスタンスを起動する ubuntu@dlp ~(keystone)$ openstack server start Ubuntu_1804 ubuntu@dlp ~(keystone)$ openstack server list +--------------------------------------+-------------+--------+-----------------------+------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-------------+--------+-----------------------+------------+----------+ | e933cf7c-9651-47d9-9a25-6a6879844a69 | Ubuntu_1804 | ACTIVE | sharednet1=10.0.0.232 | Ubuntu1804 | m1.small | +--------------------------------------+-------------+--------+-----------------------+------------+----------+ |
[5] | VNC コンソールを取得して Web ブラウザでのアクセスも可能です。 |
ubuntu@dlp ~(keystone)$ openstack server list +--------------------------------------+-------------+--------+-----------------------+------------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+-------------+--------+-----------------------+------------+----------+ | e933cf7c-9651-47d9-9a25-6a6879844a69 | Ubuntu_1804 | ACTIVE | sharednet1=10.0.0.232 | 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=65bdb428-cff4-4283-827b-02489f477bf3 | +-------+--------------------------------------------------------------------------------+ |
[6] | 上記コマンドで表示された URL に Web アクセスすると、インスタンスに接続され、操作が可能となります。 |
Sponsored Link |
|