创建key
[root@controller ~]# source kevin-openrc.sh
[root@controller ~]# ssh-keygen -q -N ""
[root@controller ~]# nova keypair-add --pub-key .ssh/id_rsa.pub mykey
[root@controller ~]# nova keypair-list
+-------+-------------------------------------------------+
| Name | Fingerprint |
+-------+-------------------------------------------------+
| mykey | e8:8e:1f:33:d2:75:b6:32:bd:7d:68:aa:a1:f6:d5:fe |
+-------+-------------------------------------------------+
创建安全组
[root@controller ~]# 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 | |
+-------------+-----------+---------+-----------+--------------+
设置安全组规则
[root@controller ~]# 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 | |
+-------------+-----------+---------+-----------+--------------+
创建虚拟机
查看虚拟机类型
root@controller ~]# 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 |
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+
查看网络类型
[root@controller ~]# neutron net-list
+--------------------------------------+------+-----------------------------------------------------+
| id | name | subnets |
+--------------------------------------+------+-----------------------------------------------------+
| d9aa89ae-01ba-4a3d-b553-7e63d48d0acb | flat |a645f499-90a2-4e90-8bcb-f9040392c6bb 192.168.1.0/24 |
+--------------------------------------+------+-----------------------------------------------------+
查看镜像
[root@controller ~]# nova image-list
+--------------------------------------+--------+--------+--------+
| ID | Name | Status | Server |
+--------------------------------------+--------+--------+--------+
| de72b13d-3f0f-4292-9afa-30c94175c3b5 | cirros | ACTIVE | |
+--------------------------------------+--------+--------+--------+
查看安全组
[root@controller ~]# nova secgroup-list
+--------------------------------------+---------+------------------------+
| Id | Name | Description |
+--------------------------------------+---------+------------------------+
| d73f3911-7d65-4833-8e6c-bddfd39b2592 | default | Default security group|
+--------------------------------------+---------+------------------------+
开始创建虚拟机
[root@controller ~]# nova boot --flavor m1.tiny --image cirros --nicnet-id=d9aa89ae-01ba-4a3d-b553-7e63d48d0acb --security-group default --key-name mykey first-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 | b2C3o9MR6cS8 |
| config_drive | |
| created | 2015-12-29T10:16:06Z |
| flavor | m1.tiny (1) |
| hostId | |
| id | 8beb0b38-9ca4-4384-bee2-91988d0a9ab2 |
| image | cirros (de72b13d-3f0f-4292-9afa-30c94175c3b5) |
| key_name | mykey |
| metadata | {} |
| name | first-instance |
| os-extended-volumes:volumes_attached | [] |
| progress | 0 |
| security_groups | default |
| status | BUILD |
| tenant_id | 1ee793c741f64d25be9010d59e4b5a3d |
| updated |2015-12-29T10:16:06Z |
| user_id | c5baee07132c40f9841a607af1789ed6 |
+--------------------------------------+-----------------------------------------------+
此时虚拟机就开始创建了,可以使用nova list查看
[root@controller ~]# nova list
+--------------------------------------+----------------+--------+------------+-------------+--------------------+
| ID | Name | Status | TaskState | Power State | Networks |
+--------------------------------------+----------------+--------+------------+-------------+--------------------+
| 8beb0b38-9ca4-4384-bee2-91988d0a9ab2 | first-instance | ACTIVE | - | Running | flat=192.168.1.101 |
+--------------------------------------+----------------+--------+------------+-------------+--------------------+
出现running表示创建成功,可以ping同,也可以ssh连接
[root@controller ~]# ssh [email protected]
获取web连接页面
[root@controller ~]# nova get-vnc-console first-instance novnc
+-------+-----------------------------------------------------------------------------------+
| Type | Url |
+-------+-----------------------------------------------------------------------------------+
| novnc |http://192.168.1.11:6080/vnc_auto.html?token=299e9487-02ba-4f4f-b84a-791ba4aee7a6|
+-------+-----------------------------------------------------------------------------------+
在浏览器中输入给出的web地址就可以连接到该虚拟机
Linux运维开发群:298324302
北京linux运维求职招聘群:153677549