1. 程式人生 > >openstack--JUNO10搭建手冊整理6:Launch an instance 建立例項

openstack--JUNO10搭建手冊整理6:Launch an instance 建立例項

#在controller節點上利用OpenStack Networking(neutron)啟動一個例項 10.1建立金鑰對 大多數雲映象使用公鑰認證,這有別於傳統的使用者名稱/密碼認證。在啟動一個例項之前,你必須使用ssh-keygen命令生成一個金鑰對,並將公鑰新增到你的OpenStack環境。

10.1.1、執行demo環境變數指令碼 source demo-open

10.1.2、生成金鑰對 ssh-keygen

#一路回車預設

10.1.3、新增公鑰到OpenStack環境 nova keypair-add --pub-key ~/.ssh/id_rsa.pub demo-key

10.1.4、驗證公鑰是否新增成功

nova keypair-list
+----------+-------------------------------------------------+
| Name     | Fingerprint                                     |
+----------+-------------------------------------------------+
| demo-key | 25:c3:16:2a:f5:de:72:ad:ec:e5:88:93:d3:48:fa:c3 |
+----------+-------------------------------------------------+

10.2啟動一個例項 要啟動一個例項,你必須最少指定flavor(雲主機型別),image name(映象名),network(網路),security group(安全組),key(金鑰)和instance name(例項名)。

10.2.1檢視可用的flavor: # flavor用來指定一個虛擬的獨立分配的資源。包括cpu,記憶體和儲存。

nova flavor-list
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+
| ID | Name      | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public |
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+
| 1  | m1.tiny   | 512       | 1    | 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      |
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+

10.2.2列出可用的映象

nova image-list
+--------------------------------------+---------------------+--------+--------+
| ID                                   | Name                | Status | Server |
+--------------------------------------+---------------------+--------+--------+
| eb6d5a72-06fe-47c4-9506-25a629195a71 | cirros-0.3.3-x86_64 | ACTIVE |        |
+--------------------------------------+---------------------+--------+--------+

10.2.3列出可用的網路

neutron net-list

+--------------------------------------+----------+----------------------------------------------------+
| id                                   | name     | subnets                                            |
+--------------------------------------+----------+----------------------------------------------------+
| 42a1e473-cba8-4bf3-9c8c-4f5a91cb978d | demo-net | ae54ef75-a3fc-40db-b681-1963a44ebc35 10.68.88.0/24 |
| 99f734d9-92b6-4711-ba67-a99d0014e72d | ext-net  | 1623e5b8-8fb2-4876-8b5b-ec1690eeb252 20.20.20.0/24 |
+--------------------------------------+----------+----------------------------------------------------+

10.2.4列出可用的安全組

nova secgroup-list
+--------------------------------------+---------+-------------+
| Id                                   | Name    | Description |
+--------------------------------------+---------+-------------+
| 879ef16e-ccb9-4c27-bdb6-b968a76c4e91 | default | default     |
+--------------------------------------+---------+-------------+

10.2.5啟動例項

模板:nova boot --flavor m1.tiny --image cirros-0.3.3-x86_64 --nic net-id=DEMO_NET_ID --security-group default --key-name demo-key demo-instance1  (instance1 只是一個名字,也可以改成別的名字 )

[[email protected] ~]# nova boot --flavor m1.tiny --image cirros-0.3.3-x86_64 --nic net-id=42a1e473-cba8-4bf3-9c8c-4f5a91cb978d --security-group default --key-name demo-key demo-instance1
+--------------------------------------+------------------------------------------------------------+
| Property                             | Value                                                      |
+--------------------------------------+------------------------------------------------------------+
| OS-DCF:diskConfig                    | MANUAL                                                     |
| OS-EXT-AZ:availability_zone          | nova                                                       |
| OS-EXT-STS:power_state               | 0                                                          |
| OS-EXT-STS:task_state                | scheduling                                                 |
| OS-EXT-STS:vm_state                  | building                                                   |
| OS-SRV-USG:launched_at               | -                                                          |
| OS-SRV-USG:terminated_at             | -                                                          |
| accessIPv4                           |                                                            |
| accessIPv6                           |                                                            |
| adminPass                            | yC7utCmPDBgr                                               |
| config_drive                         |                                                            |
| created                              | 2018-10-08T09:41:45Z                                       |
| flavor                               | m1.tiny (1)                                                |
| hostId                               |                                                            |
| id                                   | 4dd1c8b7-1d26-437f-a9d8-c3de59cf3fe9                       |
| image                                | cirros-0.3.3-x86_64 (8dd678c1-2ec3-4a01-aa50-0351e5cdb51c) |
| key_name                             | demo-key                                                   |
| metadata                             | {}                                                         |
| name                                 | demo-instance1                                             |
| os-extended-volumes:volumes_attached | []                                                         |
| progress                             | 0                                                          |
| security_groups                      | default                                                    |
| status                               | BUILD                                                      |
| tenant_id                            | f9b371bdb07744b4893e8f3ec0502314                           |
| updated                              | 2018-10-08T09:41:46Z                                       |
| user_id                              | e4b4b5aaecb84d4b98183101560b2556                           |
+--------------------------------------+------------------------------------------------------------+

10.2.6檢視例項狀態

正常狀態

如果有報錯,請參考我下一篇文章。

10.3通過虛擬控制檯訪問你的例項

可進入以下介面:

login:cirros   password:cubswin:)

10.4遠端訪問你建立的例項 10.4.1新增規則到名為default的安全組: a.允許ICMP協議(ping):

nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0
+-------------+-----------+---------+-----------+--------------+
| IP Protocol | From Port | To Port | IP Range  | Source Group |
+-------------+-----------+---------+-----------+--------------+
| icmp        | -1        | -1      | 0.0.0.0/0 |              |
+-------------+-----------+---------+-----------+--------------+

b.允許ssh協議:

nova secgroup-add-rule default 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 |              |
+-------------+-----------+---------+-----------+--------------+

10.4.2在ext-net外部網路建立一個浮動IP地址:

neutron floatingip-create ext-net

+---------------------+--------------------------------------+
| Field               | Value                                |
+---------------------+--------------------------------------+
| fixed_ip_address    |                                      |
| floating_ip_address | 20.20.20.52                         |
| floating_network_id | 8f121516-2b8d-4944-a64d-4f5df5dd156f |
| id                  | 54b0c4bc-3f94-480b-a34b-d6834ef01e2c |
| port_id             |                                      |
| router_id           |                                      |
| status              | DOWN                                 |
| tenant_id           | bb494ab439a94165998b791880eacd0e     |
+---------------------+--------------------------------------+

10.4.3分配浮動IP地址到你的例項: nova floating-ip-associate demo-instance2 20.20.20.52 10.4.4檢查你的浮動IP地址狀態:

nova list
+-----------------------------------+----------------+--------+------------+-------------+----------------------------------+
| ID                                | Name           | Status | Task State | Power State | Networks                         |
+-----------------------------------+----------------+--------+------------+-------------+----------------------------------+
| 4ddb7-1d26-437f-a9d8-c3de59cf3fe9 | demo-instance2 | ACTIVE | -          | Running     | demo-net=10.68.88.4, 20.20.20.52 |
+-----------------------------------+----------------+--------+------------+-------------+----------------------------------+

10.4.5測試

用x-shellwgbf20.20.20.52,建立1.txt,novnc檢視

在vnc虛擬主機中可以看到剛才建立的1.txt

由此可知:10.68.88.4與 20.20.20.52繫結是成功的,20.20.20.52為外網提供訪問的ip,但實際ip為建立的10.68.88.4

你可以進入openstack web頁面自己去試一下,怎麼快速建立一個主機,怎麼給它分配ip,繫結外部網路,在此,我就不再一一細說了。

至此,有關openstack專案的所有實驗均已完畢,如果你能看到這,謝謝你,把我寫的這些有用的,沒用的都看一邊。

學無止境,繼續努力向前!