3.0.glance概述
1)glance作用和特性
- 用户使用镜像服务 (glance) 允许来创建,查询虚拟机镜像。它提供了一个 REST API,允许查询虚拟机镜像的 metadata 并获取一个现存的镜像
- 可以将虚拟机镜像存储到各种位置,如简单的文件系统或者是对象存储系统,例如 OpenStack 对象存储, 并通过镜像服务使用
- 上传指定的文件作为后端配置镜像服务,默认目录是 /var/lib/glance/images/。
2)glance镜像服务的组件
glance-api:
- 用于接收镜像REST API的调用,诸如镜像查找,获取,上传,删除
glance-registry:
- 用于与mysql数据库交互,监听端口为9191,
- 提供镜像元数据相关的REST接口,用于存储、处理和恢复镜像的元数据(metadata),元数据包括项诸如大小和类型。
- 通过glance-registry可以向数据库中写入或获取镜像的各种数据
- 其中有两张表,image表保存了镜像格式大小等信息,image property表保存进行的定制化信息
- 注意:glance-registry是私有内部服务,用于服务OpenStack Image服务。不能向用户暴露
image:镜像文件的存储仓库
- 支持多种类型的仓库,它们有普通文件系统、对象存储、RADOS块设备、HTTP、以及亚马逊S3。另外,其中一些仓库仅支持只读方式使用。
image store:
- 是一个存储的接口层,通过这个接口glance可以获取镜像,支持的存储有亚马逊的S3,openstack本身的swift,还有ceph,sheepdog,GlusterFS等分布式存储
- image store是镜像保存与获取的接口,仅仅是一个接口层,具体的实现需要外部的存储支持
数据库:
- 存放镜像元数据,用户是可以依据个人喜好选择数据库的,多数的部署使用MySQL或SQLite。
元数据定义服务:
- 通用的API,是用于为厂商,管理员,服务,以及用户自定义元数据。
- 这种元数据可用于不同的资源,例如镜像,工件,卷,配额以及集合。
- 一个定义包括了新属性的键,描述,约束以及可以与之关联的资源的类型。
3.1.在控制端安装镜像服务glance
1)创建glance数据库
# 用数据库连接客户端以 root 用户连接到数据库服务器 mysql -u root -p # 创建 glance 数据库 CREATE DATABASE glance; # 对``glance``数据库授予恰当的权限 GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'glance'; GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'glance';
3.2.在keystone上面注册glance
1)在keystone上创建glance用户
# 以下命令在local_user表创建glance用户
mkdir /server/tools && cd /server/tools source keystone-admin-pass.sh openstack user create --domain default --password=glance glance openstack user list
2)在keystone上将glance用户添加为service项目的admin角色(权限)
# 以下命令无输出
openstack role add --project service --user glance admin
3)创建glance镜像服务的实体
# 以下命令在service表中增加glance项目
openstack service create --name glance --description "OpenStack Image" image openstack service list
4)创建镜像服务的 API 端点(endpoint)
openstack endpoint create --region RegionOne image public http://controller:9292 openstack endpoint create --region RegionOne image internal http://controller:9292 openstack endpoint create --region RegionOne image admin http://controller:9292
openstack endpoint list
# 至此,glance在keystone上面注册完成,可以进行安装
3.3.安装glance相关软件
1)安装glance软件
yum install openstack-glance python-glance python-glanceclient -y
3)执行以下命令可以快速配置glance-api.conf
openstack-config --set /etc/glance/glance-api.conf database connection mysql+pymysql://glance:glance@controller/glance openstack-config --set /etc/glance/glance-api.conf keystone_authtoken www_authenticate_uri http://controller:5000 openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_url http://controller:5000 openstack-config --set /etc/glance/glance-api.conf keystone_authtoken memcached_servers controller:11211 openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_type password openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_domain_name Default openstack-config --set /etc/glance/glance-api.conf keystone_authtoken user_domain_name Default openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_name service openstack-config --set /etc/glance/glance-api.conf keystone_authtoken username glance openstack-config --set /etc/glance/glance-api.conf keystone_authtoken password glance openstack-config --set /etc/glance/glance-api.conf paste_deploy flavor keystone openstack-config --set /etc/glance/glance-api.conf glance_store stores file,http 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/
4)执行以下命令可以快速配置glance-registry.conf
openstack-config --set /etc/glance/glance-registry.conf database connection mysql+pymysql://glance:glance@controller/glance openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken www_authenticate_uri http://controller:5000 openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken auth_url http://controller:5000 openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken memcached_servers controller:11211 openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken auth_type password openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken project_domain_name Default openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken user_domain_name Default openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken project_name service openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken username glance openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken password glance openstack-config --set /etc/glance/glance-registry.conf paste_deploy flavor keystone
# 查看生效的配置
grep '^[a-z]' /etc/glance/glance-api.conf grep '^[a-z]' /etc/glance/glance-registry.conf
# 至此,glance服务安装完毕,该服务需要启动
4.4.同步glance数据库
1)为glance镜像服务初始化同步数据库
su -s /bin/sh -c "glance-manage db_sync" glance
# 查看表
mysql glance -e 'show tables'
3.5.启动glance镜像服务
1)启动glance镜像服务、并配置开机自启动
systemctl start openstack-glance-api.service openstack-glance-registry.service systemctl status openstack-glance-api.service openstack-glance-registry.service systemctl enable openstack-glance-api.service openstack-glance-registry.service systemctl list-unit-files |grep openstack-glance*
3.6.检查确认glance安装正确
1)下载镜像
cd /server/tools wget http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img
2)获取管理员权限
source keystone-admin-pass.sh
3)上传镜像到glance
# 使用qcow2磁盘格式, bare容器格式上传镜像到镜像服务并设置公共可见,这样所有的项目都可以访问它
openstack image create "cirros" --file cirros-0.3.5-x86_64-disk.img --disk-format qcow2 --container-format bare --public
4)查看镜像
openstack image list
~~~至此glance镜像服务安装完成,启动成功~~~