《3》CentOS7.0+OpenStack+kvm云平台部署—配置Glance,《3》kvm


初始化Glance

(1).安装Glance服务:

[root@openstack ~]# yum -y installopenstack-glance

 

(2).创建Glance数据库:

[root@openstack ~]# openstack-db--init --service glance

 

(3).修改配置文件中的数据库链接:

[root@openstack ~]# openstack-config--set /etc/glance/glance-api.conf DEFAULT sql_connectionmysql://glance:glance@localhost/glance

[root@openstack ~]# openstack-config--set /etc/glance/glance-registry.conf DEFAULT sql_connectionmysql://glance:glance@localhost/glance

 

创建User,定义Services API Endpoints

(1).Glance服务创建一个glance用户:

[root@openstack ~]# keystoneuser-create--name=glance --pass=service --email=glance@zcs.com

[root@openstack ~]# keystoneuser-role-add --user=glance --tenant=service --role=admin

(2).glance创建一个服务:

[root@openstack ~]# keystoneservice-create --name=glance --type=image --description="GlanceImageService"

(3).使用服务ID创建一个endpoint

[root@openstack ~]# vi/root/config/glance.sh

#!/bin/bash

my_ip=10.1.1.2

service=$(keystone service-list | awk'/glance/ {print $2}')

keystone endpoint-create --service-id=$service--publicurl=http://$my_ip:9292 --internalurl=http://$my_ip:9292--adminurl=http://$my_ip:9292

 

[root@mg ~]# sh /root/config/glance.sh

WARNING: Bypassing authentication using atoken & endpoint (authentication credentials are being ignored).

+-------------+----------------------------------+

|  Property  |              Value               |

+-------------+----------------------------------+

|  adminurl  |     http://10.1.1.2:9292      |

|     id     |fe281515d406407bbcd4887cb5815de4 |

| internalurl |     http://10.1.1.2:9292      |

publicurl  |     http://10.1.1.2:9292      |

|   region   |            regionOne             |

service_id | 7c0102f0e715479e9292c0581d214de2 |

+-------------+----------------------------------+

配置Glance服务

 

(1).keystone认证信息添加到glance配置文件中:

[root@openstack ~]# openstack-config --set/etc/glance/glance-api.conf keystone_authtoken auth_host 127.0.0.1

[root@openstack ~]# openstack-config --set/etc/glance/glance-api.conf keystone_authtoken auth_port 35357

[root@openstack ~]# openstack-config --set/etc/glance/glance-api.conf keystone_authtoken auth_protocol http

[root@openstack ~]# openstack-config --set/etc/glance/glance-api.conf keystone_authtoken admin_tenant_name service

[root@openstack ~]# openstack-config --set/etc/glance/glance-api.conf keystone_authtoken admin_user glance

[root@openstack ~]# openstack-config --set/etc/glance/glance-api.conf keystone_authtoken admin_password service

 

[root@openstack ~]# openstack-config --set/etc/glance/glance-registry.conf keystone_authtoken auth_host 127.0.0.1

[root@openstack ~]# openstack-config --set/etc/glance/glance-registry.conf keystone_authtoken auth_port 35357

[root@openstack ~]# openstack-config --set/etc/glance/glance-registry.conf keystone_authtoken auth_protocol http

[root@openstack ~]# openstack-config --set/etc/glance/glance-registry.conf keystone_authtoken admin_tenant_name service

[root@openstack ~]# openstack-config --set/etc/glance/glance-registry.conf keystone_authtoken admin_user glance

[root@openstack ~]# openstack-config --set/etc/glance/glance-registry.conf keystone_authtoken admin_password service


(2).
修改ini文件路径,将keystone认证信息添加到ini文件中:

[root@openstack ~]# openstack-config --set/etc/glance/glance-api.conf paste_deploy config_file/etc/glance/glance-api-paste.ini

[root@openstack ~]# openstack-config --set/etc/glance/glance-api.conf paste_deploy flavor keystone

[root@openstack ~]# openstack-config --set/etc/glance/glance-registry.conf paste_deploy config_file /etc/glance/glance-registry-paste.ini

[root@openstack ~]# openstack-config --set/etc/glance/glance-registry.conf paste_deploy flavor keystone

 

[root@openstack ~]# cp/usr/share/glance/glance-api-dist-paste.ini /etc/glance/glance-api-paste.ini

[root@openstack ~]# cp/usr/share/glance/glance-registry-dist-paste.ini/etc/glance/glance-registry-paste.ini

[root@openstack ~]# chown -R root:glance/etc/glance/glance-api-paste.ini 

[root@openstack ~]# chown -R root:glance/etc/glance/glance-registry-paste.ini

 

[root@openstack ~]# openstack-config --set/etc/glance/glance-api-paste.ini filter:authtoken auth_host 127.0.0.1

[root@openstack ~]# openstack-config --set/etc/glance/glance-api-paste.ini filter:authtoken admin_tenant_name service

[root@openstack ~]# openstack-config --set/etc/glance/glance-api-paste.ini filter:authtoken admin_user glance

[root@openstack ~]# openstack-config --set/etc/glance/glance-api-paste.ini filter:authtoken admin_password service

[root@openstack ~]# openstack-config --set/etc/glance/glance-registry-paste.ini filter:authtoken auth_host 127.0.0.1

[root@openstack ~]# openstack-config --set/etc/glance/glance-registry-paste.ini filter:authtoken admin_tenant_nameservice

[root@openstack ~]# openstack-config --set/etc/glance/glance-registry-paste.ini filter:authtoken admin_user glance

[root@openstack ~]# openstack-config --set/etc/glance/glance-registry-paste.ini filter:authtoken admin_password service


(3).修改镜像文件的存放路径(默认存放在/var/lib/glance目录下,若不需修改,此步骤可省略)

[root@openstack ~]# openstack-config--set /etc/glance/glance-api.conf DEFAULT filesystem_store_datadir/openstack/lib/glance/images/

[root@openstack ~]# openstack-config--set /etc/glance/glance-api.conf DEFAULT scrubber_datadir/openstack/lib/glance/scrubber

[root@openstack ~]# openstack-config --set/etc/glance/glance-api.conf DEFAULT image_cache_dir/openstack/lib/glance/image-cache/

[root@openstack ~]# mkdir -p/openstack/lib

[root@openstack ~]# cp -r/var/lib/glance/ /openstack/lib/

[root@openstack ~]# chown -Rglance:glance /openstack/lib/glance/

 

(4).启动glance服务,设置开机自启动

[root@openstack ~]# serviceopenstack-glance-api start

[root@openstack ~]# serviceopenstack-glance-registry start

[root@openstack ~]# chkconfigopenstack-glance-api on

[root@openstack ~]# chkconfigopenstack-glance-registry on

 

Glance测试

 

(1).上传镜像

[root@openstack ~]# glanceimage-create --name=centos6.4 --disk-format=qcow2 --container-format=ovf--is-public=true < /root/centos6.4-mini_x64.qcow2 

注意:(以下框住的描述可忽略)验证镜像服务的安装(Verify theImage Service installation)

为了测试镜像服务的安装,至少下载一个虚拟机镜像,这个镜像一定要能够与OpenStack一起工作。例如,CirrOS是一个很小的测试镜像,它经常用于测试OpenStack部署。这个过程,使用了64-bitCirrOSQCOW2镜像。

有关更多如何下载和创建镜像的信息,请参考OpenStackVirtual Machine Image Guide,有关如何管理镜像的信息,请参考OpenStackUser Guide”.

1. wgetcurl下载该镜像到指定的目录

$ mkdirimages
$ cd images/
$ wget 
http://cdn.download.cirros-cloud.net/0.3.1/cirros-0.3.1-x86_64-disk.img

2. 上传该镜像到该镜像服务中

# glanceimage-create --name=imageLabel --disk-format=fileFormat \
--container-format=containerFormat --is-public=accessValue < imageFile

参数说明:

imageLabel  任意的标志,该名称由用户指向镜像。

fileFormat     说明镜像文件格式,有效的文件格式包括:qcow2rawvhd,vmdk,vdi,iso,aki,ari,andami等等。

这里选择format的时候,最好选择vmdk,因为后面创建虚拟机实例的时候可能会识别不了

containerFormat  指定的容器格式,有效的格式包括:bare,ovf,aki,ariand ami

指定bare格式表明镜像文件不在文件格式里,也就是说包含有关虚拟机的元数据。虽然目前这个字段是必须的,但实际上任何其它的OpenStack服务不使用它,而且在系统运行时也没有效果。因为该值在任何地方都没有用到,为了安全,一直指定bare作为容器的格式。

accessValue   指定镜像是否能访问。

                             true --所有的用户都能够查看和使用该镜像。

                             false --只有管理员才能够查看和使用该镜像

imageFile           指定你下载的镜像文件名称


 

注:上传出错:

Requestreturned failure status.
HTTPInternalServerError (HTTP 500)

后来查看debug,是我在配置/etc/glance/glanceregistry.conf文件时把:

[paste_deploy]
...
flavor = keystone
中的keystone错写成了glance

更改后,再上传,就对了,结果如下:

root@controller:~/image#glance image-create --name="CirrOS 0.3.1" --disk-format=qcow2--container-format=bare --is-public=true < cirros-0.3.1-x86_64-disk.img
+------------------+--------------------------------------+
| Property         |Value                               |
+------------------+--------------------------------------+
| checksum         |d972013792949d0d3ba628fbe8685bce     |
| container_format |bare                                |
| created_at       |2014-03-14T10:03:34                 |
| deleted          |False                               |
| deleted_at       |None                                |
| disk_format      |qcow2                               |
|id              | 84e4056d-662f-4c88-809a-6551b9e3185a |
| is_public        |True                                |
| min_disk         |0                                   |
| min_ram          |0                                   |
| name            | CirrOS0.3.1                        |
| owner            |fe0f1b42a1df44bcac0b6908b96bcaae     |
| protected        |False                               |
| size            |13147648                            |
| status           |active                              |
| updated_at       |2014-03-14T10:03:35                 |
+------------------+--------------------------------------+

查看glance数据库中的表images,就可以看到添加的镜像文件。

再查看/var/lib/glance/images目录下,就有一个与images表中ID号相同的文件。

 

(2).查看镜像

[root@openstack ~]# glance image-list

相关内容