在openstack上建立第一個虛擬機

1、建立虛擬網絡

第一次建立虛擬機,使用命令行來建立
node


在控制節點上,加載 admin 憑證來獲取管理員能執行的命令訪問權限linux

[root@linux-node1 ~]# source admin-openstack.sh

建立提供者網絡shell

[root@linux-node1 ~]# neutron net-create --shared --provider:physical_network public --provider:network_type flat public-net
Created a new network:
+---------------------------+--------------------------------------+
| Field                     | Value                                |
+---------------------------+--------------------------------------+
| admin_state_up            | True                                 |
| availability_zone_hints   |                                      |
| availability_zones        |                                      |
| created_at                | 2016-11-09T17:03:20                  |
| description               |                                      |
| id                        | 2cbfb54c-b760-41e1-ba69-83131220463b |
| ipv4_address_scope        |                                      |
| ipv6_address_scope        |                                      |
| mtu                       | 1500                                 |
| name                      | public-net                           |
| port_security_enabled     | True                                 |
| provider:network_type     | flat                                 |
| provider:physical_network | public                               |
| provider:segmentation_id  |                                      |
| router:external           | False                                |
| shared                    | True                                 |
| status                    | ACTIVE                               |
| subnets                   |                                      |
| tags                      |                                      |
| tenant_id                 | 53f72af1420a4d098d48f2c82d7e9ec7     |
| updated_at                | 2016-11-09T17:03:20                  |
+---------------------------+--------------------------------------+
#參數解釋
#--provider:physical_network網絡類型選項,在配置文件中設置的爲public,public映射的是eth0端口
#--provider:network_type 提供者的網絡類型flat
#public-net是提供者網絡的名稱,按照本身的意願定義

查看已經建立的網絡安全

[root@linux-node1 ~]# neutron net-list
+--------------------------------------+------------+---------+
| id                                   | name       | subnets |
+--------------------------------------+------------+---------+
| 2cbfb54c-b760-41e1-ba69-83131220463b | public-net |         |
+--------------------------------------+------------+---------+

建立子網網絡

[root@linux-node1 ~]# neutron subnet-create --name public-subnet --allocation-pool start=192.168.56.100,end=192.168.56.200 --dns-nameserver 223.5.5.5 --gateway 192.168.56.2 public-net 192.168.56.0/24
Created a new subnet:
+-------------------+------------------------------------------------------+
| Field             | Value                                                |
+-------------------+------------------------------------------------------+
| allocation_pools  | {"start": "192.168.56.100", "end": "192.168.56.200"} |
| cidr              | 192.168.56.0/24                                      |
| created_at        | 2016-11-10T02:56:27                                  |
| description       |                                                      |
| dns_nameservers   | 223.5.5.5                                            |
| enable_dhcp       | True                                                 |
| gateway_ip        | 192.168.56.2                                         |
| host_routes       |                                                      |
| id                | 6e217cbe-3201-4b47-8765-84ba932afa93                 |
| ip_version        | 4                                                    |
| ipv6_address_mode |                                                      |
| ipv6_ra_mode      |                                                      |
| name              | public-subnet                                        |
| network_id        | 2cbfb54c-b760-41e1-ba69-83131220463b                 |
| subnetpool_id     |                                                      |
| tenant_id         | 53f72af1420a4d098d48f2c82d7e9ec7                     |
| updated_at        | 2016-11-10T02:56:27                                  |
+-------------------+------------------------------------------------------+

查看建立的子網ssh

[root@linux-node1 ~]# neutron subnet-list
+--------------------------------------+---------------+-----------------+------------------------------------------------------+
| id                                   | name          | cidr            | allocation_pools                                     |
+--------------------------------------+---------------+-----------------+------------------------------------------------------+
| 6e217cbe-3201-4b47-8765-84ba932afa93 | public-subnet | 192.168.56.0/24 | {"start": "192.168.56.100", "end": "192.168.56.200"} |
+--------------------------------------+---------------+-----------------+------------------------------------------------------+

再次執行neutron net-list,能夠看到建立的網絡與子網已經關聯在一塊兒tcp

[root@linux-node1 ~]# neutron net-list
+--------------------------------------+------------+------------------------------------------------------+
| id                                   | name       | subnets                                              |
+--------------------------------------+------------+------------------------------------------------------+
| 2cbfb54c-b760-41e1-ba69-83131220463b | public-net | 6e217cbe-3201-4b47-8765-84ba932afa93 192.168.56.0/24 |
+--------------------------------------+------------+------------------------------------------------------+

2、建立m1.nano規格的主機

一、建立一個nano規格的主機

默認的最小規格的主機須要512 MB內存。對於環境中計算節點內存不足4 GB的,咱們推薦建立只須要64 MB的m1.nano規格的主機。若單純爲了測試的目的,請使用m1.nano規格的主機來加載CirrOS鏡像ide

[root@linux-node1 ~]# openstack flavor create --id 0 --vcpus 1 --ram 64 --disk 1 m1.nano
+----------------------------+---------+
| Field                      | Value   |
+----------------------------+---------+
| OS-FLV-DISABLED:disabled   | False   |
| OS-FLV-EXT-DATA:ephemeral  | 0       |
| disk                       | 1       |
| id                         | 0       |
| name                       | m1.nano |
| os-flavor-access:is_public | True    |
| ram                        | 64      |
| rxtx_factor                | 1.0     |
| swap                       |         |
| vcpus                      | 1       |
+----------------------------+---------+
#--id,主機類型的ID
#--vcpus,建立主機的cpu的數量
#--ram,內存,默認單位爲M
#--disk,硬盤,默認單位爲G
[root@linux-node1 ~]# openstack flavor list
+----+-----------+-------+------+-----------+-------+-----------+
| ID | Name      |   RAM | Disk | Ephemeral | VCPUs | Is Public |
+----+-----------+-------+------+-----------+-------+-----------+
| 0  | m1.nano   |    64 |    1 |         0 |     1 | True      |
| 1  | m1.tiny   |   512 |    1 |         0 |     1 | True      |
| 2  | m1.small  |  2048 |   20 |         0 |     1 | True      |
| 3  | m1.medium |  4096 |   40 |         0 |     2 | True      |
| 4  | m1.large  |  8192 |   80 |         0 |     4 | True      |
| 5  | m1.xlarge | 16384 |  160 |         0 |     8 | True      |
+----+-----------+-------+------+-----------+-------+-----------+
#ID爲0的是剛纔建立的,生產環境中能夠依據本身的須要進行建立

二、生成一個鍵值對

(1)導入demo用戶的環境變量

[root@linux-node1 ~]# cat demo-openstack.sh 
export OS_PROJECT_DOMAIN_NAME=default
export OS_USER_DOMAIN_NAME=default
export OS_PROJECT_NAME=demo
export OS_USERNAME=demo
export OS_PASSWORD=DEMO_PASS
export OS_AUTH_URL=http://controller:5000/v3
export OS_IDENTITY_API_VERSION=3
export OS_IMAGE_API_VERSION=2
[root@linux-node1 ~]# source demo-openstack.sh

生成密鑰對oop

[root@linux-node1 ~]# ssh-keygen -q -N ""
Enter file in which to save the key (/root/.ssh/id_rsa):

在openstack上建立密鑰對測試

[root@linux-node1 ~]# openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey
+-------------+-------------------------------------------------+
| Field       | Value                                           |
+-------------+-------------------------------------------------+
| fingerprint | 76:e0:a8:ff:ec:20:43:40:5d:42:0a:f1:90:1f:78:38 |
| name        | mykey                                           |
| user_id     | 6762a6adffd140b1906bbe69dbf42518                |
+-------------+-------------------------------------------------+

驗證密鑰對是否建立成功

[root@linux-node1 ~]# openstack keypair list
+-------+-------------------------------------------------+
| Name  | Fingerprint                                     |
+-------+-------------------------------------------------+
| mykey | 76:e0:a8:ff:ec:20:43:40:5d:42:0a:f1:90:1f:78:38 |
+-------+-------------------------------------------------+

三、增長安全組規則

默認狀況下, default安全組適用於全部實例而且包括拒絕遠程訪問實例的防火牆規則。對諸如CirrOS這樣的Linux鏡像,至少容許ICMP (ping) 和安全shell(SSH)規則。

添加規則到default安全組

容許icmp
[root@linux-node1 ~]# openstack security group rule create --proto icmp default
+-----------------------+--------------------------------------+
| Field                 | Value                                |
+-----------------------+--------------------------------------+
| id                    | ca56bc9b-5f12-43ea-b72f-4638cfb55094 |
| ip_protocol           | icmp                                 |
| ip_range              | 0.0.0.0/0                            |
| parent_group_id       | a6670191-a77f-44f1-86b1-a617a5c7547d |
| port_range            |                                      |
| remote_security_group |                                      |
+-----------------------+--------------------------------------+
容許ssh鏈接
[root@linux-node1 ~]# openstack security group rule create --proto tcp --dst-port 22 default
+-----------------------+--------------------------------------+
| Field                 | Value                                |
+-----------------------+--------------------------------------+
| id                    | 5457a51f-a177-4db3-bac5-5b8d1cfb939d |
| ip_protocol           | tcp                                  |
| ip_range              | 0.0.0.0/0                            |
| parent_group_id       | a6670191-a77f-44f1-86b1-a617a5c7547d |
| port_range            | 22:22                                |
| remote_security_group |                                      |
+-----------------------+--------------------------------------+

四、建立實例

[root@linux-node1 ~]# openstack server create --flavor m1.nano --p_w_picpath cirros   --nic net-id=2cbfb54c-b760-41e1-ba69-83131220463b --security-group default   --key-name mykey provider-instance
+--------------------------------------+-----------------------------------------------+
| Field                                | Value                                         |
+--------------------------------------+-----------------------------------------------+
| OS-DCF:diskConfig                    | MANUAL                                        |
| OS-EXT-AZ:availability_zone          |                                               |
| OS-EXT-STS:power_state               | 0                                             |
| 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                            | Q9KXwLniQpoM                                  |
| config_drive                         |                                               |
| created                              | 2016-11-10T06:13:27Z                          |
| flavor                               | m1.nano (0)                                   |
| hostId                               |                                               |
| id                                   | 0006405c-db45-42b4-a65a-d4a2041e2e88          |
| p_w_picpath                                | cirros (29d99654-ba91-4d04-8808-e1b8d16861fb) |
| key_name                             | mykey                                         |
| name                                 | provider-instance                             |
| os-extended-volumes:volumes_attached | []                                            |
| progress                             | 0                                             |
| project_id                           | 81e76ab533b14b448b1c6394bc5e4d86              |
| properties                           |                                               |
| security_groups                      | [{u'name': u'default'}]                       |
| status                               | BUILD                                         |
| updated                              | 2016-11-10T06:13:28Z                          |
| user_id                              | 6762a6adffd140b1906bbe69dbf42518              |
+--------------------------------------+-----------------------------------------------+
#--nic 這裏使用網絡的ID

查看已建立的主機

[root@linux-node1 ~]# openstack server list
+--------------------------------------+-------------------+--------+---------------------------+
| ID                                   | Name              | Status | Networks                  |
+--------------------------------------+-------------------+--------+---------------------------+
| 0006405c-db45-42b4-a65a-d4a2041e2e88 | provider-instance | ACTIVE | public-net=192.168.56.101 |
+--------------------------------------+-------------------+--------+---------------------------+

五、鏈接虛擬機

默認的用戶名是cirros,密碼是cubswin:)

[root@linux-node2 ~]# ssh cirros@192.168.56.101
cirros@192.168.56.101's password: 
$ sudo su -
# ifconfig
eth0      Link encap:Ethernet  HWaddr FA:16:3E:C5:10:81  
          inet addr:192.168.56.101  Bcast:192.168.56.255  Mask:255.255.255.0
          inet6 addr: fe80::f816:3eff:fec5:1081/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:133 errors:0 dropped:0 overruns:0 frame:0
          TX packets:146 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:16003 (15.6 KiB)  TX bytes:15456 (15.0 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
相關文章
相關標籤/搜索