基础
镜像服务glance允许用户发现、注册和获取虚拟镜像。它提供一个RESETAPI允许查询虚拟机镜像的metadata并获取一个现存的镜像。
安装和配置
安装条件
创建数据库
1
2
3
4
5
6
7# login mysql
mysql -u root -p
# create database named glance
create database glance;
# grant privileges
grant all privileges on glance.* to 'glc_db'@'localhost' identified by 'passwd';
grant all privileges on glance.* to 'glc_db'@'192.168.122.%' identified by 'passwd';获得admin凭证获取只有管理员才能执行的命令的权限
. admin-openrc
创建服务证书
创建glance用户
1
2openstack user create --domain default \
--password-prompt glance为用户添加admin角色
1
openstack role add --project service --user glance admin
创建glance实体
1
2
3openstack service create \
--name glance \
--description "OpenStack Image" image
- 创建镜像服务的API端点
1
2
3
4
5
6
7
8
9
10
11
12# create public image api
openstack endpoint create \
--region RegionOne \
image public http://ops-cont:9292
# create internal image api
openstack endpoint create \
--region RegionOne \
image internale http://ops-cont:9292
# create admin image api
openstack endpoint create \
--region RegionOne \
image admin http://ops-cont:9292
安装配置组件
- 安装
yum install openstack-glance -y
配置
glance-api.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26cd /etc/glance
vi glance-api.conf
# config database in [database]
[datebase]
# add
connection = mysql_pymysql://glc_db:db_passwd@ops-cont/glance
# config auth in [keystone_authtoken] and [paste_deploy]
[keystone_authtoken]
# add
auth_url=http://ops-cont:5000
auth_url=http://ops-cont:35357
memcached_servers=ops-cont:11211
auth_type=password
project_domain_name=default
user_domain_name=default
project_name=service
username=glance
password=user_passwd
[paste_deploy]
# add
flavor=keystone
# config image postion in [glance_store]
[glance_store]
stores=file,http
default_store=file
filesystem_store_datadir=/var/lib/glance/images/配置
glance-registry.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18# configure database in [database]
[database]
# add
connection=mysql+pymysql://glc_db:db_passwd@opc-cont/glance
# configure auth in [keystone_token] and [paste-deploy]
[keystone_authtoken]
# add
auth_uri=http://ops-cont:5000
auth_url=http://ops-cont:35357
memcached_servers=ops-cont:11211
auth_type=password
project_domain_name=default
user_domain_name=default
project_name=service
username=glance
password=user_passwd
[paste_deploy]
flavor=keystone写入镜像服务数据库
/bin/sh -c "glance-manage db_sync" glance
- 启动服务
1
2systemctl start openstack-glance-api openstack-glance-registry
systemctl enable openstack-glance-api openstack-glance-registry
验证服务
- 获得admin凭证
. admin-openrc
- 下载cirros镜像
wget https://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img cirros040.img
将下载的镜像移动到/var/lib/glance/images
- 使用qcow2格式,bare容器格式上传镜像到镜像服务并设置公共可见
1
2
3
4
5openstack image create "cirros" \
--file cirros040.img \
--disk-format qcow2 \
--container-format bare \
--public
- 查看镜像属性
openstack image list