zoukankan      html  css  js  c++  java
  • openstack--4--控制节点安装配置glance

    Glance相关介绍


     

    image Service 的功能是管理 Image,让用户能够发现、获取和保存 Image。
    在 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/。

    安装并配置组件


     

    安装软件包
    [root@linux-node1 ~]# yum install openstack-glance -y
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: mirrors.163.com
     * epel: mirror01.idc.hinet.net
     * extras: mirrors.163.com
     * updates: mirrors.163.com
    Package 1:openstack-glance-12.0.0-1.el7.noarch already installed and latest version
    Nothing to do
    [root@linux-node1 ~]# 
    

      

    配置部分---数据库部分

    1、编辑文件 /etc/glance/glance-api.conf:
    在 [database] 部分,配置数据库访问(大概在641行):

    [root@linux-node1 ~]# vim /etc/glance/glance-api.conf
    connection = mysql+pymysql://glance:glance@192.168.56.11/glance
    

    2、编辑文件 /etc/glance/glance-registry.conf:
    在 [database] 部分,配置数据库访问(382行左右):

    [root@linux-node1 ~]# vim /etc/glance/glance-registry.conf
    connection = mysql+pymysql://glance:glance@192.168.56.11/glance
    
    3、同步数据库。
    有警告,openstack有警告没关系,只要不是error即可
    [root@linux-node1 ~]# 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)
    [root@linux-node1 ~]# 
    
    检查同步结果
    [root@linux-node1 ~]# mysql -h192.168.56.11 -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                            |
    +----------------------------------+
    [root@linux-node1 ~]# 
    

      

     

    配置部分---设置keystone

    编辑文件 /etc/glance/glance-api.conf 并完成如下动作
    在 [keystone_authtoken] 和 [paste_deploy] 部分,配置认证服务访问:

     [keystone_authtoken]下添加下面参数

    auth_uri = http://192.168.56.11:5000
    auth_url = http://192.168.56.11:35357
    memcached_servers = 192.168.56.11:11211
    auth_type = password
    project_domain_name = default
    user_domain_name = default
    project_name = service
    username = glance
    password = glance
    

     下面模块下改成如下

    以上操作,配置文件更改的部分如下
    [root@linux-node1 ~]# grep -n "^[a-Z]"  /etc/glance/glance-api.conf
    641:connection = mysql+pymysql://glance:glance@192.168.56.11/glance
    1112:auth_uri = http://192.168.56.11:5000
    1113:auth_url = http://192.168.56.11:35357
    1114:memcached_servers = 192.168.56.11: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
    1695:flavor = keystone
    [root@linux-node1 ~]# 
    

      

    编辑/etc/glance/glance-registry.conf
    在 [keystone_authtoken] 和 [paste_deploy] 部分,配置认证服务访问,配置内容和上面一样:

     

    glance-registry.conf 修改的地方
    [root@linux-node1 ~]# grep -n "^[a-Z]"  /etc/glance/glance-registry.conf 
    382:connection = mysql+pymysql://glance:glance@192.168.56.11/glance
    837:auth_uri = http://192.168.56.11:5000
    838:auth_url = http://192.168.56.11:35357
    839:memcached_servers = 192.168.56.11: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
    1402:flavor = keystone
    [root@linux-node1 ~]# 
    

      

     

    配置部分----设置镜像位置

    /etc/glance/glance-api.conf
    在 [glance_store] 部分,配置本地文件系统存储和镜像文件位置
    在下面模块下取消这3行的注释,可以通过搜索定位

    [glance_store]
    ...
    stores = file,http
    default_store = file
    filesystem_store_datadir = /var/lib/glance/images/
     
     
    最终/etc/glance/glance-api.conf改动如下
    [root@linux-node1 ~]# grep -n "^[a-Z]"  /etc/glance/glance-api.conf
    641:connection = mysql+pymysql://glance:glance@192.168.56.11/glance
    741:stores = file,http
    746:default_store = file
    1025:filesystem_store_datadir = /var/lib/glance/images
    1112:auth_uri = http://192.168.56.11:5000
    1113:auth_url = http://192.168.56.11:35357
    1114:memcached_servers = 192.168.56.11: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
    1695:flavor = keystone
    [root@linux-node1 ~]# 
    

      

     启动glance相关服务


     

    glance配置部分完毕,可以启动glance服务了
    [root@linux-node1 ~]# 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.
    [root@linux-node1 ~]# systemctl start openstack-glance-api.service  openstack-glance-registry.service
    [root@linux-node1 ~]# 
    

    查看监听状态
    registry监听9191端口
    glance-api监听9292端口

    [root@linux-node1 ~]# netstat -lntp 
    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:9191            0.0.0.0:*               LISTEN      9299/python2        
    tcp        0      0 0.0.0.0:5000            0.0.0.0:*               LISTEN      7352/httpd          
    tcp        0      0 0.0.0.0:25672           0.0.0.0:*               LISTEN      4916/beam.smp       
    tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      1615/mysqld         
    tcp        0      0 0.0.0.0:11211           0.0.0.0:*               LISTEN      7479/memcached      
    tcp        0      0 0.0.0.0:9292            0.0.0.0:*               LISTEN      9298/python2        
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      7352/httpd          
    tcp        0      0 0.0.0.0:4369            0.0.0.0:*               LISTEN      1/systemd           
    tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      1745/dnsmasq        
    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1160/sshd           
    tcp        0      0 0.0.0.0:15672           0.0.0.0:*               LISTEN      4916/beam.smp       
    tcp        0      0 0.0.0.0:35357           0.0.0.0:*               LISTEN      7352/httpd          
    tcp6       0      0 :::5672                 :::*                    LISTEN      4916/beam.smp       
    tcp6       0      0 :::22                   :::*                    LISTEN      1160/sshd           
    [root@linux-node1 ~]# 
    

      

    在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环境变量

    [root@linux-node1 ~]# source admin-openstack.sh 
    [root@linux-node1 ~]# openstack service create --name glance  --description "OpenStack Image" image
    +-------------+----------------------------------+
    | Field       | Value                            |
    +-------------+----------------------------------+
    | description | OpenStack Image                  |
    | enabled     | True                             |
    | id          | a7cdacff3e804796a7dbf466c616c5ec |
    | name        | glance                           |
    | type        | image                            |
    +-------------+----------------------------------+
    [root@linux-node1 ~]# 
    

      

    2、创建镜像服务的 API 端点
    public,internal,admin 这3个,端口一致
    (keystone的admin端口特殊,和public以及internal不一样)

    公共的

    [root@linux-node1 ~]# openstack endpoint create --region RegionOne  image public http://192.168.56.11:9292
    +--------------+----------------------------------+
    | Field        | Value                            |
    +--------------+----------------------------------+
    | enabled      | True                             |
    | id           | 4bfca46d433c4f2ebfc2c57ab6f50004 |
    | interface    | public                           |
    | region       | RegionOne                        |
    | region_id    | RegionOne                        |
    | service_id   | a7cdacff3e804796a7dbf466c616c5ec |
    | service_name | glance                           |
    | service_type | image                            |
    | url          | http://192.168.56.11:9292        |
    +--------------+----------------------------------+
    [root@linux-node1 ~]# 
    

    内部的  

    [root@linux-node1 ~]# openstack endpoint create --region RegionOne  image internal http://192.168.56.11:9292
    +--------------+----------------------------------+
    | Field        | Value                            |
    +--------------+----------------------------------+
    | enabled      | True                             |
    | id           | c16ae753c62c427194ae2b70655623c5 |
    | interface    | internal                         |
    | region       | RegionOne                        |
    | region_id    | RegionOne                        |
    | service_id   | a7cdacff3e804796a7dbf466c616c5ec |
    | service_name | glance                           |
    | service_type | image                            |
    | url          | http://192.168.56.11:9292        |
    +--------------+----------------------------------+
    [root@linux-node1 ~]# 
    

    管理的  

    [root@linux-node1 ~]# openstack endpoint create --region RegionOne   image admin http://192.168.56.11:9292
    +--------------+----------------------------------+
    | Field        | Value                            |
    +--------------+----------------------------------+
    | enabled      | True                             |
    | id           | 27ed39831e434c73ab2b400f1a1a4ab6 |
    | interface    | admin                            |
    | region       | RegionOne                        |
    | region_id    | RegionOne                        |
    | service_id   | a7cdacff3e804796a7dbf466c616c5ec |
    | service_name | glance                           |
    | service_type | image                            |
    | url          | http://192.168.56.11:9292        |
    +--------------+----------------------------------+
    [root@linux-node1 ~]# 
    

      

    3、查看镜像列表

    下面为空很正常,因为还没导入镜像呢

    [root@linux-node1 ~]# openstack image list
    
    [root@linux-node1 ~]# glance image-list
    +----+------+
    | ID | Name |
    +----+------+
    +----+------+
    [root@linux-node1 ~]# 
    

      

    4、导入镜像

    下载小镜像

    wget http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img
    

      

    使用 QCOW2 磁盘格式, bare 容器格式上传镜像到镜像服务并设置公共可见,这样所有的项目都可以访问它
    命令如下,注意操作时镜像是在本目录下,如果不是本目录需要写绝对路径
    openstack image create "cirros" 
      --file cirros-0.3.4-x86_64-disk.img 
      --disk-format qcow2 --container-format bare 
      --public
     
    操作如下
    [root@linux-node1 ~]# 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-02-17T16:26:40Z                                |
    | disk_format      | qcow2                                               |
    | file             | /v2/images/9969eaa3-0296-48cc-a42e-                 |
    |                  | a02251b778a6/file                                   |
    | id               | 9969eaa3-0296-48cc-a42e-a02251b778a6                |
    | min_disk         | 0                                                   |
    | min_ram          | 0                                                   |
    | name             | cirros                                              |
    | owner            | e88437b3330145e1a713469130b4c3cd                    |
    | protected        | False                                               |
    | schema           | /v2/schemas/image                                   |
    | size             | 13287936                                            |
    | status           | active                                              |
    | tags             |                                                     |
    | updated_at       | 2017-02-17T16:26:40Z                                |
    | virtual_size     | None                                                |
    | visibility       | public                                              |
    +------------------+-----------------------------------------------------+
    [root@linux-node1 ~]# 
    

    5、导入完毕,查看

    [root@linux-node1 ~]# openstack image list
    +--------------------------------------+--------+--------+
    | ID                                   | Name   | Status |
    +--------------------------------------+--------+--------+
    | 9969eaa3-0296-48cc-a42e-a02251b778a6 | cirros | active |
    +--------------------------------------+--------+--------+
    [root@linux-node1 ~]# glance image-list
    +--------------------------------------+--------+
    | ID                                   | Name   |
    +--------------------------------------+--------+
    | 9969eaa3-0296-48cc-a42e-a02251b778a6 | cirros |
    +--------------------------------------+--------+
    [root@linux-node1 ~]# 
    

      

     文件在此路径下,文件名和镜像ID一致

    [root@linux-node1 images]# cd /var/lib/glance/images/
    [root@linux-node1 images]# ls -l
    total 12980
    -rw-r----- 1 glance glance 13287936 Feb 18 00:26 9969eaa3-0296-48cc-a42e-a02251b778a6
    [root@linux-node1 images]# 
    

      

  • 相关阅读:
    观察者模式(学习笔记17)
    web前端安全编码(模版篇)
    如何获取元素最终使用的css值
    Range在各浏览器下的问题和常见处理办法
    总结cookie的一些问题
    js 设计模式单例模式
    web端不能登录问题汇总
    多域名登录方案思考
    深入分析js中的constructor 和prototype
    由一次代码优化想到的Js 数据类型
  • 原文地址:https://www.cnblogs.com/nmap/p/6416782.html
Copyright © 2011-2022 走看看