openstack controller ha测试环境搭建记录(十五)——创建实例

# source demo-openrc.sh

# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
53:fd:b1:1e:28:c5:2e:d7:e8:ef:54:a8:0e:70:38:4a root@controller1
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|           o     |
|          . + .  |
|         o o = + |
|      E S + = * .|
|     . . = = o o |
|      .   . o o  |
|           o o   |
|            ..o  |
+-----------------+

# nova keypair-add --pub-key ~/.ssh/id_rsa.pub demo-key

# nova keypair-list
+----------+-------------------------------------------------+
| Name     | Fingerprint                                     |
+----------+-------------------------------------------------+
| demo-key | 53:fd:b1:1e:28:c5:2e:d7:e8:ef:54:a8:0e:70:38:4a |
+----------+-------------------------------------------------+

# 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      |
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+

# nova image-list
+--------------------------------------+--------------------------+--------+--------+
| ID                                   | Name                     | Status | Server |
+--------------------------------------+--------------------------+--------+--------+
| 89e7fa04-dc3c-426f-9752-75f4c603bcc2 | cirros-0.3.0-x86_64-disk | ACTIVE |        |
+--------------------------------------+--------------------------+--------+--------+

# neutron net-list
+--------------------------------------+----------+-----------------------------------------------------+
| id                                   | name     | subnets                                             |
+--------------------------------------+----------+-----------------------------------------------------+
| 6484c200-a3ff-437c-8749-cf83147cb0d3 | demo-net | 2b4bf426-5e0b-44da-8772-1a306f127793 192.168.1.0/24 |
+--------------------------------------+----------+-----------------------------------------------------+

# nova secgroup-list
+--------------------------------------+---------+-------------+
| Id                                   | Name    | Description |
+--------------------------------------+---------+-------------+
| 65e1f270-1073-4254-945e-86d1db4f0a30 | default | default     |
+--------------------------------------+---------+-------------+

# nova boot --flavor m1.tiny --image cirros-0.3.0-x86_64-disk --nic net-id=6484c200-a3ff-437c-8749-cf83147cb0d3 --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                            | 4rXi2w2radYo                                                    |
| config_drive                         |                                                                 |
| created                              | 2015-12-17T17:31:32Z                                            |
| flavor                               | m1.tiny (1)                                                     |
| hostId                               |                                                                 |
| id                                   | ddec8d7b-e829-4760-a1bf-bf1dd2995dd2                            |
| image                                | cirros-0.3.0-x86_64-disk (89e7fa04-dc3c-426f-9752-75f4c603bcc2) |
| key_name                             | demo-key                                                        |
| metadata                             | {}                                                              |
| name                                 | demo-instance1                                                  |
| os-extended-volumes:volumes_attached | []                                                              |
| progress                             | 0                                                               |
| security_groups                      | default                                                         |
| status                               | BUILD                                                           |
| tenant_id                            | 33c0fa01b2724184bc8def11443a3caa                                |
| updated                              | 2015-12-17T17:31:32Z                                            |
| user_id                              | cbdb8af1c8e9444dbd9974ad3aca66fe                                |
+--------------------------------------+-----------------------------------------------------------------+

# nova list
+--------------------------------------+----------------+--------+------------+-------------+----------------------+
| ID                                   | Name           | Status | Task State | Power State | Networks             |
+--------------------------------------+----------------+--------+------------+-------------+----------------------+
| ddec8d7b-e829-4760-a1bf-bf1dd2995dd2 | demo-instance1 | ERROR  | -          | NOSTATE     | demo-net=192.168.1.2 |
+--------------------------------------+----------------+--------+------------+-------------+----------------------+

# nova show ddec8d7b-e829-4760-a1bf-bf1dd2995dd2
+--------------------------------------+------------------------------------------------------------------------------------------+
| Property                             | Value                                                                                    |
+--------------------------------------+------------------------------------------------------------------------------------------+
| OS-DCF:diskConfig                    | MANUAL                                                                                   |
| OS-EXT-AZ:availability_zone          | nova                                                                                     |
| OS-EXT-STS:power_state               | 0                                                                                        |
| OS-EXT-STS:task_state                | -                                                                                        |
| OS-EXT-STS:vm_state                  | error                                                                                    |
| OS-SRV-USG:launched_at               | -                                                                                        |
| OS-SRV-USG:terminated_at             | -                                                                                        |
| accessIPv4                           |                                                                                          |
| accessIPv6                           |                                                                                          |
| config_drive                         |                                                                                          |
| created                              | 2015-12-17T17:31:32Z                                                                     |
| demo-net network                     | 192.168.1.2                                                                              |
| fault                                | {"message": "No valid host was found. ", "code": 500, "created": "2015-12-17T17:31:35Z"} |
| flavor                               | m1.tiny (1)                                                                              |
| hostId                               | 7788431710acba448fac373e02d6a8ce8c71d41f1355210071b2699e                                 |
| id                                   | ddec8d7b-e829-4760-a1bf-bf1dd2995dd2                                                     |
| image                                | cirros-0.3.0-x86_64-disk (89e7fa04-dc3c-426f-9752-75f4c603bcc2)                          |
| key_name                             | demo-key                                                                                 |
| metadata                             | {}                                                                                       |
| name                                 | demo-instance1                                                                           |
| os-extended-volumes:volumes_attached | []                                                                                       |
| security_groups                      | default                                                                                  |
| status                               | ERROR                                                                                    |
| tenant_id                            | 33c0fa01b2724184bc8def11443a3caa                                                         |
| updated                              | 2015-12-17T17:31:34Z                                                                     |
| user_id                              | cbdb8af1c8e9444dbd9974ad3aca66fe                                                         |
+--------------------------------------+------------------------------------------------------------------------------------------+
发现报错“No valid host was found”没有可用的主机。

查看comput1的服务状态:
# systemctl status libvirtd.service openstack-nova-compute.service
libvirtd.service - Virtualization daemon
Dec 16 23:20:05 compute1 libvirtd[2710]: End of file while reading data: Input/output error

先尝试重启服务:
# systemctl restart libvirtd.service
# systemctl status -l libvirtd.service
libvirtd.service - Virtualization daemon
Dec 18 17:09:35 compute1 libvirtd[22823]: Module /usr/lib64/libvirt/connection-driver/libvirt_driver_lxc.so not accessible

此次报错不同,缺少某个库文件,安装后没问题:
# yum install -y libvirt-daemon-lxc
# systemctl restart libvirtd.service
# systemctl status -l libvirtd.service

删除出问题的实例并重建:
# nova delete ddec8d7b-e829-4760-a1bf-bf1dd2995dd2
# nova boot --flavor m1.tiny --image cirros-0.3.0-x86_64-disk --nic net-id=6484c200-a3ff-437c-8749-cf83147cb0d3 --security-group default --key-name demo-key demo-instance1
# nova list
发现还是相同报错,再检查服务,服务没问题:
# systemctl status -l libvirtd.service openstack-nova-compute.service

跟踪计算节点创建实例时的日志:
# tail -f /var/log/nova/nova-compute.log

可见错误500,估计又是某个配置项不对:
2015-12-18 18:55:38.627 32127 ERROR nova.compute.manager [-] [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0] Instance failed to spawn
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0] Traceback (most recent call last):
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]   File "/usr/lib/python2.7/site-packages/nova/compute/manager.py", line 2246, in _build_resources
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]     yield resources
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]   File "/usr/lib/python2.7/site-packages/nova/compute/manager.py", line 2116, in _build_and_run_instance
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]     block_device_info=block_device_info)
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]   File "/usr/lib/python2.7/site-packages/nova/virt/libvirt/driver.py", line 2616, in spawn
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]     admin_pass=admin_password)
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]   File "/usr/lib/python2.7/site-packages/nova/virt/libvirt/driver.py", line 3006, in _create_image
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]     project_id=instance['project_id'])
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]   File "/usr/lib/python2.7/site-packages/nova/virt/libvirt/imagebackend.py", line 208, in cache
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]     *args, **kwargs)
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]   File "/usr/lib/python2.7/site-packages/nova/virt/libvirt/imagebackend.py", line 451, in create_image
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]     prepare_template(target=base, max_size=size, *args, **kwargs)
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]   File "/usr/lib/python2.7/site-packages/nova/openstack/common/lockutils.py", line 272, in inner
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]     return f(*args, **kwargs)
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]   File "/usr/lib/python2.7/site-packages/nova/virt/libvirt/imagebackend.py", line 198, in fetch_func_sync
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]     fetch_func(target=target, *args, **kwargs)
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]   File "/usr/lib/python2.7/site-packages/nova/virt/libvirt/utils.py", line 452, in fetch_image
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]     max_size=max_size)
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]   File "/usr/lib/python2.7/site-packages/nova/virt/images.py", line 79, in fetch_to_raw
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]     max_size=max_size)
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]   File "/usr/lib/python2.7/site-packages/nova/virt/images.py", line 73, in fetch
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]     IMAGE_API.download(context, image_href, dest_path=path)
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]   File "/usr/lib/python2.7/site-packages/nova/image/api.py", line 178, in download
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]     dst_path=dest_path)
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]   File "/usr/lib/python2.7/site-packages/nova/image/glance.py", line 359, in download
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]     _reraise_translated_image_exception(image_id)
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]   File "/usr/lib/python2.7/site-packages/nova/image/glance.py", line 357, in download
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]     image_chunks = self._client.call(context, 1, 'data', image_id)
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]   File "/usr/lib/python2.7/site-packages/nova/image/glance.py", line 232, in call
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]     return getattr(client.images, method)(*args, **kwargs)
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]   File "/usr/lib/python2.7/site-packages/glanceclient/v1/images.py", line 142, in data
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]     % urlparse.quote(str(image_id)))
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]   File "/usr/lib/python2.7/site-packages/glanceclient/common/http.py", line 259, in get
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]     return self._request('GET', url, **kwargs)
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]   File "/usr/lib/python2.7/site-packages/glanceclient/common/http.py", line 227, in _request
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]     raise exc.from_response(resp, resp.content)
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0] HTTPInternalServerError: HTTPInternalServerError (HTTP 500)
2015-12-18 18:55:38.627 32127 TRACE nova.compute.manager [instance: 267a9e48-e6c9-47dc-9736-a37f2750c1c0]2015-12-18 18:55:37.188 8873 INFO nova.api.openstack.wsgi [req-27360a40-7988-4209-9ccc-aa13d64aaed1 None] HTTP exception thrown: The resource could not be found.

老外关于此问题的讨论:
https://bugs.launchpad.net/nova/+bug/1306342

从日志看,最后出问题的似乎是image,故删除旧的image,重新上传:
# glance image-create --name "cirros-0.3.0-x86_64-disk" --file cirros-0.3.0-x86_64-disk.img --disk-format qcow2 --container-format bare --is-public True --progress

# nova boot --flavor m1.tiny --image cirros-0.3.0-x86_64-disk --nic net-id=6484c200-a3ff-437c-8749-cf83147cb0d3 --security-group default --key-name demo-key demo-instance1

# nova list
+--------------------------------------+----------------+--------+------------+-------------+-----------------------+
| ID                                   | Name           | Status | Task State | Power State | Networks              |
+--------------------------------------+----------------+--------+------------+-------------+-----------------------+
| c2a0d974-4548-4f3a-a64f-85f1125001eb | demo-instance1 | ACTIVE | -          | Running     | demo-net=192.168.1.12 |
+--------------------------------------+----------------+--------+------------+-------------+-----------------------+
没问题了,颇感慨。我环境是3个控制节点,glance分别安装在3个节点上,image文件存放于/var/lib/glance/images,创建实例前,我已手动复制image到各控制节点的相同路径。
之前上传image的节点是controller2,现在调用image的节点是controller1。
看来即使3个glance使用了相同的mysql数据库,还是存在每个节点的image不同步的问题。说明glance的多节点配置我还是不得要领。

# nova get-vnc-console demo-instance1 novnc
+-------+----------------------------------------------------------------------------+
| Type  | Url                                                                        |
+-------+----------------------------------------------------------------------------+
| novnc | http://myvip:6080/vnc_auto.html?token=c1d27680-de9a-418c-acf4-4ff35f98d3fd |
+-------+----------------------------------------------------------------------------+

登录cirros,默认密码“cubswin:)”:
# ping 192.168.1.1

上一篇:ARM汇编指令集


下一篇:mac中使用brew安装软件,下载太慢怎么办?