next up previous contents
Next: 測試 Instances 虛擬機 Up: Nova Compute and Controller Previous: Nova 安裝   Contents

建立 Instances

  1. 改變環境變數為一般使用者 myuser。
    [root@kvm4 ~(keystone_admin)]# source keystonerc_myuser 
    [root@kvm4 ~(keystone_myuser)]#
    
  2. 複製終端機訊息提示檔至 /tmp 目錄,並加入一行提示此 instance 是由 nova 命令安裝。
    [root@kvm4 ~(keystone_myuser)]# cp /etc/issue /tmp/
    [root@kvm4 ~(keystone_myuser)]# echo "Installed using nova comman-line" >> /tmp/issue
    
  3. 產生一組新的 SSH 登入鑰匙,名為 key1,存於 /root 目錄下。
    [root@kvm4 ~(keystone_myuser)]# nova keypair-add key1 > /root/key1.pem
    [root@kvm4 ~(keystone_myuser)]# ll /root/key1.pem 
    -rw-r--r--. 1 root root 1676 Jan 25 16:11 /root/key1.pem
    
  4. 產生新的 security group,名為 mysecgroup。
    [root@kvm4 ~(keystone_myuser)]# nova secgroup-create mysecgroup "SSH"
    +------------+-------------+
    | Name       | Description |
    +------------+-------------+
    | mysecgroup | SSH         |
    +------------+-------------+
    
  5. mysecgroup 允許 0.0.0.0/0 以 TCP/22 port 連結,也就是所有 ip 皆可以 TCP 協定連接 22 port。
    [root@kvm4 ~(keystone_myuser)]# nova secgroup-add-rule mysecgroup tcp 22 22 0.0.0.0/0
    +-------------+-----------+---------+-----------+--------------+
    | IP Protocol | From Port | To Port | IP Range  | Source Group |
    +-------------+-----------+---------+-----------+--------------+
    | tcp         | 22        | 22      | 0.0.0.0/0 |              |
    +-------------+-----------+---------+-----------+--------------+
    
  6. 建立 instance 必須知道使用的 image, flavor, net 等 id 或名稱。查詢 image id。
    [root@kvm4 ~(keystone_myuser)]# nova image-list 
    +--------------------------------------+--------+--------+--------+
    | ID                                   | Name   | Status | Server |
    +--------------------------------------+--------+--------+--------+
    | 79e088a9-0d8c-40fc-b5d5-13865cc891d2 | minkvm | ACTIVE |        |
    +--------------------------------------+--------+--------+--------+
    
  7. 查詢 flavor 名稱。
    [root@kvm4 ~(keystone_myuser)]# nova flavor-list 
    +----+-----------+-----------+------+-----------+------+-------+-------------+-----------+-------------+
    | ID | Name      | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public | extra_specs |
    +----+-----------+-----------+------+-----------+------+-------+-------------+-----------+-------------+
    | 1  | m1.tiny   | 512       | 0    | 0         |      | 1     | 1.0         | True      | {}          |
    | 2  | m1.small  | 2048      | 20   | 0         |      | 1     | 1.0         | True      | {}          |
    | 3  | m1.medium | 4096      | 40   | 0         |      | 2     | 1.0         | True      | {}          |
    | 4  | m1.large  | 8192      | 80   | 0         |      | 4     | 1.0         | True      | {}          |
    | 5  | m1.xlarge | 16384     | 160  | 0         |      | 8     | 1.0         | True      | {}          |
    +----+-----------+-----------+------+-----------+------+-------+-------------+-----------+-------------+
    
  8. 查詢網路 id。
    [root@kvm4 ~(keystone_myuser)]# quantum net-list
    +--------------------------------------+---------+------------------------------------------------------+
    | id                                   | name    | subnets                                              |
    +--------------------------------------+---------+------------------------------------------------------+
    | 48e9c08e-158d-4c6a-9623-b4eeaea5716c | private | af75410d-6cf3-457c-a393-891641e563db 192.168.32.0/24 |
    | f9179863-802b-4a9c-b711-206dc9a5a9b4 | public  | 76055bb3-ebb3-4e75-8971-64d90c5d8af6                 |
    +--------------------------------------+---------+------------------------------------------------------+
    
  9. 使用 m1.tiny flavor, minkvm image, key1 key, mysecgroup security group, private network ID and /tmp/issue file 產生 instance,名為 minkvm。
    [root@kvm4 ~(keystone_myuser)]# nova boot --flavor m1.tiny \
    --image minkvm --key-name key1 --security-group mysecgroup \
    --nic net-id=48e9c08e-158d-4c6a-9623-b4eeaea5716c \
    --file /etc/issue=/tmp/issue minkvm
    +-----------------------------+--------------------------------------+
    | Property                    | Value                                |
    +-----------------------------+--------------------------------------+
    | status                      | BUILD                                |
    | updated                     | 2014-01-26T23:00:51Z                 |
    | OS-EXT-STS:task_state       | scheduling                           |
    | key_name                    | key1                                 |
    | image                       | minkvm                               |
    | hostId                      |                                      |
    | OS-EXT-STS:vm_state         | building                             |
    | flavor                      | m1.tiny                              |
    | id                          | 97b5d1bd-9741-4098-b2a9-bd16d5373cb7 |
    | security_groups             | [{u'name': u'mysecgroup'}]           |
    | user_id                     | 9904d73f9a1841fa89381fccd2bc59df     |
    | name                        | minkvm                               |
    | adminPass                   | u7FqWFdcUdk5                         |
    | tenant_id                   | 6c26d132e38f4b83a1d9f5a777beeb52     |
    | created                     | 2014-01-26T23:00:50Z                 |
    | OS-DCF:diskConfig           | MANUAL                               |
    | metadata                    | {}                                   |
    | accessIPv4                  |                                      |
    | accessIPv6                  |                                      |
    | progress                    | 0                                    |
    | OS-EXT-STS:power_state      | 0                                    |
    | OS-EXT-AZ:availability_zone | nova                                 |
    | config_drive                |                                      |
    +-----------------------------+--------------------------------------+
    
  10. 使用 nova list 查看 instance 狀態,目前為建置中 (BUILD)。
    [root@kvm4 ~(keystone_myuser)]# nova list
    +--------------------------------------+--------+--------+----------+
    | ID                                   | Name   | Status | Networks |
    +--------------------------------------+--------+--------+----------+
    | 97b5d1bd-9741-4098-b2a9-bd16d5373cb7 | minkvm | BUILD  |          |
    +--------------------------------------+--------+--------+----------+
    
  11. 經過一段時間再查看 instance 已建置完成,狀態為啟動 (ACTIVE)。
    [root@kvm4 ~(keystone_myuser)]# nova list
    +--------------------------------------+--------+--------+----------------------+
    | ID                                   | Name   | Status | Networks             |
    +--------------------------------------+--------+--------+----------------------+
    | 97b5d1bd-9741-4098-b2a9-bd16d5373cb7 | minkvm | ACTIVE | private=192.168.32.2 |
    +--------------------------------------+--------+--------+----------------------+
    
  12. 若 instance 狀態為錯誤 (ERROR),必須查看建置過程紀錄檔 /var/log/nova/compute.log,錯誤的可能原因:
    1. 自行產生的 image 需要較大的 RAM,但指定使用的 flavor 不够大。
    2. 自行設計的作業系統,也就是匯入的 image 硬碟分割使用兩個 vg,但其中一個無法使用。
    3. 並不是任意的 image 檔都可使用,詳細請參考「自訂虛擬機 Images」9.6
  13. instance minkvm 指定的 ip 為 192.168.32.2,使用 quantum port-list 找到連結此 ip 的 port ID。
    [root@kvm4 ~(keystone_myuser)]# quantum port-list 
    +--------------------------------------+------+-------------------+-------------------------------------------------------------------------------------+
    | id                                   | name | mac_address       | fixed_ips                                                                           |
    +--------------------------------------+------+-------------------+-------------------------------------------------------------------------------------+
    | 79dd275e-7ac9-4e1c-82f6-f49d9409d014 |      | fa:16:3e:93:3b:37 | {"subnet_id": "af75410d-6cf3-457c-a393-891641e563db", "ip_address": "192.168.32.3"} |
    | 8febcb98-132d-4bf8-8189-dcf7184a15de |      | fa:16:3e:91:dc:9a | {"subnet_id": "af75410d-6cf3-457c-a393-891641e563db", "ip_address": "192.168.32.2"} |
    +--------------------------------------+------+-------------------+-------------------------------------------------------------------------------------+
    
  14. 找到浮動 ip 的 ID。
    [root@kvm4 ~(keystone_myuser)]# quantum floatingip-list 
    +--------------------------------------+------------------+---------------------+---------+
    | id                                   | fixed_ip_address | floating_ip_address | port_id |
    +--------------------------------------+------------------+---------------------+---------+
    | 9a01e37b-8927-4311-9b6e-9615df28eb0f |                  | 192.168.122.10      |         |
    +--------------------------------------+------------------+---------------------+---------+
    
  15. 連結 192.168.32.2 的 port 到指定的浮動 ip,讓 instance 可以連接外部網路。
    [root@kvm4 ~(keystone_myuser)]# quantum floatingip-associate \
    9a01e37b-8927-4311-9b6e-9615df28eb0f 8febcb98-132d-4bf8-8189-dcf7184a15de
    Associated floatingip 9a01e37b-8927-4311-9b6e-9615df28eb0f
    
  16. 再次查看浮動 ip 192.168.122.10 已連結到 192.168.32.2 的 port。
    [root@kvm4 ~(keystone_myuser)]# quantum floatingip-list 
    +--------------------------------------+------------------+---------------------+--------------------------------------+
    | id                                   | fixed_ip_address | floating_ip_address | port_id                              |
    +--------------------------------------+------------------+---------------------+--------------------------------------+
    | 9a01e37b-8927-4311-9b6e-9615df28eb0f | 192.168.32.2     | 192.168.122.10      | 8febcb98-132d-4bf8-8189-dcf7184a15de |
    +--------------------------------------+------------------+---------------------+--------------------------------------+
    
  17. 以 ssh 使用 key1.pem 登入 192.168.122.10。由於虛擬機開機較慢且自行製作的 image,有可能開機有問題,因而無法登入。建議先使用下一章的 dashboard 開啟網頁中的虛擬機 console,先看是否正常開機,且網路沒問題。
    [root@kvm4 ~(keystone_myuser)]# chmod 600 /root/key1.pem
    [root@kvm4 ~(keystone_myuser)]# ssh -i /root/key1.pem root@192.168.122.10
    The authenticity of host '192.168.122.10 (192.168.122.10)' can't be established.
    RSA key fingerprint is 14:9f:cd:45:1e:fe:cd:15:98:57:76:c9:18:99:77:49.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added '192.168.122.10' (RSA) to the list of known hosts.
    Last login: Sun Jan 26 21:28:13 2014
    [root@kvm3 ~]# hostname 
    kvm3.deyu.wang
    [root@kvm3 ~]#
    



2015-12-29