openstack安装-glance

glance提供镜像服务使用户能够发现,注册和检索虚拟机镜像。它提供了一个 REST API,可让您查询虚拟机镜像元数据并检索实际镜像。您可以存储镜像在各种位置(从简单的文件系统到像OpenStack Object Storage这样的对象存储系统)。
为了简单起见,这里只是教你如何配置镜像服务,并把镜像保存到controller节点的文件目录里面,此目录为/var/lib/glance/images/。
这一章还是在controller节点操作。。。

准备

创建数据库

  • root用户权限执行mysql

    1
    $ mysql
  • 创建glance数据库

    1
    MariaDB [(none)]> CREATE DATABASE glance;
  • 赋予适合的权限给glance数据库

    1
    2
    3
    4
    MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' \
    IDENTIFIED BY 'GLANCE_DBPASS';
    MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' \
    IDENTIFIED BY 'GLANCE_DBPASS';

替换一下GLANCE_DBPASS为一个合适的密码,后面会用到

  • 退出mysql

    执行以下命令,进入admin身份

    1
    $ . admin-openrc

创建服务

  • 创建glance用户
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    $ openstack user create --domain default --password-prompt glance

    User Password:
    Repeat User Password:
    +---------------------+----------------------------------+
    | Field | Value |
    +---------------------+----------------------------------+
    | domain_id | default |
    | enabled | True |
    | id | 3f4e777c4062483ab8d9edd7dff829df |
    | name | glance |
    | options | {} |
    | password_expires_at | None |
    +---------------------+----------------------------------+

这里会提示输入密码,记住这个密码,下面会用到。

  • admin角色到glance用户和service项目

    1
    $ openstack role add --project service --user glance admin
  • 创建glance服务实体

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    $ openstack service create --name glance \
    --description "OpenStack Image" image

    +-------------+----------------------------------+
    | Field | Value |
    +-------------+----------------------------------+
    | description | OpenStack Image |
    | enabled | True |
    | id | 8c2c7f1b9b5049ea9e63757b5533e6d2 |
    | name | glance |
    | type | image |
    +-------------+----------------------------------+

创建镜像服务API endpoints

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
$ openstack endpoint create --region RegionOne \
image public http://controller:9292

+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | 340be3625e9b4239a6415d034e98aace |
| interface | public |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 8c2c7f1b9b5049ea9e63757b5533e6d2 |
| service_name | glance |
| service_type | image |
| url | http://controller:9292 |
+--------------+----------------------------------+

$ openstack endpoint create --region RegionOne \
image internal http://controller:9292

+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | a6e4b153c2ae4c919eccfdbb7dceb5d2 |
| interface | internal |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 8c2c7f1b9b5049ea9e63757b5533e6d2 |
| service_name | glance |
| service_type | image |
| url | http://controller:9292 |
+--------------+----------------------------------+

$ openstack endpoint create --region RegionOne \
image admin http://controller:9292

+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | 0c37ed58103f4300a84ff125a539032d |
| interface | admin |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 8c2c7f1b9b5049ea9e63757b5533e6d2 |
| service_name | glance |
| service_type | image |
| url | http://controller:9292 |
+--------------+----------------------------------+

安装和配置组件

安装包

1
$ apt install glance

修改/etc/glance/glance-api.conf

  • [database]区域,添加数据访问配置
    1
    2
    3
    [database]
    # ...
    connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance

替换GLANCE_DBPASS为前一节创建数据库的那个密码

  • [keystone_authtoken][paste_deploy]区域,配置keystone
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    [keystone_authtoken]
    # ...
    auth_uri = http://controller:5000
    auth_url = http://controller:35357
    memcached_servers = controller:11211
    auth_type = password
    project_domain_name = default
    user_domain_name = default
    project_name = service
    username = glance
    password = GLANCE_PASS

    [paste_deploy]
    # ...
    flavor = keystone

替换GLANCE_PASS为之前你创建glance用户时的密码。

  • [glance_store]区域,配置镜像存储路径。
    1
    2
    3
    4
    5
    [glance_store]
    # ...
    stores = file,http
    default_store = file
    filesystem_store_datadir = /var/lib/glance/images/

修改/etc/glance/glance-registry.conf

  • [database]区域,添加数据访问配置
    1
    2
    3
    [database]
    # ...
    connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance

替换GLANCE_DBPASS为前一节创建数据库的那个密码

  • [keystone_authtoken][paste_deploy]区域,配置keystone
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    [keystone_authtoken]
    # ...
    auth_uri = http://controller:5000
    auth_url = http://controller:35357
    memcached_servers = controller:11211
    auth_type = password
    project_domain_name = default
    user_domain_name = default
    project_name = service
    username = glance
    password = GLANCE_PASS

    [paste_deploy]
    # ...
    flavor = keystone

替换GLANCE_PASS为之前你创建glance用户时的密码。

初始化镜像服务数据库:

1
$ su -s /bin/sh -c "glance-manage db_sync" glance

重启服务

1
2
$ service glance-registry restart
$ service glance-api restart

验证

进入admin身份

1
$ . admin-openrc

下载测试镜像

1
$ wget http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img

上传测试镜像到镜像服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$ openstack image create "cirros" \
--file cirros-0.3.5-x86_64-disk.img \
--disk-format qcow2 --container-format bare \
--public

+------------------+------------------------------------------------------+
| Field | Value |
+------------------+------------------------------------------------------+
| checksum | 133eae9fb1c98f45894a4e60d8736619 |
| container_format | bare |
| created_at | 2015-03-26T16:52:10Z |
| disk_format | qcow2 |
| file | /v2/images/cc5c6982-4910-471e-b864-1098015901b5/file |
| id | cc5c6982-4910-471e-b864-1098015901b5 |
| min_disk | 0 |
| min_ram | 0 |
| name | cirros |
| owner | ae7a98326b9c455588edd2656d723b9d |
| protected | False |
| schema | /v2/schemas/image |
| size | 13200896 |
| status | active |
| tags | |
| updated_at | 2015-03-26T16:52:10Z |
| virtual_size | None |
| visibility | public |
+------------------+------------------------------------------------------+

确认是否上传成功

1
2
3
4
5
6
7
$ openstack image list

+--------------------------------------+--------+--------+
| ID | Name | Status |
+--------------------------------------+--------+--------+
| 38047887-61a7-41ea-9b49-27987d5e8bb9 | cirros | active |
+--------------------------------------+--------+--------+