OpenStack 镜像服务Glance [三]

摘要

创建虚拟机我们需要有glance的支持,因为glance是提供镜像服务,glance有两个比较重要的服务 Glance-api接受云系统镜像的构建、删除、读取请求 Glance-Registry云系统的镜像注册服务

OpenStack 镜像服务Glance [三]

openstack
时间:2016年11月28日

OpenStack镜像服务Glance介绍

创建虚拟机我们需要有glance的支持,因为glance是提供镜像服务
glance有两个比较重要的服务
Glance-api接受云系统镜像的构建、删除、读取请求
Glance-Registry云系统的镜像注册服务
image_1b289am7r11f85hn7714quj8h9.png-382.8kB
  我们需要配置glance-api的配置文件和glance-registry配置文件
  glance不需要配置消息队列,但是glance需要配置keystone(认证中心

提示:默认情况下上传镜像存放在/var/lib/glance/images

安装glance
创建数据库和在keystone上创建glance用户我们已经创建完成

安装软件包

  1. [root@linux-node1 ~]# yum install openstack-glance -y

修改数据库地址

  1. [root@linux-node1 ~]# vim /etc/glance/glance-api.conf
  2. [database]
  3. connection = mysql+pymysql://glance:glance@192.168.56.11/glance
  4. [root@linux-node1 ~]# vim /etc/glance/glance-registry.conf
  5. [database]
  6. connection = mysql+pymysql://glance:glance@192.168.56.11/glance
  7. #打开注释,写mysql地址,注意是在database默认下

修改完之后我们需要同步数据库

  1. [root@linux-node1 ~]# su -s /bin/sh -c "glance-manage db_sync" glance
  2. #替我们去创建表结构,openstack有警告没有关系,只要不是error就可以

同步完数据库之后我们进行检查

  1. [root@linux-node1 ~]# mysql -h 192.168.56.11 -u glance -pglance -e "use glance;show tables;"
  2. +----------------------------------+
  3. | Tables_in_glance |
  4. +----------------------------------+
  5. | artifact_blob_locations |
  6. | artifact_blobs |
  7. | artifact_dependencies |
  8. | artifact_properties |
  9. | artifact_tags |
  10. | artifacts |
  11. | image_locations |
  12. | image_members |
  13. | image_properties |
  14. | image_tags |
  15. | images |
  16. | metadef_namespace_resource_types |
  17. | metadef_namespaces |
  18. | metadef_objects |
  19. | metadef_properties |
  20. | metadef_resource_types |
  21. | metadef_tags |
  22. | migrate_version |
  23. | task_info |
  24. | tasks |
  25. +----------------------------------+

我们要确保数据库可以进行同步

设置keystone

[keystone_authtoken]进行设置

  1. [root@linux-node1 ~]# vim /etc/glance/glance-api.conf
  2. [keystone_authtoken]
  3. auth_uri = http://192.168.56.11:5000
  4. auth_url = http://192.168.56.11:35357
  5. memcached_servers = 192.168.56.11:11211
  6. auth_type = password #验证类型为密码
  7. project_domain_name = default #默认域
  8. user_domain_name = default #用户默认域
  9. project_name = service #项目名称
  10. username = glance #用户
  11. password = glance #密码

提示:必须复制在[keystone_authtoken]模块下,否则不生效
还需要设置[paste_deploy]模块

  1. [paste_deploy]
  2. flavor = keystone
  3. #去掉注释并修改为keystone

设置registry,和api的设置一样

  1. [root@linux-node1 ~]# vim /etc/glance/glance-registry.conf
  2. [keystone_authtoken]
  3. auth_uri = http://192.168.56.11:5000
  4. auth_url = http://192.168.56.11:35357
  5. memcached_servers = 192.168.56.11:11211
  6. auth_type = password
  7. project_domain_name = default
  8. user_domain_name = default
  9. project_name = service
  10. username = glance
  11. password = glance
  12. [paste_deploy]
  13. flavor = keystone

配置镜像路径
glance-api配置本地文件系统存储和镜像文件位置

  1. [root@linux-node1 ~]# vim /etc/glance/glance-api.conf
  2. [glance_store]
  3. stores = file,http
  4. default_store = file
  5. filesystem_store_datadir = /var/lib/glance/images
  6. #以上配置都是打开注释就可以

检查
glance-api配置文件配置小结:

  1. [root@linux-node1 ~]# grep '^[a-z]' /etc/glance/glance-api.conf
  2. connection = mysql+pymysql://glance:glance@192.168.56.11/glance
  3. stores = file,http
  4. default_store = file
  5. filesystem_store_datadir = /var/lib/glance/images
  6. auth_uri = http://192.168.56.11:5000
  7. auth_url = http://192.168.56.11:35357
  8. memcached_servers = 192.168.56.11:11211
  9. auth_type = password
  10. project_domain_name = default
  11. user_domain_name = default
  12. project_name = service
  13. username = glance
  14. password = glance
  15. flavor = keystone

registry配置如下

  1. [root@linux-node1 ~]# grep '^[a-z]' /etc/glance/glance-registry.conf
  2. connection = mysql+pymysql://glance:glance@192.168.56.11/glance
  3. auth_uri = http://192.168.56.11:5000
  4. auth_url = http://192.168.56.11:35357
  5. memcached_servers = 192.168.56.11:11211
  6. auth_type = password
  7. project_domain_name = default
  8. user_domain_name = default
  9. project_name = service
  10. username = glance
  11. password = glance
  12. flavor = keystone
  13. 提示:registryapi的配置跟我一样现在我们就可以启动了

设置开启启动并开启服务

  1. [root@linux-node1 ~]# systemctl enable openstack-glance-api.service
  2. [root@linux-node1 ~]# systemctl enable openstack-glance-registry.service
  3. [root@linux-node1 ~]# systemctl start openstack-glance-api.service
  4. [root@linux-node1 ~]# systemctl start openstack-glance-registry.service

image_1b2kdnfi710p31rpf2lj1j5nig19.png-95.6kB

提示:9292glance-api的端口,9191glance-registry的端口

在keystone上设置服务注册
1.创建服务

  1. [root@linux-node1 ~]# source admin-openstack.sh
  2. [root@linux-node1 ~]# openstack service create --name glance --description "OpenStack Image" image
  3. +-------------+----------------------------------+
  4. | Field | Value |
  5. +-------------+----------------------------------+
  6. | description | OpenStack Image |
  7. | enabled | True |
  8. | id | c9fd28645efe45faa2a9cf2f2cce623e |
  9. | name | glance |
  10. | type | image |
  11. +-------------+----------------------------------+

2.创建镜像服务的API端点

  1. [root@linux-node1 ~]# openstack endpoint create --region RegionOne \
  2. > image public http://192.168.56.11:9292
  3. +--------------+----------------------------------+
  4. | Field | Value |
  5. +--------------+----------------------------------+
  6. | enabled | True |
  7. | id | cabb8016fef74b438a341866ef10917f |
  8. | interface | public |
  9. | region | RegionOne |
  10. | region_id | RegionOne |
  11. | service_id | c9fd28645efe45faa2a9cf2f2cce623e |
  12. | service_name | glance |
  13. | service_type | image |
  14. | url | http://192.168.56.11:9292 |
  15. +--------------+----------------------------------+
  16. [root@linux-node1 ~]# openstack endpoint create --region RegionOne image internal http://192.168.56.11:9292
  17. +--------------+----------------------------------+
  18. | Field | Value |
  19. +--------------+----------------------------------+
  20. | enabled | True |
  21. | id | 0bafb4e5d90745d789a16c97fc3f5688 |
  22. | interface | internal |
  23. | region | RegionOne |
  24. | region_id | RegionOne |
  25. | service_id | c9fd28645efe45faa2a9cf2f2cce623e |
  26. | service_name | glance |
  27. | service_type | image |
  28. | url | http://192.168.56.11:9292 |
  29. +--------------+----------------------------------+
  30. [root@linux-node1 ~]# openstack endpoint create --region RegionOne image admin http://192.168.56.11:9292
  31. +--------------+----------------------------------+
  32. | Field | Value |
  33. +--------------+----------------------------------+
  34. | enabled | True |
  35. | id | 911d06d783094d62bf2cf97e4dd3fed6 |
  36. | interface | admin |
  37. | region | RegionOne |
  38. | region_id | RegionOne |
  39. | service_id | c9fd28645efe45faa2a9cf2f2cce623e |
  40. | service_name | glance |
  41. | service_type | image |
  42. | url | http://192.168.56.11:9292 |
  43. +--------------+----------------------------------+

测试
我们可以使用openstack list或者glance list进行查看

  1. [root@linux-node1 ~]# openstack image list
  2. [root@linux-node1 ~]# glance image-list
  3. +----+------+
  4. | ID | Name |
  5. +----+------+
  6. +----+------+

提示:如果此处没有出现空,那么这时候就需要看日志了。

最后我们可以上传一个镜像进行测试

  1. [root@linux-node1 ~]# wget http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img

我们下载上面的镜像进行测试

  1. [root@linux-node1 ~]# openstack image create "cirros" \
  2. > --file cirros-0.3.4-x86_64-disk.img \
  3. > --disk-format qcow2 --container-format bare \
  4. > --public
  5. +------------------+------------------------------------------------------+
  6. | Field | Value |
  7. +------------------+------------------------------------------------------+
  8. | checksum | ee1eca47dc88f4879d8a229cc70a07c6 |
  9. | container_format | bare |
  10. | created_at | 2016-11-17T10:34:14Z |
  11. | disk_format | qcow2 |
  12. | file | /v2/images/fc67361d-ad30-40b2-9d96-941e50fc17f5/file |
  13. | id | fc67361d-ad30-40b2-9d96-941e50fc17f5 |
  14. | min_disk | 0 |
  15. | min_ram | 0 |
  16. | name | cirros |
  17. | owner | 026a58f98402437fa95ef4a21fbd4d1a |
  18. | protected | False |
  19. | schema | /v2/schemas/image |
  20. | size | 13287936 |
  21. | status | active |
  22. | tags | |
  23. | updated_at | 2016-11-17T10:34:14Z |
  24. | virtual_size | None |
  25. | visibility | public |
  26. +------------------+------------------------------------------------------+

#提示:如果没有环境变量还需要source一下

检查是否上传成功

  1. [root@linux-node1 ~]# openstack image list
  2. +--------------------------------------+--------+--------+
  3. | ID | Name | Status |
  4. +--------------------------------------+--------+--------+
  5. | fc67361d-ad30-40b2-9d96-941e50fc17f5 | cirros | active |
  6. +--------------------------------------+--------+--------+
  7. [root@linux-node1 ~]# glance image-list
  8. +--------------------------------------+--------+
  9. | ID | Name |
  10. +--------------------------------------+--------+
  11. | fc67361d-ad30-40b2-9d96-941e50fc17f5 | cirros |
  12. +--------------------------------------+--------+
  13. [root@linux-node1 ~]# ls /var/lib/glance/images/
  14. fc67361d-ad30-40b2-9d96-941e50fc17f5
  15. 镜像存放在/var/lib/glance/images

[M版本]
官方中文文档:http://docs.openstack.org/mitaka/zh_CN/install-guide-rdo/keystone-install.html

image_1b2kejcd9lfq13h31f5g1897oopm.png-58.1kB


新闻联播老司机

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:2   其中:访客  2   博主  0

  1. avatar 木比白 0
    老哥,你坑我啊,那个glance.api和glance.registry 配置文件中:project_domain_name = default、user_domain_name = default之前你创建的域是首字母大写的,也就是Default,搞得一直出错,浪费了一个下午
    • avatar 新闻联播老司机 3
      是不是版本的问题导致的,之前配置文件设置的就是首字母大写的。