安装OpenStack Glance 组件
本篇主要记录一下 如何安装 OpenStack 的 Glance 镜像管理组件
和上一篇一样 选择的是 queens 版本
操作系统:Centos7
1.官网地址
有一些前置条件 如 mariadb 、 NTP 同步 、MQ 等 需要提前安装好 详细在上一篇Keystone中
https://docs.openstack.org/glance/queens/install/install-rdo.html
2.配置 glance 前置条件
2.1 创建 glance 数据库
mysql -u root -p
MariaDB [(none)]> CREATE DATABASE glance;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' \
IDENTIFIED BY 'root123'; #密码可以自定义
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' \
IDENTIFIED BY 'root123';
2.2 创建一个 glance 用户
openstack user create --domain default --password-prompt glance
输入密码:#自定义密码 我的是root123
重复输入密码:
2.3 把glance用户赋予 admin 角色
openstack role add --project service --user glance admin
#This command provides no output. 就是这一行输入完后 没有任何输出
2.4 创建 glance service
openstack service create --name glance \
--description "OpenStack Glance Image" image
2.5 创建 glance 的 endpoint
上一篇有提到 endpoint 分为3种类型, public、internal、admin ,所以glance 的endpoint 也是要去创建这3种类型
2.5.1 创建 public endpoint
openstack endpoint create --region RegionOne \
image public http://controller:9292
2.5.2 创建 internal endpoint
openstack endpoint create --region RegionOne \
image internal http://controller:9292
2.5.3 创建 admin endpoint
openstack endpoint create --region RegionOne \
image admin http://controller:9292
3.安装 glance 组件
3.1 安装glance packages
yum install openstack-glance #我安装的时候很慢 最后科学上网才安装成功
3.2 编辑/etc/glance/glance-api.conf
3.2.1 配置 数据库连接
[database]
# ...
connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance #注意替换grance密码
3.2.2 配置 keystone_authtoken 和 paste_deploy
[keystone_authtoken]
# ...
auth_uri = http://controller:5000
auth_url = http://controller:5000
memcached_servers = controller:11211
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = glance
password = GLANCE_PASS
[paste_deploy]
# ...
flavor = keystone
3.2.3 配置 glance_store 镜像存储地址
[glance_store]
# ...
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/
3.3 编辑 /etc/glance/glance-registry.conf
和上面的两步一样
3.3.1 配置 数据库连接
[database]
# ...
connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance #注意替换grance密码
3.3.2 配置 keystone_authtoken 和 paste_deploy
[keystone_authtoken]
# ...
auth_uri = http://controller:5000
auth_url = http://controller:5000
memcached_servers = controller:11211
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = glance
password = GLANCE_PASS
[paste_deploy]
# ...
flavor = keystone
3.4 执行 db_sync 脚本
su -s /bin/sh -c "glance-manage db_sync" glance
执行完成后 可以去数据库里查看到 对应的glance 的表
3.5 设置开机自启 和 启动
systemctl enable openstack-glance-api.service \
openstack-glance-registry.service
systemctl start openstack-glance-api.service \
openstack-glance-registry.service
4.测试 glance 上传镜像
至此 glance 已经安装完毕,那我们来测试一下 它的 上传镜像 基础功能
4.1 下载官方cirros 镜像
专门openstack 用于 测试用的小型镜像 下载地址 https://download.cirros-cloud.net/0.5.2/
4.2 上传镜像
glance image-create --name "cirros-0.5.2-x86_64-disk.img" --file /root/cirros-0.5.2-x86_64-disk.img --container-format bare --disk-format qcow2 --progress
4.3 查看镜像
openstack image list
4.4 通过 Api查询镜像
http://192.168.56.30:9292/v2/images?
注意需要带上 X-Auth-Token 去是keystone 拿
5.扩展
5.1 Disk和Container格式
当我们添加一个镜像到glance时,你必须指定虚拟机的disk格式和container格式,关于disk格式请自行研究kvm等虚拟。
disk和container格式是每个部署的基本配置,常用的格式如下:
1.Disk Format
不同的虚拟化应用的厂针有不同的虚拟机镜像的disk格式:
-
raw
This is an unstructured disk image format
-
vhd
This is the VHD disk format, a common disk format used by virtual machine monitors from VMware, Xen, Microsoft, VirtualBox, and others
-
vhdx
This is the VHDX disk format, an enhanced version of the vhd format which supports larger disk sizes among other features.
-
vmdk
Another common disk format supported by many common virtual machine monitors
-
vdi
A disk format supported by VirtualBox virtual machine monitor and the QEMU emulator
-
iso
An archive format for the data contents of an optical disc (e.g. CDROM).
-
ploop
A disk format supported and used by Virtuozzo to run OS Containers
-
qcow2
A disk format supported by the QEMU emulator that can expand dynamically and supports Copy on Write
-
aki
This indicates what is stored in Glance is an Amazon kernel image
-
ari
This indicates what is stored in Glance is an Amazon ramdisk image
-
ami
This indicates what is stored in Glance is an Amazon machine image
5.2 Container Format
容器container格式是指虚拟机映像是否包含一个文件格式,该文件格式还包含有关实际虚拟机的元数据。
需要注意的是:容器格式字符串在当前并不会被glance或其他OpenStack组件的使用,所以如果你不确定,简单的将容器格式指定bare是安全的。
你可以设置如下容器格式:
-
bare
This indicates there is no container or metadata envelope for the image
-
ovf
This is the OVF container format
-
aki
This indicates what is stored in Glance is an Amazon kernel image
-
ari
This indicates what is stored in Glance is an Amazon ramdisk image
-
ami
This indicates what is stored in Glance is an Amazon machine image
-
ova
This indicates what is stored in Glance is an OVA tar archive file
-
docker
This indicates what is stored in Glance is a Docker tar archive of the container filesystem
总结:
本篇主要记录一下 安装 OpenStack 的 Glance 镜像管理组件的全过程,最后再进行测试glance 的上传镜像功能,以及通过API的方式获取查询镜像
欢迎大家访问 个人博客 Johnny小屋