glance架构
1、客户端client
glance服务应用程序的使用者:OpenStack命令行工具、horizon、Nova服务
2、glance-api:
glance入口,用于接收镜像REST API的调用,诸如镜像查找,获取,上传,删除
3、glance-registry:
用于与mysql数据库交互,监听端口为9191,
提供镜像元数据相关的REST接口,用于存储、处理和恢复镜像的元数据(metadata),元数据包括项诸如大小和类型。
通过glance-registry可以向数据库中写入或获取镜像的各种数据
其中有两张表,image表保存了镜像格式大小等信息,image property表保存进行的定制化信息
注意:glance-registry是私有内部服务,用于服务OpenStack Image服务。不能向用户暴露
OpenStack-queens版-控制节点部署glance服务
1、安装配置glance之前先以root用户身份使用数据库访问客户端,连接到数据库服务器
[root@controller ~]# mysql -u root -p
Enter password:
MariaDB [(none)]> CREATE DATABASE glance; #创建数据库glance
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'whj1218' ; #对本地授权,密码为whj1218
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'whj1218';#
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| glance |
| information_schema |
| keystone |
| mysql |
| performance_schema |
+--------------------+
MariaDB [(none)]> quit #退出数据库
2、在keystone上面注册glance
1)在keystone上创建glance用户
[root@controller ~]# source keystone-admin-pass.sh #加载admin的环境变量
[root@controller ~]# openstack user create --domain default --password-prompt glance #创建glance用户,密码为whj1218
User Password:
Repeat User Password:
+---------------------+----------------------------------+
| Field | Value |
+---------------------+----------------------------------+
| domain_id | default |
| enabled | True |
| id | b2f7c49185004822957e5e40227b833a |
| name | glance |
| options | {} |
| password_expires_at | None |
+---------------------+----------------------------------+
[root@controller ~]# openstack user list #列出用户
+----------------------------------+---------+
| ID | Name |
+----------------------------------+---------+
| 4640a445474e44abba73328aa81a805b | admin |
| 9c1f982fc354433dbea4d060681619bf | myuser |
| 0356c4d61dcf4afb9d8df45c1dea3ffc | my_user |
| b2f7c49185004822957e5e40227b833a | glance |
+----------------------------------+---------+
[root@controller ~]# openstack role add --project service --user glance admin#在keystone上将glance用户添加为service项目的admin角色(权限)
3)创建glance镜像服务的实体
[root@controller ~]# openstack service create --name glance --description "OpenStack Image" image#创建glance服务条目,在service表中增加glance项目
+-------------+----------------------------------+
| Field | Value |
+-------------+----------------------------------+
| description | OpenStack Image |
| enabled | True |
| id | 04289507c30f41faa7ba4e5f730db3d0 |
| name | glance |
| type | image |
+-------------+----------------------------------+
[root@controller ~]# openstack service list #列出服务
+----------------------------------+----------+----------+
| ID | Name | Type |
+----------------------------------+----------+----------+
| 04289507c30f41faa7ba4e5f730db3d0 | glance | image |
| 5bf0447c80e44bc5a68d8ccc554d81e8 | keystone | identity |
+----------------------------------+----------+----------+
4)创建镜像服务的 API 端点(endpoint)
[root@controller ~]# openstack endpoint create --region RegionOne image internal http://controller:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | 3ad1568a787d467893daf154e65d60d2 |
| interface | internal |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 04289507c30f41faa7ba4e5f730db3d0 |
| service_name | glance |
| service_type | image |
| url | http://controller:9292 |
+--------------+----------------------------------+
[root@controller ~]# openstack endpoint create --region RegionOne image public http://controller:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | 03317d828e5944daaa9b9806c92b6319 |
| interface | public |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 04289507c30f41faa7ba4e5f730db3d0 |
| service_name | glance |
| service_type | image |
| url | http://controller:9292 |
+--------------+----------------------------------+
[root@controller ~]# openstack endpoint create --region RegionOne image admin http://controller:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | 6d5e77dc42a243c5810c29f679a486f8 |
| interface | admin |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 04289507c30f41faa7ba4e5f730db3d0 |
| service_name | glance |
| service_type | image |
| url | http://controller:9292 |
+--------------+----------------------------------+
[root@controller ~]# openstack endpoint list
+----------------------------------+-----------+--------------+--------------+---------+-----------+-----------------------------+
| ID | Region | Service Name | Service Type | Enabled | Interface | URL |
+----------------------------------+-----------+--------------+--------------+---------+-----------+-----------------------------+
| 03317d828e5944daaa9b9806c92b6319 | RegionOne | glance | image | True | public | http://controller:9292 |
| 3ad1568a787d467893daf154e65d60d2 | RegionOne | glance | image | True | internal | http://controller:9292 |
| 6d5e77dc42a243c5810c29f679a486f8 | RegionOne | glance | image | True | admin | http://controller:9292 |
| bcbf96c2a7d54d1181d75e752eb1642d | RegionOne | keystone | identity | True | internal | http://controller:5000/v3/ |
| d41a39b417964676b6cfea658a7f3d01 | RegionOne | keystone | identity | True | admin | http://controller:5000/v3/ |
| f25f1eab7c8b4c4489f1c84234be9912 | RegionOne | keystone | identity | True | public | http://controller:5000/v3/ |
+----------------------------------+-----------+--------------+--------------+---------+-----------+-----------------------------+
至此glance在keystone上面注册完成,可以进行后面的安装
3.安装glance相关软件
[root@controller ~]# python --version #检查Python版本
Python 2.7.5
[root@controller ~]# yum -y install openstack-glance python-glance python-glanceclient #安装glance相关软件
快速配置glance-api.conf
[root@controller ~]# openstack-config --set /etc/glance/glance-api.conf database connection mysql+pymysql://glance:whj1218@controller/glance
[root@controller ~]# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken www_authenticate_uri http://controller:5000
[root@controller ~]# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_url http://controller:5000
[root@controller ~]# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken memcached_servers controller:11211
[root@controller ~]# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_type password
[root@controller ~]# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_domain_name Default
[root@controller ~]# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken user_domain_name Default
[root@controller ~]# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_name service
[root@controller ~]# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken username glance
[root@controller ~]# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken password whj1218
[root@controller ~]# openstack-config --set /etc/glance/glance-api.conf paste_deploy flavor keystone
[root@controller ~]# openstack-config --set /etc/glance/glance-api.conf glance_store stores file,http
[root@controller ~]# openstack-config --set /etc/glance/glance-api.conf glance_store default_store file
[root@controller ~]# openstack-config --set /etc/glance/glance-api.conf glance_store filesystem_store_datadir /var/lib/glance/images/
快速配置glance-registry.conf
[root@controller ~]# openstack-config --set /etc/glance/glance-registry.conf database connection mysql+pymysql://glance:whj1218@controller/glance
[root@controller ~]# openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken www_authenticate_uri http://controller:5000
[root@controller ~]# openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken auth_url http://controller:5000
[root@controller ~]# openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken memcached_servers controller:11211
[root@controller ~]# openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken auth_type password
[root@controller ~]# openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken project_domain_name Default
[root@controller ~]# openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken user_domain_name Default
[root@controller ~]# openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken project_name service
[root@controller ~]# openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken username glance
[root@controller ~]# openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken password whj1218
[root@controller ~]# openstack-config --set /etc/glance/glance-registry.conf paste_deploy flavor keystone
[root@controller ~]# grep '^[a-z]' /etc/glance/glance-api.conf #查看生效的配置
connection = mysql+pymysql://glance:whj1218@controller/glance
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/
www_authenticate_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 = whj1218
flavor = keystone
[root@controller ~]# grep '^[a-z]' /etc/glance/glance-registry.conf #查看生效的配置
connection = mysql+pymysql://glance:whj1218@controller/glance
www_authenticate_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 = whj1218
flavor = keystone
+----------------------------------+-----------+--------------+--------------+---------+-----------+-----------------------------+
[root@controller ~]# cp /etc/glance/glance-api.conf /etc/glance/glance-api.conf.bak
[root@controller ~]# grep '^[a-z[]' /etc/glance/glance-api.conf.bak >/etc/glance/glance-api.conf
[root@controller ~]# vim /etc/glance/glance-api.conf
[DEFAULT]
[cinder]
[cors]
[database]
connection = mysql+pymysql://glance:whj1218@controller/glance
[file]
[glance.store.http.store]
[glance.store.rbd.store]
[glance.store.sheepdog.store]
[glance.store.swift.store]
[glance.store.vmware_datastore.store]
[glance_store]
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/
[image_format]
[keystone_authtoken]
www_authenticate_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 = whj1218
[oslo_concurrency]
[oslo_messaging_amqp]
[oslo_messaging_kafka]
[oslo_messaging_notifications]
[oslo_messaging_rabbit]
[oslo_middleware]
[oslo_policy]
[paste_deploy]
flavor = keystone
[profiler]
[store_type_location_strategy]
[task]
[taskflow_executor]
[root@controller ~]# cp /etc/glance/glance-registry.conf /etc/glance/glance-registry.conf.bak
[root@controller ~]# grep '^[a-z[]' /etc/glance/glance-registry.conf.bak >/etc/glance/glance-registry.conf
[root@controller ~]# vim /etc/glance/glance-registry.conf
[DEFAULT]
[database]
connection = mysql+pymysql://glance:whj1218@controller/glance
[keystone_authtoken]
www_authenticate_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 = whj1218
[oslo_messaging_amqp]
[oslo_messaging_kafka]
[oslo_messaging_notifications]
[oslo_messaging_rabbit]
[oslo_policy]
[paste_deploy]
flavor = keystone
[profiler]
+----------------------------------+-----------+--------------+--------------+---------+-----------+-----------------------------+
4.同步glance数据库
1)为glance镜像服务初始化同步数据库
[root@controller ~]# su -s /bin/sh -c "glance-manage db_sync" glance #生成的相关表
2)同步完成进行连接测试
[root@controller ~]# mysql -h192.168.136.134 -uglance -pwhj1218 -e "use glance;show tables;"# 保证所有需要的表已经建立,否则后面可能无法进行下去
+----------------------------------+
| Tables_in_glance |
+----------------------------------+
| alembic_version |
| image_locations |
| image_members |
| image_properties |
| image_tags |
| images |
| metadef_namespace_resource_types |
| metadef_namespaces |
| metadef_objects |
| metadef_properties |
| metadef_resource_types |
| metadef_tags |
| migrate_version |
| task_info |
| tasks |
+----------------------------------+
[root@controller ~]# mysql -h192.168.136.134 -uglance -pwhj1218 -e "use glance;show tables;" |wc -l #统计生成的表有15张
16
5.启动glance镜像服务
1)启动glance镜像服务、并配置开机自启动
[root@controller ~]# systemctl start openstack-glance-api.service openstack-glance-registry.service #启动服务
[root@controller ~]# systemctl enable openstack-glance-api.service openstack-glance-registry.service#设置开机自启动
[root@controller ~]# systemctl status openstack-glance-api.service openstack-glance-registry.service#查看服务状态
[root@controller ~]# systemctl list-unit-files |grep openstack-glance*
openstack-glance-api.service enabled
openstack-glance-registry.service enabled
openstack-glance-scrubber.service disabled
6.检查确认glance安装正确
可以下载小型的Linux镜像CirrOS用来进行 OpenStack部署测试
[root@controller ~]# wget http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img #下载linux镜像cirros
[root@controller ~]# ls
anaconda-ks.cfg initial-setup-ks.cfg --os-project-domain-name 下载 图片 桌面 视频
cirros-0.3.5-x86_64-disk.img keystone-admin-pass.sh --os-project-name 公共 文档 模板 音乐
[root@controller ~]# mv cirros-0.3.5-x86_64-disk.img /opt/ #移到/opt/下
[root@controller ~]# ll /opt/
total 12960
-rw-r--r-- 1 root root 13267968 Jan 27 2020 cirros-0.3.5-x86_64-disk.img
drwxr-xr-x. 2 root root 6 Oct 31 2018 rh
[root@controller ~]# source keystone-admin-pass.sh #获取管理员权限
[root@controller ~]# openstack image create "cirros" --file /opt/cirros-0.3.5-x86_64-disk.img --disk-format qcow2 --container-format bare --public #上传镜像到glance,使用qcow2磁盘格式, bare容器格式上传镜像到镜像服务并设置公共可见,这样所有的项目都可以访问它
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field | Value |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| checksum | f8ab98ff5e73ebab884d80c9dc9c7290 |
| container_format | bare |
| created_at | 2020-07-30T13:35:51Z |
| disk_format | qcow2 |
| file | /v2/images/5cccad53-04cf-4554-87e2-66c47a6801d8/file |
| id | 5cccad53-04cf-4554-87e2-66c47a6801d8 |
| min_disk | 0 |
| min_ram | 0 |
| name | cirros |
| owner | 705ac96bcde14628b64e92c0d124825c |
| properties | os_hash_algo='sha512', os_hash_value='f0fd1b50420dce4ca382ccfbb528eef3a38bbeff00b54e95e3876b9bafe7ed2d6f919ca35d9046d437c6d2d8698b1174a335fbd66035bb3edc525d2cdb187232', os_hidden='False' |
| protected | False |
| schema | /v2/schemas/image |
| size | 13267968 |
| status | active |
| tags | |
| updated_at | 2020-07-30T13:35:51Z |
| virtual_size | None |
| visibility | public |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
[root@controller ~]# openstack image list #查看镜像
+--------------------------------------+--------+--------+
| ID | Name | Status |
+--------------------------------------+--------+--------+
| 5cccad53-04cf-4554-87e2-66c47a6801d8 | cirros | active |
+--------------------------------------+--------+--------+