三,openstack之glance服务的安装

openstack之镜像服务glance的安装

一,glance服务简介

Glance是Openstack镜像服务组件,监听在9292端口,接收REST API请求,通过其它模块来完成镜像的获取,上传,删除等。

在创建虚拟机的时候,先把镜像上传到glace,

glance-api接收镜像的删除、上传和读取;
glance-registry(port:9191)与mysql交互,存储获取镜像的元数据。

glance数据库有两张表,一张image表,一张image property表:保存了镜像格式、大小等信息

image store是一个存储的接口层,通过这个接口glance可以获取镜像

二,glance的安装

1,openstack安装服务的通用步骤

1,创库授权

2,在keystone创建用户,关联角色

3,在keystone上创建服务,注册api

4,安装服务相关的软件包

5,修改配置

  • 数据库的连接
  • keystone的认证授权信息
  • rabbitmq的连接信息
  • 其他服务的连接配置

6,同步数据库,创建表

7,启动服务

2,安装配置glance

1,创建glance库并授权

[root@controller ~]# mysql -uroot -p***

MariaDB [(none)]> CREATE DATABASE glance;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'GLANCE_DBPASS';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'GLANCE_DBPASS';

2,导入admin用户的环境变量,创建glance用户并授权

source admin-openrc   #应用admin的环境变量
openstack user create --domain default --password GLANCE_PASS glance #创建glance用户
openstack role add --project service --user glance admin #关联角色,给glance用户授权

[root@controller ~]# openstack role assignment list  #查看授权的用户
+----------------------------------+----------------------------------+-------+----------------------------------+--------+--------+-----------+
| Role                             | User                             | Group | Project                          | Domain | System | Inherited |
+----------------------------------+----------------------------------+-------+----------------------------------+--------+--------+-----------+
| 38f0eca02ff449ddb5645c03edf6ea95 | 6d5b2f95c05248e5b0534e22b71a1780 |       | 695024d064f84bcfa5a48170b4519fad |        |        | False     |
| 8ec87a64484944d88e93d2a59f55bfe0 | 84a0c3edd86a416a9c5bf0196e724843 |       | 695024d064f84bcfa5a48170b4519fad |        |        | False     |
| 38f0eca02ff449ddb5645c03edf6ea95 | c5d3016e0873403487102264a4ba09e4 |       | 4c0a56c8e5444a73a1eb0a4e3cb3d4a7 |        |        | False     |
| 38f0eca02ff449ddb5645c03edf6ea95 | c5d3016e0873403487102264a4ba09e4 |       |                                  |        | all    | False     |
+----------------------------------+----------------------------------+-------+----------------------------------+--------+--------+-----------+

3,创建glance服务并注册API

openstack service create --name glance \
  --description "OpenStack Image" image
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Image                  |
| enabled     | True                             |
| id          | 29c34febca274d90a47bd23623267ca1 |
| name        | glance                           |
| type        | image                            |
+-------------+----------------------------------+

openstack endpoint create --region RegionOne \
  image public http://controller:9292                 #注册公共API
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | bdeb1eb06bb94e80acbf2c41c40772da |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 29c34febca274d90a47bd23623267ca1 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+
  
openstack endpoint create --region RegionOne \
  image internal http://controller:9292                # 注册内部使用API
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | bc163af48a7342b393a66f37e2184b69 |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 29c34febca274d90a47bd23623267ca1 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+

openstack endpoint create --region RegionOne \ 
  image admin http://controller:9292                      #注册管理员API
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 9ca3abd29a754dd0ae646a3cf7d16da6 |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 29c34febca274d90a47bd23623267ca1 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+
  

4,安装glance并配置

yum install openstack-glance -y

cp /etc/glance/glance-api.conf /etc/glance/glance-api.conf.bak
grep -Ev '^$|#' /etc/glance/glance-api.conf.bak > /etc/glance/glance-api.conf

vim /etc/glance/glance-api.conf  #配置glance-api.conf
[database]
# ...
connection = mysql+pymysql://glance:GLANCE_DBPASS@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 = GLANCE_PASS

[paste_deploy]
# ...
flavor = keystone

[glance_store]          #配置本地文件系统存储和镜像文件的位置
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/

su -s /bin/sh -c "glance-manage db_sync" glance   #初始化生成glance数据库

# 启动映像服务,并将其配置为在系统引导时启动:
systemctl enable openstack-glance-api.service
systemctl start openstack-glance-api.service

#查看9292端口启动,即说明glance安装成功
ss -tnlp 
LISTEN     0      128     *:9292  *:*                   
users:(("glance-api",pid=2494,fd=4),("glance-api",pid=2482,fd=4))

3,通过实验验证glance服务

下载一个cirros镜像(cirros是一个很小的Linux系统),验证glance的安装

source admin-openrc #在admin用户下
wget http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img  (如果下载慢,也可以在windows下使用迅雷等工具下载,然后上传到控制节点的root目录下)

openstack image create --file /root/cirros-0.4.0-x86_64-disk.img --disk-format qcow2 --container-format bare --public cirros #(官方文档坑点之一,这里不要使用官方文档里面的glance image-create这样的写法,新版本的OpenStack已经不支持,尽量统一使用以openstack开头的命令写法)
# --disk-format qcow2 镜像的格式为qcow2格式
# --container-format bare  容器类型,bare即为普通虚拟机镜像
# --public cirros 

执行结果如图一,再查看image list如图二,查看存放镜像目录如图三,证明glance服务正常运行

至此,glance服务安装完成

posted @ 2019-12-26 16:02  戴红领巾的少年  阅读(752)  评论(0编辑  收藏  举报
感谢您的阅读,如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮。本文欢迎各位转载,但是转载文章之后必须在文章页面中给出作者和原文连接