设为首页 收藏本站
查看: 926|回复: 0

[经验分享] openstack--4--控制节点安装配置glance

[复制链接]

尚未签到

发表于 2017-6-26 19:31:22 | 显示全部楼层 |阅读模式
Glance相关介绍



  image Service 的功能是管理 Image,让用户能够发现、获取和保存 Image。
在 OpenStack 中,提供 Image Service 的是 Glance,其具体功能如下:
  1. 提供 REST API 让用户能够查询和获取 image 的元数据和 image 本身
  2. 支持多种方式存储 image,包括普通的文件系统、Swift、Amazon S3 等
  3. 对 Instance 执行 Snapshot 创建新的 image
DSC0000.png

  上面是 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/。

安装并配置组件





安装软件包


[iyunv@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
[iyunv@linux-node1 ~]#

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



[iyunv@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行左右):



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


3、同步数据库。



有警告,openstack有警告没关系,只要不是error即可


[iyunv@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)
[iyunv@linux-node1 ~]#


检查同步结果


[iyunv@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                            |
+----------------------------------+
[iyunv@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

DSC0001.png

  下面模块下改成如下
DSC0002.png



以上操作,配置文件更改的部分如下


[iyunv@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
[iyunv@linux-node1 ~]#

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

DSC0004.png



glance-registry.conf 修改的地方


[iyunv@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
[iyunv@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改动如下


[iyunv@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
[iyunv@linux-node1 ~]#


启动glance相关服务





glance配置部分完毕,可以启动glance服务了


[iyunv@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.
[iyunv@linux-node1 ~]# systemctl start openstack-glance-api.service  openstack-glance-registry.service
[iyunv@linux-node1 ~]#

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



[iyunv@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           
[iyunv@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环境变量



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

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



[iyunv@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        |
+--------------+----------------------------------+
[iyunv@linux-node1 ~]#

  内部的  



[iyunv@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        |
+--------------+----------------------------------+
[iyunv@linux-node1 ~]#

  管理的  



[iyunv@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        |
+--------------+----------------------------------+
[iyunv@linux-node1 ~]#

  3、查看镜像列表
  下面为空很正常,因为还没导入镜像呢



[iyunv@linux-node1 ~]# openstack image list
[iyunv@linux-node1 ~]# glance image-list
+----+------+
| ID | Name |
+----+------+
+----+------+
[iyunv@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



操作如下


[iyunv@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                                              |
+------------------+-----------------------------------------------------+
[iyunv@linux-node1 ~]#

  5、导入完毕,查看



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

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



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

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-388363-1-1.html 上篇帖子: OpenStack 镜像服务Glance [三] 下篇帖子: OpenStack(企业私有云)万里长征第二步
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表