glance概述:
Image Service镜像服务主要用于创建instance时提供镜像的发现,注册,检索服务,nova启动instance时,会向glance请求对应的image,然后下载对应的image到本地。glance的镜像支持多种存储方式,如常见的本地文件系统,分布式存储ceph,glusterfs上,或者存储在swift上,默认存放在controller的本地文件系统上,存储的路径是:/var/lib/glance/images,为了确保有足够的空间,建议修改路径,或者划分一个单独的空间给glance使用。
glance由两个服务组成:glance-api和glance-registry,其中,glance-api负责接收外部发送的请求,glance-registry接收用户发送的请求后,完成向后端镜像的存储,检索镜像和元数据等功能。此外,镜像的所有信息,包括镜像的元数据信息,都会以持久化的方式保存在数据库中。
十四、glance的安装(在controller上root用户进行)
(1)创建数据库
# mysql -uroot -popenstack
> create database glance;
> grant all privileges on glance.* to 'glance'@'localhost' identified by 'GLANCE_DBPASS';
> grant all privileges on glance.* to 'glance'@'%' identified by 'GLANCE_DBPASS';
> exit
#测试查看新建的数据库
# mysql -uglance -pGLANCE_DBPASS -e 'SHOW DATABASES;'
(2)创建keystone认证的用户
#创建用户
# source /root/admin-openrc.sh
# keystone user-create --name glance --pass GLANCE_PASS --email glance@example.com --enabled true
# keystone user-list
#授予glance权限
#链接admin角色与glance用户
# keystone user-role-add --user glance --tenant service --role admin
# keystone user-role-list --user glance --tenant service
#创建glance服务
#创建image服务实体
# keystone service-create --type image --name glance --description "Openstack Glance Image Service"
# keystone service-list
#将glance服务路径注册到keystone
#创建image服务的api端口
# keystone endpoint-create --service-id $(keystone service-list | awk '/ image / {print $2}') --publicurl http://controller0:9292 --internalurl http://controller0:9292 --adminurl http://controller0:9292 --region regionOne
# keystone endpoint-list
(3) 安装glance服务
# yum -y install openstack-glance python-glanceclient
(4)配置glance-api服务
#配置数据库连接
# openstack-config --set /etc/glance/glance-api.conf database connection mysql://glance:GLANCE_DBPASS@controller0/glance
# cat /etc/glance/glance-api.conf |more
#查看是否修改成功
#配置keystone
# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_uri http://controller0:5000/v2.0
# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken identity_uri http://controller0:35357
# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken admin_tenant_name service
# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken admin_user glance
# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken admin_password GLANCE_PASS
#以上为kestone验证
#下面一步为keystone服务入口
# openstack-config --set /etc/glance/glance-api.conf paste_deploy flavor keystone
# cat /etc/glance/glance-api.conf |more
#配置image存储位置,使用本地的文件系统存储
# openstack-config --set /etc/glance/glance-api.conf glance_store default_store file
# openstack-config --set /etc/glance/glance-api.conf glance_store filesystem_store_datadir /var/lib/glance/images/
#以上两项设置镜像存储位置
#下一步启动详细日志
# openstack-config --set /etc/glance/glance-api.conf DEFAULT verbose True
(5)配置glance-registry服务
#配置数据库连接
# openstack-config --set /etc/glance/glance-registry.conf database connection mysql://glance:GLANCE_DBPASS@controller0/glance
#配置keystone认证
# openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken auth_uri http://controller0:5000/v2.0
# openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken identity_uri http://controller0:35357
# openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken admin_tenant_name service
# openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken admin_user glance
# openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken admin_password GLANCE_PASS
# openstack-config --set /etc/glance/glance-registry.conf paste_deploy flavor keystone
# openstack-config --set /etc/glance/glance-registry.conf DEFAULT verbose True
#建立glance数据库中所需要的表
# su -s /bin/sh -c "glance-manage db_sync" glance
# mysql -uglance -pGLANCE_DBPASS -e "show tables from glance;"
(6)启动glance服务
#启动glance服务
# service openstack-glance-api start
# chkconfig openstack-glance-api on
# service openstack-glance-registry start
# chkconfig openstack-glance-registry on
#校验glance服务
把镜像文件cirros-0.3.0-x86_64-disk.img上传到/root根目录下
# cd ~
# file cirros-0.3.3-x86_64-disk.img
# source admin-openrc.sh
# glance image-create --name cirros --disk-format qcow2 --container-format bare --file /root/cirros-0.3.3-x86_64-disk.img --is-public True --is-protected False --human-readable --progress
#校验image是否上传成功
# glance image-list
#查看image详细信息,此处的XXX是上一步执行结果中显示的ID
# glance image-show XXX
glance日志路径位于:
glance-api: /var/log/glance/api.log
glance-registry: /var/log/glance/registry.log