OpenStack-liberty版创建第一台虚拟机

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OpenStack-liberty版创建第一台虚拟机相关的知识,希望对你有一定的参考价值。

创建网络:
[[email protected] ~]# source admin-openrc.sh

[[email protected] ~]# neutron net-create flat --shared --provider:physical_network physnet1  --provider:network_type flat
Created a new network:
+---------------------------+--------------------------------------+
| Field                     | Value                                |
+---------------------------+--------------------------------------+
| admin_state_up            | True                                 |
| id                        | 9252cb78-d155-40d4-8ea5-5e45852a6b40 |
| mtu                       | 0                                    |
| name                      | flat                                 |
| port_security_enabled     | True                                 |
| provider:network_type     | flat                                 |
| provider:physical_network | physnet1                             |
| provider:segmentation_id  |                                      |
| router:external           | False                                |
| shared                    | True                                 |
| status                    | ACTIVE                               |
| subnets                   |                                      |
| tenant_id                 | d7064a9e91934300b28cccc787161fdb     |
+---------------------------+--------------------------------------+
[[email protected] ~]# neutron subnet-create flat 192.168.56.0/24 --name flat-subnet --allocation-pool start=192.168.56.100,end=192.168.56.200 --dns-nameserver 192.168.56.2 --gateway 192.168.56.2
Created a new subnet:
+-------------------+------------------------------------------------------+
| Field             | Value                                                |
+-------------------+------------------------------------------------------+
| allocation_pools  | {"start": "192.168.56.100", "end": "192.168.56.200"} |
| cidr              | 192.168.56.0/24                                      |
| dns_nameservers   | 192.168.56.2                                         |
| enable_dhcp       | True                                                 |
| gateway_ip        | 192.168.56.2                                         |
| host_routes       |                                                      |
| id                | 5ff3d70a-c336-421d-880e-d1a13791afd0                 |
| ip_version        | 4                                                    |
| ipv6_address_mode |                                                      |
| ipv6_ra_mode      |                                                      |
| name              | flat-subnet                                          |
| network_id        | 9252cb78-d155-40d4-8ea5-5e45852a6b40                 |
| subnetpool_id     |                                                      |
| tenant_id         | d7064a9e91934300b28cccc787161fdb                     |
+-------------------+------------------------------------------------------+
[[email protected] ~]# neutron subnet-list
+--------------------------------------+-------------+-----------------+------------------------------------------------------+
| id                                   | name        | cidr            | allocation_pools                                     |
+--------------------------------------+-------------+-----------------+------------------------------------------------------+
| 5ff3d70a-c336-421d-880e-d1a13791afd0 | flat-subnet | 192.168.56.0/24 | {"start": "192.168.56.100", "end": "192.168.56.200"} |
+--------------------------------------+-------------+-----------------+------------------------------------------------------+
[[email protected] ~]# neutron net-list
+--------------------------------------+------+------------------------------------------------------+
| id                                   | name | subnets                                              |
+--------------------------------------+------+------------------------------------------------------+
| 9252cb78-d155-40d4-8ea5-5e45852a6b40 | flat | 5ff3d70a-c336-421d-880e-d1a13791afd0 192.168.56.0/24 |
+--------------------------------------+------+------------------------------------------------------+

创建key:
[[email protected] ~]# source demo-openrc.sh

[[email protected] ~]# ssh-keygen -q -N ""
Enter file in which to save the key (/root/.ssh/id_rsa):
[[email protected] ~]# ls .ssh/
id_rsa  id_rsa.pub

[[email protected] ~]# nova keypair-add --pub-key ~/.ssh/id_rsa.pub mykey

[[email protected] ~]# nova keypair-list    
+-------+-------------------------------------------------+
| Name  | Fingerprint                                     |
+-------+-------------------------------------------------+
| mykey | 9c:a0:94:9c:f0:25:2d:f0:8b:1b:32:02:e6:9e:1c:54 |
+-------+-------------------------------------------------+

添加安全组:

[[email protected] ~]# 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 |              |
+-------------+-----------+---------+-----------+--------------+
[[email protected] ~]# 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 |              |
+-------------+-----------+---------+-----------+--------------+

启动虚拟机:

[[email protected] ~]# 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      |
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+
[[email protected] ~]# nova image-list     
+--------------------------------------+--------+--------+--------+
| ID                                   | Name   | Status | Server |
+--------------------------------------+--------+--------+--------+
| 0297b83c-f9d7-4c19-ab05-762fd4616c49 | cirros | ACTIVE |        |
+--------------------------------------+--------+--------+--------+
[[email protected] ~]# nova net-list 
+--------------------------------------+-------+------+
| ID                                   | Label | CIDR |
+--------------------------------------+-------+------+
| 9252cb78-d155-40d4-8ea5-5e45852a6b40 | flat  | None |
+--------------------------------------+-------+------+
[[email protected] ~]# nova boot --flavor m1.tiny --image cirros --nic net-id=9252cb78-d155-40d4-8ea5-5e45852a6b40 --security-group default --key-name mykey hello-instance
+--------------------------------------+-----------------------------------------------+
| Property                             | 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               | -                                             |
| OS-SRV-USG:terminated_at             | -                                             |
| accessIPv4                           |                                               |
| accessIPv6                           |                                               |
| adminPass                            | ubu5nc8Pv3kD                                  |
| config_drive                         |                                               |
| created                              | 2018-10-08T23:55:54Z                          |
| flavor                               | m1.tiny (1)                                   |
| hostId                               |                                               |
| id                                   | 5b6b6e93-2aed-4c73-ba6d-220b43c9d48a          |
| image                                | cirros (0297b83c-f9d7-4c19-ab05-762fd4616c49) |
| key_name                             | mykey                                         |
| metadata                             | {}                                            |
| name                                 | hello-instance                                |
| os-extended-volumes:volumes_attached | []                                            |
| progress                             | 0                                             |
| security_groups                      | default                                       |
| status                               | BUILD                                         |
| tenant_id                            | 29b7833bc24e41d7b4c1d8c77de81e88              |
| updated                              | 2018-10-08T23:56:04Z                          |
| user_id                              | 8ce3700aed4e428d9ce51b05685ae0a6              |
+--------------------------------------+-----------------------------------------------+

连接虚拟机:

[[email protected] ~]# nova list
+--------------------------------------+----------------+--------+------------+-------------+---------------------+
| ID                                   | Name           | Status | Task State | Power State | Networks            |
+--------------------------------------+----------------+--------+------------+-------------+---------------------+
| e7585ece-c8e9-4ad8-8796-8a58bca459bf | hello-instance | ACTIVE | -          | Running     | flat=192.168.56.103 |
+--------------------------------------+----------------+--------+------------+-------------+---------------------+
[[email protected] ~]# ping 192.168.56.103 
PING 192.168.56.103 (192.168.56.103) 56(84) bytes of data.
64 bytes from 192.168.56.103: icmp_seq=1 ttl=64 time=22.1 ms
64 bytes from 192.168.56.103: icmp_seq=2 ttl=64 time=17.7 ms
64 bytes from 192.168.56.103: icmp_seq=3 ttl=64 time=4.11 ms
64 bytes from 192.168.56.103: icmp_seq=4 ttl=64 time=44.4 ms
^C
--- 192.168.56.103 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3006ms
rtt min/avg/max/mdev = 4.119/22.102/44.434/14.503 ms
[[email protected] ~]# ssh [email protected]
The authenticity of host ‘192.168.56.103 (192.168.56.103)‘ can‘t be established.
RSA key fingerprint is SHA256:34k1lHbVI28Tn4YlfxQtaFNuv2a3lcSGgoXScynRAeY.
RSA key fingerprint is MD5:fa:29:2a:6f:56:67:2a:45:bb:74:3c:9d:9b:84:83:5d.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘192.168.56.103‘ (RSA) to the list of known hosts.
$ whoami
cirros
$ ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether fa:16:3e:f4:6f:fe brd ff:ff:ff:ff:ff:ff
    inet 192.168.56.103/24 brd 192.168.56.255 scope global eth0
    inet6 fe80::f816:3eff:fef4:6ffe/64 scope link 
       valid_lft forever preferred_lft forever
$ exit
Connection to 192.168.56.103 closed.

通过VNC连接:
获取hello-instance虚拟机实力连接url;

[[email protected] ~]# nova get-vnc-console hello-instance novnc  
+-------+------------------------------------------------------------------------------------+
| Type  | Url                                                                                |
+-------+------------------------------------------------------------------------------------+
| novnc | http://192.168.56.11:6080/vnc_auto.html?token=b895d0e1-cfed-4736-99e0-e91986b7b82c |
+-------+------------------------------------------------------------------------------------+

通过浏览器打开url;
技术分享图片

node1网卡变化;

[[email protected] ~]# ifconfig 
brq9252cb78-d1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.56.11  netmask 255.255.255.0  broadcast 192.168.56.255
        ether 00:0c:29:81:30:8f  txqueuelen 1000  (Ethernet)
        RX packets 19654  bytes 3675080 (3.5 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 17122  bytes 21751953 (20.7 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::c52b:9095:bd1d:f94e  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:81:30:8f  txqueuelen 1000  (Ethernet)
        RX packets 30222  bytes 5286547 (5.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 32628  bytes 34571258 (32.9 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.47.142  netmask 255.255.255.0  broadcast 192.168.47.255
        inet6 fe80::d51e:5fe4:2294:35f0  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:81:30:99  txqueuelen 1000  (Ethernet)
        RX packets 3203  bytes 230403 (225.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 732  bytes 63739 (62.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 156173  bytes 47463676 (45.2 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 156173  bytes 47463676 (45.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

tap3bbe2f60-5a: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether e6:b1:a1:e9:bc:46  txqueuelen 1000  (Ethernet)
        RX packets 156  bytes 17384 (16.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1386  bytes 144188 (140.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
[[email protected] ~]# brctl show
bridge name bridge id       STP enabled interfaces
brq9252cb78-d1      8000.000c2981308f   no      ens33
                            tap3bbe2f60-5a

node2网卡变化;

[[email protected] linux-node2 ~]# ifconfig 
brq9252cb78-d1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.56.12  netmask 255.255.255.0  broadcast 192.168.56.255
        inet6 fe80::2cf6:8ff:fed1:e558  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b2:dc:b3  txqueuelen 1000  (Ethernet)
        RX packets 3911  bytes 834854 (815.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4240  bytes 1069545 (1.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::9752:504d:ee43:64f5  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b2:dc:b3  txqueuelen 1000  (Ethernet)
        RX packets 2044792  bytes 230569291 (219.8 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2033577  bytes 214521423 (204.5 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.47.143  netmask 255.255.255.0  broadcast 192.168.47.255
        inet6 fe80::c33f:7c14:d42c:bc06  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b2:dc:bd  txqueuelen 1000  (Ethernet)
        RX packets 133097  bytes 145683102 (138.9 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 27306  bytes 1767757 (1.6 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 104602  bytes 5520393 (5.2 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 104602  bytes 5520393 (5.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

tapf761b1bc-25: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::fc16:3eff:fef4:6ffe  prefixlen 64  scopeid 0x20<link>
        ether fe:16:3e:f4:6f:fe  txqueuelen 1000  (Ethernet)
        RX packets 180  bytes 18710 (18.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 156  bytes 18742 (18.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
[[email protected]ame linux-node2 ~]# brctl show
bridge name bridge id       STP enabled interfaces
brq9252cb78-d1      8000.000c29b2dcb3   no      ens33
                            tapf761b1bc-25

以上是关于OpenStack-liberty版创建第一台虚拟机的主要内容,如果未能解决你的问题,请参考以下文章

OpenStack-liberty版网络介绍

OpenStack-liberty版Ciner部署

OpenStack kilo版 启动第一台虚拟机

OpenStack-liberty版Glance服务部署

OpenStack-liberty版Neutron服务部署

OpenStack-liberty版Nova服务部署