openstack搭建--4--控制节点安装配置glance
在 OpenStack 中,提供 Image Service 的是 Glance,其具体功能如下:
1. 提供 REST API 让用户能够查询和获取 image 的元数据和 image 本身
2. 支持多种方式存储 image,包括普通的文件系统、Swift、Amazon S3 等
3. 对 Instance 执行 Snapshot 创建新的 image
上面是 Glance 的架构图
glance-api
glance-api 是系统后台运行的服务进程。 对外提供 REST API,响应 image 查询、获取和存储的调用。
glance-api 不会真正处理请求。 如果是与 image metadata(元数据)相关的操作,glance-api 会把请求转发给 glance-registry;
如果是与 image 自身存取相关的操作,glance-api 会把请求转发给该 image 的 store backend。
glance-registry
glance-registry 是系统后台运行的服务进程。 负责处理和存取 image 的 metadata,例如 image 的大小和类型。
glance-store
image 的元数据 通过glance-registry 存放在 db 中; image 的chunk 数据 通过 glance-store 存放在各种 backend store 中,并从中获取
支持多种方式存储 image,包括普通的文件系统、Swift、Amazon S3、GlusterFS 等
registry在api后面,它的作用和mysql打交道,存储镜像的属性registry监听9191端口,glance-api监听9292端口
配置glance服务,要配置2个配置文件,1个api和1个registry
glance不需要配置消息队列,但是需要配置keystone
镜像默认在下面路径下,这个目录是 /var/lib/glance/images/。
安装并配置组件
安装软件包[[email protected] ~]# yum install openstack-glance -y
配置部分---数据库部分
1、编辑文件 /etc/glance/glance-api.conf:在 [database] 部分,配置数据库访问
connection = mysql+pymysql://glance:[email protected]/glance
2、编辑文件 /etc/glance/glance-registry.conf:
在 [database] 部分,配置数据库访问(382行左右):
connection = mysql+pymysql://glance:[email protected]/glance
3.同步数据库
[[email protected] ~]# su -s /bin/sh -c "glance-manage db_sync" glance
Option "verbose" from group "DEFAULT" is deprecated for removal. Its value may be silently ignored in the future.
/usr/lib/python2.7/site-packages/oslo_db/sqlalchemy/enginefacade.py:1056: OsloDBDeprecationWarning: EngineFacade is deprecated; please use oslo_db.sqlalchemy.enginefacade
expire_on_commit=expire_on_commit, _conf=conf)
检查同步结果
[[email protected] ~]# mysql -h192.168.1.2 -uglance -pglance -e "use glance;show tables;"
+----------------------------------+
| Tables_in_glance |
+----------------------------------+
| artifact_blob_locations |
| artifact_blobs |
| artifact_dependencies |
| artifact_properties |
| artifact_tags |
| artifacts |
| 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 |
+----------------------------------+
[[email protected] ~]#
配置部分---设置keystone
编辑文件 /etc/glance/glance-api.conf 并完成如下动作
在 [keystone_authtoken] 和 [paste_deploy] 部分,配置认证服务访问:
[keystone_authtoken]下添加下面参数
auth_uri = http://192.168.1.2:5000auth_url = http://192.168.1.2:35357
memcached_servers = 192.168.1.2:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = glance
password = glance
[paste_deploy] 下添加下面参数
flavor = keystone
619:connection = mysql+pymysql://glance:[email protected]/glance
1112:auth_uri = http://192.168.1.2:5000
1113:auth_url = http://192.168.1.2:35357
1114:memcached_servers = 192.168.1.2:11211
1115:auth_type = password
1116:project_domain_name = default
1117:user_domain_name = default
1118:project_name = service
1119:username = glance
1120:password = glance
1685:flavor = keystone
编辑/etc/glance/glance-registry.conf
在 [keystone_authtoken] 和 [paste_deploy] 部分,配置认证服务访问,配置内容和上面一样:
[[email protected] ~]# grep -n "^[a-Z]" /etc/glance/glance-registry.conf
360:connection = mysql+pymysql://glance:[email protected]/glance
837:auth_uri = http://192.168.1.2:5000
838:auth_url = http://192.168.1.2:35357
839:memcached_servers = 192.168.1.2:11211
840:auth_type = password
841:project_domain_name = default
842:user_domain_name = default
843:project_name = service
844:username = glance
845:password = glance
1392:flavor = keystone
在 [glance_store] 部分,配置本地文件系统存储和镜像文件位置
在下面模块下取消这3行的注释,可以通过搜索定位
[glance_store]
...
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images
619:connection = mysql+pymysql://glance:[email protected]/glance
741:stores = file,http
746:default_store = file
1025:filesystem_store_datadir = /var/lib/glance/images
1112:auth_uri = http://192.168.1.2:5000
1113:auth_url = http://192.168.1.2:35357
1114:memcached_servers = 192.168.1.2:11211
1115:auth_type = password
1116:project_domain_name = default
1117:user_domain_name = default
1118:project_name = service
1119:username = glance
1120:password = glance
1685:flavor = keystone
启动glance相关服务
[[email protected] ~]# systemctl enable openstack-glance-api.service openstack-glance-registry.service
Created symlink from /etc/systemd/system/multi-user.target.wants/openstack-glance-api.service to /usr/lib/systemd/system/openstack-glance-api.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/openstack-glance-registry.service to /usr/lib/systemd/system/openstack-glance-registry.service.
[[email protected] ~]# systemctl start openstack-glance-api.service openstack-glance-registry.service
查看监听状态
registry监听9191端口
glance-api监听9292端口
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2287/mysqld
tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 913/memcached
tcp 0 0 0.0.0.0:9292 0.0.0.0:* LISTEN 5214/python2
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 915/httpd
tcp 0 0 0.0.0.0:4369 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 997/sshd
tcp 0 0 0.0.0.0:15672 0.0.0.0:* LISTEN 907/beam
tcp 0 0 0.0.0.0:35357 0.0.0.0:* LISTEN 915/httpd
tcp 0 0 0.0.0.0:9191 0.0.0.0:* LISTEN 5215/python2
tcp 0 0 0.0.0.0:25672 0.0.0.0:* LISTEN 907/beam
tcp 0 0 0.0.0.0:5000 0.0.0.0:* LISTEN 915/httpd
tcp6 0 0 :::22 :::* LISTEN 997/sshd
tcp6 0 0 :::5672 :::* LISTEN 907/beam
在keystone上做服务注册
下面3步在之前都已经做了
1、之前glance的数据库创建完毕2、 glance 用户创建完毕
openstack user create --domain default --password-prompt glance
3、添加 admin 角色到 glance 用户和 service 项目上。
openstack role add --project service --user glance admin
接下来创建实体
1、创建glance服务实体,操作之前先source环境变量
[[email protected] ~]# source admin-openstack.sh
[[email protected] ~]# openstack service create --name glance --description "OpenStack Image" image
+-------------+----------------------------------+
| Field | Value |
+-------------+----------------------------------+
| description | OpenStack Image |
| enabled | True |
| id | 453a37cc31754678b54cd1d223ecba46 |
| name | glance |
| type | image |
+-------------+----------------------------------+
2、创建镜像服务的 API 端点
(keystone的admin端口特殊,和public以及internal不一样)
公共的
[[email protected] ~]# openstack endpoint create --region RegionOne image public http://192.168.1.2:9292+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | a9d523d1658c4ef9a43e9c1ee61afab8 |
| interface | public |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 453a37cc31754678b54cd1d223ecba46 |
| service_name | glance |
| service_type | image |
| url | http://192.168.1.2:9292 |
+--------------+----------------------------------+
内部的
[[email protected] ~]# openstack endpoint create --region RegionOne image internal http://192.168.1.2:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | b35e5ed5c01d4dffacb80f754da68e9b |
| interface | internal |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 453a37cc31754678b54cd1d223ecba46 |
| service_name | glance |
| service_type | image |
| url | http://192.168.1.2:9292 |
+--------------+----------------------------------+
管理的
[[email protected] ~]# openstack endpoint create --region RegionOne image admin http://192.168.1.2:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | a255bcfb2cb24197b27b4aae9d64a677 |
| interface | admin |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 453a37cc31754678b54cd1d223ecba46 |
| service_name | glance |
| service_type | image |
| url | http://192.168.1.2:9292 |
+--------------+----------------------------------+
3、查看镜像列表
下面为空很正常,因为还没导入镜像呢
[[email protected] ~]# openstack image list[[email protected] ~]# glance image-list
+----+------+
| ID | Name |
+----+------+
+----+------+
4、导入镜像
下载小镜像wget http:
//download
.cirros-cloud.net
/0
.3.4
/cirros-0
.3.4-x86_64-disk.img
[[email protected] ~]# openstack image create "cirros" --file cirros-0.3.4-x86_64-disk.img --disk-format qcow2 --container-format bare --public
+------------------+------------------------------------------------------+
| Field | Value |
+------------------+------------------------------------------------------+
| checksum | ee1eca47dc88f4879d8a229cc70a07c6 |
| container_format | bare |
| created_at | 2017-08-02T06:28:50Z |
| disk_format | qcow2 |
| file | /v2/images/b7fb24c1-b6d5-42bf-af36-20fbd9a66239/file |
| id | b7fb24c1-b6d5-42bf-af36-20fbd9a66239 |
| min_disk | 0 |
| min_ram | 0 |
| name | cirros |
| owner | 883e2da5c2444e238e7ca1f02328b6b8 |
| protected | False |
| schema | /v2/schemas/image |
| size | 13287936 |
| status | active |
| tags | |
| updated_at | 2017-08-02T06:28:52Z |
| virtual_size | None |
| visibility | public |
+------------------+------------------------------------------------------+
5、导入完毕,查看
[[email protected] ~]# openstack image list
+--------------------------------------+--------+--------+
| ID | Name | Status |
+--------------------------------------+--------+--------+
| b7fb24c1-b6d5-42bf-af36-20fbd9a66239 | cirros | active |
+--------------------------------------+--------+--------+
[[email protected] ~]# glance image-list
+--------------------------------------+--------+
| ID | Name |
+--------------------------------------+--------+
| b7fb24c1-b6d5-42bf-af36-20fbd9a66239 | cirros |
+--------------------------------------+--------+
文件在此路径下,文件名和镜像ID一致
[[email protected] images]# cd /var/lib/glance/images/
[[email protected] images]# ls -l
total 12980
-rw-r----- 1 glance glance 13287936 Aug 2 14:28 b7fb24c1-b6d5-42bf-af36-20fbd9a66239