第四章Openstack镜像服务Glance

Glance组件介绍和安装配置

Glance镜像服务

 

Glance

 

1.安装Glance软件包

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

已加载插件:fastestmirror

base                                                     | 3.6 kB     00:00

 

 

2.编辑文件/etc/glance/glance-api.conf并完成如下动作:

  • 在[database]部分,配置数据库访问:
# Deprecated group/name - [sql]/connection

connection = mysql+pymysql://glance:glance@192.168.1.11/glance

 

# The SQLAlchemy connection string to use to connect to the slave

 

黄色部分的配置和registry配置是一样的,蓝色部分为镜像服务glance的数据库密码

 

  • 在[keystone_authtoken]和[paste_deploy]部分,配置认证服务访问:
 

[keystone_authtoken]

 

auth_uri = http://192.168.1.11:5000

auth_url = http://192.168.1.11:35357

memcached_servers = 192.168.1.11:11211

auth_type = password

project_domain_name = default

user_domain_name = default

project_name = service

username = glance

password = glance

将配置添加在[keystone_authtoken]下面

[paste_deploy]

flavor = keystone

 

 

  • 在[glance_store]部分,配置本地文件系统存储和镜像文件位置:
[glance_store]

 

stores = file,http

default_store = file

filesystem_store_datadir = /var/lib/glance/images/

 

3.编辑文件/etc/glance/glance-registry.conf并完成如下动作:

  • 在[database]部分,配置数据库访问:
# Deprecated group/name - [sql]/connection

connection = mysql+pymysql://glance:glance@192.168.1.11/glance

 

# The SQLAlchemy connection string to use to connect to the slave

 

 

黄色部分的配置和registry配置是一样的,蓝色部分为镜像服务glance的数据库密码

 

  • 在[keystone_authtoken]和[paste_deploy]部分,配置认证服务访问:

 

[keystone_authtoken]

 

auth_uri = http://192.168.1.11:5000

auth_url = http://192.168.1.11:35357

memcached_servers = 192.168.1.11:11211

auth_type = password

project_domain_name = default

user_domain_name = default

project_name = service

username = glance

password = glance

 

 

将配置黏贴在[keystone_authtoken]下面

[paste_deploy]

flavor = keystone

 

 

4.同步glance镜像服务数据库:

[root@linux-node1 ~]# su -s /bin/sh -c "glance-manage db_sync" glance

 

检查同步是否完成:

[root@linux-node1 ~]# mysql -h 192.168.1.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~]# grep '^[a-z]' | /etc/glance/glance-registry.conf
connection = mysql+pymysql://glance:glance@192.168.1.11/glance

stores = file,http

default_store = file

filesystem_store_datadir = /var/lib/glance/images

auth_uri = http://192.168.1.11:5000

auth_url = http://192.168.1.11:35357

memcached_servers = 192.168.1.11:11211

auth_type = password

project_domain_name = default

user_domain_name = default

project_name = service

username = glance

password = glance

flavor = keystone

 

 

完成安装

  • 启动镜像服务、配置他们开机自动启动:
[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 ~]# netstat -ntlp

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      3536/python2

tcp                         0               0                  0.0.0.0:25672           0.0.0.0:*               LISTEN      844/beam

tcp                         0               0                 0.0.0.0:3306            0.0.0.0:*               LISTEN      1183/mysqld

tcp                         0               0                 127.0.0.1:11211         0.0.0.0:*               LISTEN      836/memcached

tcp                         0               0                 0.0.0.0:9292            0.0.0.0:*               LISTEN      4237/python2

tcp                         0               0                 0.0.0.0:4369            0.0.0.0:*               LISTEN      1/systemd

tcp                         0               0                 0.0.0.0:22              0.0.0.0:*               LISTEN      839/sshd

tcp                         0               0                 0.0.0.0:15672           0.0.0.0:*               LISTEN      844/beam

tcp                         0               0                 127.0.0.1:25            0.0.0.0:*               LISTEN      1439/master

tcp6                       0               0                   :::5672                      :::*                    LISTEN      844/beam

tcp6                       0               0                   :::5000                      :::*                    LISTEN      838/httpd

tcp6                       0               0                  ::1:11211                   :::*                    LISTEN      836/memcached

tcp6                       0               0                  :::80                            :::*                    LISTEN      838/httpd

tcp6                       0               0                     :::22                         :::*                    LISTEN      839/sshd

tcp6                       0               0                     ::1:25                       :::*                    LISTEN      1439/master

tcp6                       0               0                    :::35357                     :::*                    LISTEN      838/httpd

 

[root@linux-node1 ~]# ps aux | grep glance

glance    3536  0.0  3.5 338868 67400 ?        Ss   6月22   0:00 /usr/bin/python2 /usr/bin/glance-registry

glance    3565  0.0  3.3 338868 62732 ?        S    6月22   0:00 /usr/bin/python2 /usr/bin/glance-registry

glance    4237  1.4  3.7 363232 70412 ?        Rs   00:11   0:01 /usr/bin/python2 /usr/bin/glance-api

glance    4248  0.0  3.4 363364 65088 ?        S    00:11   0:00 /usr/bin/python2 /usr/bin/glance-api

root      4267  0.0  0.0 112664   972 pts/0    R+   00:13   0:00 grep --color=auto glance

 

 

查看日志记录:

[root@linux-node1 ~]# cd /var/log/glance/

[root@linux-node1 glance]# ls

api.log  registry.log

[root@linux-node1 glance]# tail api.log

2017-06-22 22:57:04.238 3013 INFO migrate.versioning.api [-] 41 -> 42...

2017-06-22 22:57:04.368 3013 INFO migrate.versioning.api [-] done

2017-06-22 22:57:04.368 3013 INFO migrate.versioning.api [-] 42 -> 43...

2017-06-22 22:57:04.382 3013 INFO migrate.versioning.api [-] done

2017-06-22 22:57:04.382 3013 INFO migrate.versioning.api [-] 43 -> 44...

2017-06-22 22:57:04.389 3013 INFO migrate.versioning.api [-] done

 

 

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

+----------------------------------+----------+----------+

| ID                               | Name     | Type     |

+----------------------------------+----------+----------+

| 78e6f8140aa344e0abbc41ca7d21d9ed | keystone | identity |

+----------------------------------+----------+----------+

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

+----------------------------+-----------+--------------+--------------+---------+-----------+----------------------------+

| ID                         | Region    | Service Name | Service Type | Enabled | Interface | URL                        |

+----------------------------+-----------+--------------+--------------+---------+-----------+----------------------------+

| 353d9c2b13ec4f5d8e3d51abe7 | RegionOne | keystone     | identity     | True    | internal  | http://192.168.1.11:5000/v |

| ca6ee2                     |           |              |              |         |           | 3                          |

| 84952464ca3644da82907fae74 | RegionOne | keystone     | identity     | True    | public    | http://192.168.1.11:5000/v |

| 453c99                     |           |              |              |         |           | 3                          |

| f56fc2678a13414cbe94b6fea5 | RegionOne | keystone     | identity     | True    | admin     | http://192.168.1.11:35357/ |

| 06d13c                     |           |              |              |         |           | v3                         |

+----------------------------+-----------+--------------+--------------+---------+-----------+----------------------------+

 

 

  • 创建Glance服务实体
[root@linux-node1 ~]# openstack service create --name glance \

> --description "OpenStack Image" image

+-------------+----------------------------------+

| Field       | Value                            |

+-------------+----------------------------------+

| description | OpenStack Image                  |

| enabled     | True                             |

| id          | c29f2863d89047b997c721cdb51e77cb |

| name        | glance                           |

| type        | image                            |

+-------------+----------------------------------+

 

 

检查是否创建成功:

 

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

+----------------------------------+----------+----------+

| ID                               | Name     | Type     |

+----------------------------------+----------+----------+

| 78e6f8140aa344e0abbc41ca7d21d9ed | keystone | identity |

| c29f2863d89047b997c721cdb51e77cb | glance   | image    |

+----------------------------------+----------+----------+

 

 

  • 创建镜像服务的API端点:
[root@linux-node1 ~]# openstack endpoint create --region RegionOne \

> image public http://192.168.1.11:9292

+--------------+----------------------------------+

| Field        | Value                            |

+--------------+----------------------------------+

| enabled      | True                             |

| id           | 9529f8eba1ce4b27bff51a13b7371d51 |

| interface    | public                           |

| region       | RegionOne                        |

| region_id    | RegionOne                        |

| service_id   | c29f2863d89047b997c721cdb51e77cb |

| service_name | glance                           |

| service_type | image                            |

| url          | http://192.168.1.11:9292         |

+--------------+----------------------------------+

 

 

[root@linux-node1 ~]# openstack endpoint create --region RegionOne \

> image internal http://192.168.1.11:9292

+--------------+----------------------------------+

| Field        | Value                            |

+--------------+----------------------------------+

| enabled      | True                             |

| id           | f3b9aae336cb4f478b95ad7c77431580 |

| interface    | internal                         |

| region       | RegionOne                        |

| region_id    | RegionOne                        |

| service_id   | c29f2863d89047b997c721cdb51e77cb |

| service_name | glance                           |

| service_type | image                            |

| url          | http://192.168.1.11:9292         |

+--------------+----------------------------------+

 

 

[root@linux-node1 ~]# openstack endpoint create --region RegionOne \

> image admin http://192.168.1.11:9292

+--------------+----------------------------------+

| Field        | Value                            |

+--------------+----------------------------------+

| enabled      | True                             |

| id           | bcafb0d3927f4307bfcc96f9f8882211 |

| interface    | admin                            |

| region       | RegionOne                        |

| region_id    | RegionOne                        |

| service_id   | c29f2863d89047b997c721cdb51e77cb |

| service_name | glance                           |

| service_type | image                            |

| url          | http://192.168.1.11:9292         |

+--------------+----------------------------------+

 

 

以上三个API注册完成!

 

 

 

检查下Glance的三个API是否已经成功:(:9292)

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

+----------------------------+-----------+--------------+--------------+---------+-----------+----------------------------+

| ID                         | Region    | Service Name | Service Type | Enabled | Interface | URL                        |

+----------------------------+-----------+--------------+--------------+---------+-----------+----------------------------+

| 353d9c2b13ec4f5d8e3d51abe7 | RegionOne | keystone     | identity     | True    | internal  | http://192.168.1.11:5000/v |

| ca6ee2                     |           |              |              |         |           | 3                          |

| 84952464ca3644da82907fae74 | RegionOne | keystone     | identity     | True    | public    | http://192.168.1.11:5000/v |

| 453c99                     |           |              |              |         |           | 3                          |

| 9529f8eba1ce4b27bff51a13b7 | RegionOne | glance       | image        | True    | public    | http://192.168.1.11:9292   |

| 371d51                     |           |              |              |         |           |                            |

| bcafb0d3927f4307bfcc96f9f8 | RegionOne | glance       | image        | True    | admin     | http://192.168.1.11:9292   |

| 882211                     |           |              |              |         |           |                            |

| f3b9aae336cb4f478b95ad7c77 | RegionOne | glance       | image        | True    | internal  | http://192.168.1.11:9292   |

| 431580                     |           |              |              |         |           |                            |

| f56fc2678a13414cbe94b6fea5 | RegionOne | keystone     | identity     | True    | admin     | http://192.168.1.11:35357/ |

| 06d13c                     |           |              |              |         |           | v3                         |

+----------------------------+-----------+--------------+--------------+---------+-----------+----------------------------+

 

 

验证Glance服务:

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

+----+------+

| ID | Name |

+----+------+

+----+------+

 

 

验证操作

 

使用CirrOS对镜像服务进行验证,CirrOS是一个小型的Linux镜像可以用来帮助我们进行Openstack部署测试。

1.下载源镜像:

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

 

 

检查镜像是否已经下载:

[root@linux-node1 ~]# ls -lh

总用量 13M

-rw-r--r--  1 root root  267 6月  23 00:30 admin-openstack.sh

-rw-------. 1 root root 1.3K 6月  10 06:06 anaconda-ks.cfg

-rw-r--r--  1 root root  13M 5月   7 2015 cirros-0.3.4-x86_64-disk.img

 

 

2.使用QCOW2磁盘格式,bare容器格式上传镜像到镜像服务并设置公共可见,这样所有的项目都可以访问它:

[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-06-23T05:05:42Z                                 |

| disk_format      | qcow2                                                |

| file             | /v2/images/e44ea6d8-5a32-4bd3-8768-e606018db5ce/file |

| id               | e44ea6d8-5a32-4bd3-8768-e606018db5ce                 |

| min_disk         | 0                                                    |

| min_ram          | 0                                                    |

| name             | cirros                                               |

| owner            | 5a17da2eed3e4da9ae3e2f1c8d9fe6ac                     |

| protected        | False                                                |

| schema           | /v2/schemas/image                                    |

| size             | 13287936                                             |

| status           | active                                               |

| tags             |                                                      |

| updated_at       | 2017-06-23T05:05:42Z                                 |

| virtual_size     | None                                                 |

| visibility       | public                                               |

+------------------+------------------------------------------------------+

 

 

检查是否已经成功上传到Glance镜像位置:

[root@linux-node1 ~]# cd /var/lib/glance/images

[root@linux-node1 images]# ll

总用量 12980

-rw-r----- 1 glance glance 13287936 6月  23 01:05 e44ea6d8-5a32-4bd3-8768-e606018db5ce

 

 

[root@linux-node1 images]# file e44ea6d8-5a32-4bd3-8768-e606018db5ce

e44ea6d8-5a32-4bd3-8768-e606018db5ce: QEMU QCOW Image (v2), 41126400 bytes

[root@linux-node1 images]# ll -lh

总用量 13M

-rw-r----- 1 glance glance 13M 6月  23 01:05 e44ea6d8-5a32-4bd3-8768-e606018db5ce

 

 

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

+--------------------------------------+--------+--------+

| ID                                   | Name   | Status |

+--------------------------------------+--------+--------+

| e44ea6d8-5a32-4bd3-8768-e606018db5ce | cirros | active |

+--------------------------------------+--------+--------+

 

posted @ 2017-06-25 13:07  Mr.hu  阅读(224)  评论(0编辑  收藏  举报