OpenStack Ocata : インスタンスを起動する2017/02/27 |
仮想マシンインスタンスを起動します。
|
|
[1] | 仮想マシンインスタンスに割り当てるメモリ容量やストレージ容量等々の定義 (flavor) を作成し、インスタンスを作成して起動します。 |
# flavor 作成 [root@dlp ~(keystone)]# openstack flavor create --id 0 --vcpus 1 --ram 2048 --disk 10 m1.small +----------------------------+----------+ | Field | Value | +----------------------------+----------+ | OS-FLV-DISABLED:disabled | False | | OS-FLV-EXT-DATA:ephemeral | 0 | | disk | 10 | | id | 0 | | name | m1.small | | os-flavor-access:is_public | True | | properties | | | ram | 2048 | | rxtx_factor | 1.0 | | swap | | | vcpus | 1 | +----------------------------+----------+[root@dlp ~(keystone)]# openstack flavor list +----+----------+------+------+-----------+-------+-----------+ | ID | Name | RAM | Disk | Ephemeral | VCPUs | Is Public | +----+----------+------+------+-----------+-------+-----------+ | 0 | m1.small | 2048 | 10 | 0 | 1 | True | +----+----------+------+------+-----------+-------+-----------+ # 利用可能なイメージ [root@dlp ~(keystone)]# openstack image list +--------------------------------------+---------+--------+ | ID | Name | Status | +--------------------------------------+---------+--------+ | c8f1484e-b877-4447-b6ce-f1baa6bef785 | CentOS7 | active | +--------------------------------------+---------+--------+ # 利用可能なネットワーク [root@dlp ~(keystone)]# openstack network list +--------------------------------------+------------+--------------------------------------+ | ID | Name | Subnets | +--------------------------------------+------------+--------------------------------------+ | 20f54b04-74a2-44e3-a187-e0fa1e7289e7 | sharednet1 | 4ae2ff30-ce64-4444-a770-08f350fa5a6d | +--------------------------------------+------------+--------------------------------------+
[root@dlp ~(keystone)]#
netID=`openstack network list | grep sharednet1 | awk '{ print $2 }'` # インスタンス作成・起動 [root@dlp ~(keystone)]# openstack server create --flavor m1.small --image CentOS7 --security-group default --nic net-id=$netID CentOS_7 +-------------------------------------+------------------------------------------------+ | Field | Value | +-------------------------------------+------------------------------------------------+ | OS-DCF:diskConfig | MANUAL | | OS-EXT-AZ:availability_zone | | | OS-EXT-SRV-ATTR:host | None | | OS-EXT-SRV-ATTR:hypervisor_hostname | None | | OS-EXT-SRV-ATTR:instance_name | | | 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 | 4PkvwmeLorP2 | | config_drive | | | created | 2017-02-28T07:47:14Z | | flavor | m1.small (0) | | hostId | | | id | da129ae7-dc41-4c9b-b6c3-a8e073a9bbcb | | image | CentOS7 (c8f1484e-b877-4447-b6ce-f1baa6bef785) | | key_name | None | | name | CentOS_7 | | progress | 0 | | project_id | c654e2e098b14356b97b6e613775cc54 | | properties | | | security_groups | name='default' | | status | BUILD | | updated | 2017-02-28T07:47:15Z | | user_id | cf3c5cbcdd214707b91d322a69af038e | | volumes_attached | | +-------------------------------------+------------------------------------------------+ # 動作確認 (起動直後しばらくは [BUILD] ステータスとなっている) [root@dlp ~(keystone)]# openstack server list +--------------------------------------+----------+--------+-----------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------------------------+----------+--------+-----------------------+------------+ | da129ae7-dc41-4c9b-b6c3-a8e073a9bbcb | CentOS_7 | BUILD | sharednet1=10.0.0.201 | CentOS7 | +--------------------------------------+----------+--------+-----------------------+------------+ # 正常に起動すると [ACTIVE] ステータスとなる [root@dlp ~(keystone)]# openstack server list +--------------------------------------+----------+--------+-----------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------------------------+----------+--------+-----------------------+------------+ | da129ae7-dc41-4c9b-b6c3-a8e073a9bbcb | CentOS_7 | ACTIVE | sharednet1=10.0.0.201 | CentOS7 | +--------------------------------------+----------+--------+-----------------------+------------+ |
[2] | 起動した仮想マシンインスタンスに SSH 接続できるように、デフォルトセキュリティグループにポート許可の設定を追加します。 |
# ICMP 許可 [root@dlp ~(keystone)]# openstack security group rule create --protocol icmp --ingress default +-------------------+--------------------------------------+ | Field | Value | +-------------------+--------------------------------------+ | created_at | 2017-02-28T07:54:12Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 180e4ec7-9221-42fb-bdba-382c5a06a8f4 | | name | None | | port_range_max | None | | port_range_min | None | | project_id | c654e2e098b14356b97b6e613775cc54 | | protocol | icmp | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 1 | | security_group_id | 160e1d9e-72b9-4ed3-a434-276518f22a7b | | updated_at | 2017-02-28T07:54:12Z | +-------------------+--------------------------------------+ # SSH 許可 [root@dlp ~(keystone)]# openstack security group rule create --protocol tcp --dst-port 22:22 default +-------------------+--------------------------------------+ | Field | Value | +-------------------+--------------------------------------+ | created_at | 2017-02-28T07:55:14Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 93a858de-87b5-4544-8d23-ef4f24da5f3b | | name | None | | port_range_max | 22 | | port_range_min | 22 | | project_id | c654e2e098b14356b97b6e613775cc54 | | protocol | tcp | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 1 | | security_group_id | 160e1d9e-72b9-4ed3-a434-276518f22a7b | | updated_at | 2017-02-28T07:55:14Z | +-------------------+--------------------------------------+[root@dlp ~(keystone)]# openstack security group rule list +-------------------+-------------+-----------+------------+--------------------------------------+--------------+ | ID | IP Protocol | IP Range | Port Range | Remote Security Group | Security Gro | +-------------------+-------------+-----------+------------+--------------------------------------+--------------+ | 180e4ec7-9221-... | icmp | 0.0.0.0/0 | | None | 160e1d9e-... | | 29b38eb3-2004-... | None | None | | 160e1d9e-72b9-4ed3-a434-276518f22a7b | 160e1d9e-... | | 93a858de-87b5-... | tcp | 0.0.0.0/0 | 22:22 | None | 160e1d9e-... | | 9f86c90e-6357-... | None | None | | None | 160e1d9e-... | | a1feacc0-c8ea-... | None | None | | None | 160e1d9e-... | | f46d96c3-235a-... | None | None | | 160e1d9e-72b9-4ed3-a434-276518f22a7b | 160e1d9e-... | +-------------------+-------------+-----------+------------+--------------------------------------+--------------+ |
[3] | 起動した仮想マシンインスタンスに SSH ログインします。 |
[root@dlp ~(keystone)]# openstack server list +--------------------------------------+----------+--------+-----------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------------------------+----------+--------+-----------------------+------------+ | da129ae7-dc41-4c9b-b6c3-a8e073a9bbcb | CentOS_7 | ACTIVE | sharednet1=10.0.0.201 | CentOS7 | +--------------------------------------+----------+--------+-----------------------+------------+ # ping 応答が返ってくれば OK [root@dlp ~(keystone)]# ping 10.0.0.201 PING 10.0.0.201 (10.0.0.201) 56(84) bytes of data. 64 bytes from 10.0.0.201: icmp_seq=1 ttl=63 time=2.17 ms 64 bytes from 10.0.0.201: icmp_seq=2 ttl=64 time=0.920 ms ^C --- 10.0.0.201 ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1001ms rtt min/avg/max/mdev = 0.920/1.546/2.173/0.627 ms # SSH ログイン [root@dlp ~(keystone)]# ssh 10.0.0.201 The authenticity of host '10.0.0.201 (10.0.0.201)' can't be established. ECDSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '10.0.0.201' (ECDSA) to the list of known hosts. root@10.0.0.201's password: # イメージ作成時に設定したrootパスワード Last login: Tue Feb 28 15:47:44 2017[root@host-10-0-0-201 ~]# # ログインできた |
[4] | インターネットから取得した仮想マシンイメージを利用中でパスワードが不明な場合は、SSH 鍵を登録することでログイン可能です。 自身で作成したイメージの場合は、前もって仮想マシンイメージに「cloud-init」パッケージをインストールし、「cloud-init」サービスを有効にしておくことで、SSH 鍵でのログインが可能となります。ちなみに、cloud-init のデフォルト設定は「centos」が SSH 接続ユーザーとなっています。 |
# キーペア作成 [root@dlp ~(keystone)]# ssh-keygen -q -N "" Enter file in which to save the key (/root/.ssh/id_rsa): # 公開鍵登録 [root@dlp ~(keystone)]# openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey +-------------+-------------------------------------------------+ | Field | Value | +-------------+-------------------------------------------------+ | fingerprint | 23:a9:8c:a2:61:57:ff:77:bc:11:45:ca:ca:d7:c2:7e | | name | mykey | | user_id | cf3c5cbcdd214707b91d322a69af038e | +-------------+-------------------------------------------------+[root@dlp ~(keystone)]# openstack keypair list +-------+-------------------------------------------------+ | Name | Fingerprint | +-------+-------------------------------------------------+ | mykey | 23:a9:8c:a2:61:57:ff:77:bc:11:45:ca:ca:d7:c2:7e | +-------+-------------------------------------------------+ # キーを指定してインスタンス作成・起動 [root@dlp ~(keystone)]# openstack server create --flavor m1.small --image CentOS7 --security-group default --nic net-id=$netID --key-name mykey CentOS_7
openstack server list +--------------------------------------+----------+--------+-----------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------------------------+----------+--------+-----------------------+------------+ | 130c2b1b-5055-47ff-a12f-d3c4cd53534b | CentOS_7 | ACTIVE | sharednet1=10.0.0.194 | CentOS7 | +--------------------------------------+----------+--------+-----------------------+------------+ # キーを指定してログイン [root@dlp ~(keystone)]# ssh -i mykey centos@10.0.0.194
# ログインできた |
[5] | 一旦作成して起動した仮想マシンインスタンスを停止/起動する場合は、以下のように start/stop コマンドで制御できます。 |
[root@dlp ~(keystone)]# openstack server list +--------------------------------------+----------+--------+-----------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------------------------+----------+--------+-----------------------+------------+ | 0b696343-1e50-4a1f-ad95-92f697e8551e | CentOS_7 | ACTIVE | sharednet1=10.0.0.201 | CentOS7 | +--------------------------------------+----------+--------+-----------------------+------------+ # インスタンス停止 [root@dlp ~(keystone)]# openstack server stop CentOS_7 [root@dlp ~(keystone)]# openstack server list +--------------------------------------+----------+---------+-----------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------------------------+----------+---------+-----------------------+------------+ | 0b696343-1e50-4a1f-ad95-92f697e8551e | CentOS_7 | SHUTOFF | sharednet1=10.0.0.201 | CentOS7 | +--------------------------------------+----------+---------+-----------------------+------------+ # インスタンスを起動する [root@dlp ~(keystone)]# openstack server start CentOS_7 [root@dlp ~(keystone)]# openstack server list +--------------------------------------+----------+--------+-----------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------------------------+----------+--------+-----------------------+------------+ | 0b696343-1e50-4a1f-ad95-92f697e8551e | CentOS_7 | ACTIVE | sharednet1=10.0.0.201 | CentOS7 | +--------------------------------------+----------+--------+-----------------------+------------+ |
[6] | VNC コンソールを取得して Web ブラウザでのアクセスも可能です。 |
[root@dlp ~(keystone)]# openstack server list +--------------------------------------+----------+--------+-----------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------------------------+----------+--------+-----------------------+------------+ | 0b696343-1e50-4a1f-ad95-92f697e8551e | CentOS_7 | ACTIVE | sharednet1=10.0.0.201 | CentOS7 | +--------------------------------------+----------+--------+-----------------------+------------+[root@dlp ~(keystone)]# openstack console url show CentOS_7 +-------+--------------------------------------------------------------------------------+ | Field | Value | +-------+--------------------------------------------------------------------------------+ | type | novnc | | url | http://10.0.0.30:6080/vnc_auto.html?token=70092084-18f8-426f-a20c-61885043a522 | +-------+--------------------------------------------------------------------------------+ |
[7] | 上記コマンドで表示された URL にアクセスすると、インスタンスにアクセスして操作可能です。 |
Sponsored Link |