OpenStack实战四——镜像服务Glance部署

1. 镜像服务Glance介绍

OpenStack Image Service (Glance),是一个虚拟机镜像的存储、查询和检索系统。Glance 是 OpenStack Image Service 的项目名称,它会注册、列出并检索虚拟机(VM)镜像。它的配置设置较为简单,其运行进程与数据库有交互,与消息队列无连接,需配置数据库连接。

OpenStack实战四——镜像服务Glance部署

  • Glance-api:接受云系统镜像的创建、删除、读取请求,监听9292端口

  • Glance-Registry:云系统的镜像没注册服务,监听9191端口

OpenStack实战四——镜像服务Glance部署

使用file作为后端配置镜像服务,能够上传并存储在一个托管镜像服务的控制节点目录中。默认情况下,这个目录是 /var/lib/glance/images/

                                                                                                                                                                                                     

2. Glance部署

2.1 安装Glance

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

2.2 修改glance数据库配置

#glance-api,glance-registry两处都得加
[root@linux-node1 ~]# grep -w  "^connection" /etc/glance/glance-api.conf /etc/glance/glance-registry.conf 
/etc/glance/glance-api.conf:connection = mysql+pymysql://glance:glance@192.168.56.11/glance
/etc/glance/glance-registry.conf:connection = mysql+pymysql://glance:glance@192.168.56.11/glance

2.3 同步数据库

#有警告没关系,只要不是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)
/usr/lib/python2.7/site-packages/pymysql/cursors.py:166: Warning: (1831, u'Duplicate index `ix_image_properties_image_id_name`. This is deprecated and will be disallowed in a future release.')
  result = self._query(query)

2.4 检察glance数据库表结构

#表已创建,没问题
[root@linux-node1 ~]# mysql -h 192.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                        |
...

2.5 glance配置认证服务访问

#1.编辑 /etc/glance/glance-api.conf 文件
[root@linux-node1 ~]# vim /etc/glance/glance-api.conf
[keystone_authtoken]    #配置必须在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
...

[paste_deploy]
...
flavor = keystone

#2.编辑 /etc/glance/glance-api.conf 文件
[root@linux-node1 ~]# vim /etc/glance/glance-registry.conf
[keystone_authtoken]    #配置必须在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
...

[paste_deploy]
...
flavor = keystone

#3.编辑 /etc/glance/glance-api.conf 文件,在 [glance_store] 部分,配置本地文件系统存储和镜像文件位置

[glance_store]
...
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/  #上传镜像保存目录

                                                                                                                                                                                                   

3. 启动glance镜像服务并设置开机启动

3.1 设置开机启动

[root@linux-node1 ~]# systemctl enable openstack-glance-api.service   openstack-glance-registry.service

3.2 启动glance

[root@linux-node1 ~]# systemctl start openstack-glance-api.service   openstack-glance-registry.service

3.3 检察端口

[root@linux-node1 ~]# netstat -tunpl|egrep -w "9191|9292"
tcp        0      0 0.0.0.0:9292            0.0.0.0:*               LISTEN      10628/python2       
tcp        0      0 0.0.0.0:9191            0.0.0.0:*               LISTEN      10629/python2

                                                                                                                                                                                             

4. 在keystone上作注册

4.1 执行环境变量脚本获取权限

[root@linux-node1 ~]# source admin-openstack.sh

4.2 创建glance服务

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

4.3 创建镜像服务的 API 访问点:

[root@linux-node1 ~]# openstack endpoint create --region RegionOne image public http://192.168.56.11:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 26ddb169c9dc49a2b012056dba322268 |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | ddf4ed3cb33143b2b08c758350e557bc |
| service_name | glance                           |
| service_type | image                            |
| url          | http://192.168.56.11:9292        |
+--------------+----------------------------------+
[root@linux-node1 ~]# openstack endpoint create --region RegionOne image internal http://192.168.56.11:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | b8a15c907f31446a8d9e357cfeee50ea |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | ddf4ed3cb33143b2b08c758350e557bc |
| service_name | glance                           |
| service_type | image                            |
| url          | http://192.168.56.11:9292        |
+--------------+----------------------------------+
[root@linux-node1 ~]# openstack endpoint create --region RegionOne image admin http://192.168.56.11:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 823035d5657142178cd94d2a06974e49 |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | ddf4ed3cb33143b2b08c758350e557bc |
| service_name | glance                           |
| service_type | image                            |
| url          | http://192.168.56.11:9292        |
+--------------+----------------------------------+

4.4 执行以下两条命令,两处一样都为空则没有问题

[root@linux-node1 ~]# openstack image list

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

4.5 上传镜像

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

#2.上传镜像
[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-03-31T10:58:42Z                                 |
| disk_format      | qcow2                                                |
| file             | /v2/images/258e0bf5-af6c-466d-9ef1-5f60bfadb39b/file |
| id               | 258e0bf5-af6c-466d-9ef1-5f60bfadb39b                 |
| min_disk         | 0                                                    |
| min_ram          | 0                                                    |
| name             | cirros                                               |
| owner            | eac1d8e85417450bafe92987e5d56778                     |
| protected        | False                                                |
| schema           | /v2/schemas/image                                    |
| size             | 13287936                                             |
| status           | active                                               |
| tags             |                                                      |
| updated_at       | 2017-03-31T10:58:43Z                                 |
| virtual_size     | None                                                 |
| visibility       | public                                               |
+------------------+------------------------------------------------------+ 

#3.查看镜像
[root@linux-node1 ~]# openstack image list
+--------------------------------------+--------+--------+
| ID                                   | Name   | Status |
+--------------------------------------+--------+--------+
| 258e0bf5-af6c-466d-9ef1-5f60bfadb39b | cirros | active |
+--------------------------------------+--------+--------+  

[root@linux-node1 ~]# glance image-list
+--------------------------------------+--------+
| ID                                   | Name   |
+--------------------------------------+--------+
| 258e0bf5-af6c-466d-9ef1-5f60bfadb39b | cirros |
+--------------------------------------+--------+

#4.查看镜像存储目录
[root@linux-node1 ~]# ll /var/lib/glance/images/
total 12980
-rw-r----- 1 glance glance 13287936 Mar 31 18:58 258e0bf5-af6c-466d-9ef1-5f60bfadb39b

至此,说明glance已经配置部署成功,nice!


anzhihe 安志合个人博客,版权所有 丨 如未注明,均为原创 丨 转载请注明转自:https://chegva.com/2036.html | ☆★★每天进步一点点,加油!★★☆ | 

您可能还感兴趣的文章!

发表评论

电子邮件地址不会被公开。 必填项已用*标注