Glance镜像服务
它在OpenStack中的项目名称为Glance。
在早期的OpenStack版本中,Glance只有管理镜像的功能,并不具备镜像存储功能。现在,Glance已发展成为集镜像上传、检索、管理和存储等多种功能的OpenStack核心服务。
镜像
镜像的英文为Image,又译为映象,通常是指一系列文件或一个磁盘驱动器的精确副本。镜像文件其实和ZIP压缩包类似,它将特定的一系列文件按照一定的格式制作成单一的文件,以方便用户下载和使用。
镜像服务
镜像服务就是用来管理镜像的,让用户能够发现、,获取和保存镜像。在OpenStack中提供镜像服务的是Glance,其主要功能如下:
- 查询和获取镜像的元数据和镜像本身
- 注册和上传虚拟机镜像,包括镜像的创建、上传、下载和管理
- 维护镜像信息,包括元数据和镜像本身。
- 支持多种方式存储镜像,包括普通的文件系统、Swift、Amazon s3等
- 对虚拟机实例执行创建快照命令来创建新的镜像,或者备份虚拟机的状态。
OpenStack-Glance组件部署
创建数据里实例喝数据库用户
mysql -u root -p
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';
flush privileges;
exit
创建用户、修改配置文件
openstack user create --domain default --password GLANCE_PASS glance
openstack role add --project service --user glance admin
openstack service create --name glance --description "OpenStack Image" image
openstack endpoint create --region RegionOne image public http://ct:9292
openstack endpoint create --region RegionOne image internal http://ct:9292
openstack endpoint create --region RegionOne image admin http://ct:9292
安装glance软件包
安装 openstack-glance 软件包
yum -y install openstack-glance
/etc/glance/glance-api.conf
/etc/glance/glance-registry.conf
===添加glance-api.conf配置===
cp -a /etc/glance/glance-api.conf{,.bak}
grep -Ev '^$|#' /etc/glance/glance-api.conf.bak > /etc/glance/glance-api.conf
传参
openstack-config --set /etc/glance/glance-api.conf database connection mysql+pymysql://glance:GLANCE_DBPASS@ct/glance
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken www_authenticate_uri http://ct:5000
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_url http://ct:5000
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken memcached_servers ct: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_PASS
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/
cd /etc/glance
cat glance.api.conf
修改glance-registry.conf 配置文件
===修改glance-registry.conf 配置文件===
cp -a /etc/glance/glance-registry.conf{,.bak}
grep -Ev '^$|#' /etc/glance/glance-registry.conf.bak > /etc/glance/glance-registry.conf
传参
openstack-config --set /etc/glance/glance-registry.conf database connection mysql+pymysql://glance:GLANCE_DBPASS@t/glance
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken www_authenticate_uri http://ct:5000
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken auth_url http://ct:5000
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken memcached_servers ct: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_PASS
openstack-config --set /etc/glance/glance-registry.conf paste_deploy flavor keystone
cat glance-registry.conf
初始化glance数据库
su -s /bin/sh -c "glance-manage db_sync" glance
开启glance服务
===开启glance服务(此处开启之后会生成存放镜像的目录/var/lib/glance/image)===
systemctl enable openstack-glance-api.service
systemctl start openstack-glance-api.service
===查看端口(也可以使用lsof -i:9292)
netstat -natp | grep 9292
===赋予openstack-glance-api.service服务对存储设备的可写权限(-h:值对符号连接/软链接的文件修改)===
chown -hR glance:glance /var/lib/glance/
导入镜像
[root@ct /]# cd /opt/
[root@ct opt]# rz -E
rz waiting to receive.
[root@ct opt]# ls
cirros-0.3.5-x86_64-disk.img
openstack image create --file cirros-0.3.5-x86_64-disk.img --disk-format qcow2 --container-format bare --public cirros
查看镜像的方法
===查看镜像的两种方式===
openstack image list
glance image-list
小结
部署思路
1、创建数据库、授权
2、创建openstack用户、授权、管理
3、修改配置文件(glance-api.conf、glance-registry.conf)
4、初始化数据库、上传实例镜像