OpenStack学习系列之三:安装部署glance

Glance(OpenStack Image Service)是一个提供发现、注册和下载镜像的服务。Glance 提供了虚拟机镜像的集中存储,通过 Glance 的 RESTful API,可以查询镜像元数据和下载镜像。虚拟机的镜像可以很方便的存储在各种地方,从简单的文件系统到对象存储系统(比如 OpenStack Swift)。
Glance支持多种后端存储,比如nfs和ceph作为Glance的后端存储用于存储镜像。建议使用ceph作为后端存储服务,这也是官方建议。
Glance 具体功能如下:
  • 提供 RESTful API 让用户能够查询和获取镜像的元数据和镜像本身;
  • 支持多种方式存储镜像,包括普通的文件系统、Swift、Ceph 等;
  • 对实例执行快照创建新的镜像。
  • 在 Newton 之前的版本中,Glance 支持两种 RESTful API V1和V2,两者区别为:
    • V1只提供了基本的镜像和用户操作功能:镜像创建、删除、下载、列表、详细信息查询、更新,以及镜像租户成员的创建、删除和列表。
    • V2除了支持V1的所有功能外,主要是增加了如下功能:
      • 镜像 location 的添加、删除和修改等操作;
      • metadata namespace 操作;
      • 镜像 tag 操作。
  • V1和V2对镜像后端存储的支持是相同的。
 

安装glance(控制节点,node1)

---------------------------------------------#初始化数据库,glance连接mysql用户密码glance/glance
mysql -uroot -pmysql << EOF
CREATE DATABASE glance;
GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' \
  IDENTIFIED BY 'glance';
GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' \
  IDENTIFIED BY 'glance';
EOF
---------------------------------------------#创建用户,node1执行
[root@node1 ~]# . admin-openrc
[root@node1 ~]# openstack user create --domain default --password-prompt glance # 输入glance密码glance 
User Password:
Repeat User Password:
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | 74b8f80f91084f0a8b17bb04a3fd47b1 |
| name                | glance                           |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+
[root@node1 ~]# openstack role add --project service --user glance admin
[root@node1 ~]# openstack service create --name glance --description "OpenStack Image" image
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Image                  |
| enabled     | True                             |
| id          | d421acdbcaaa4a5f92d87c20c4ebfec2 |
| name        | glance                           |
| type        | image                            |
+-------------+----------------------------------+
[root@node1 ~]# openstack endpoint create --region RegionOne image public http://node1:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 38aa9583a2274dc6b6cce8289e5a518c |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | d421acdbcaaa4a5f92d87c20c4ebfec2 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://node1:9292                |
+--------------+----------------------------------+
[root@node1 ~]# openstack endpoint create --region RegionOne image internal http://node1:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 85ec01a12a424c328a554e1c925b5ac4 |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | d421acdbcaaa4a5f92d87c20c4ebfec2 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://node1:9292                |
+--------------+----------------------------------+
[root@node1 ~]# openstack endpoint create --region RegionOne image admin http://node1:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | d1391c0234f74f3cbdb8df8f94ffca17 |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | d421acdbcaaa4a5f92d87c20c4ebfec2 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://node1:9292                |
+--------------+----------------------------------+

---------------------------------------------#安装配置组件
yum --enablerepo powertools -y install openstack-glance
crudini --set /etc/glance/glance-api.conf database connection mysql+pymysql://glance:glance@node1/glance
crudini --set /etc/glance/glance-api.conf keystone_authtoken www_authenticate_uri   http://node1:5000
crudini --set /etc/glance/glance-api.conf keystone_authtoken auth_url http://node1:5000
crudini --set /etc/glance/glance-api.conf keystone_authtoken memcached_servers  node1:11211
crudini --set /etc/glance/glance-api.conf keystone_authtoken auth_type password
crudini --set /etc/glance/glance-api.conf keystone_authtoken project_domain_name Default
crudini --set /etc/glance/glance-api.conf keystone_authtoken user_domain_name Default
crudini --set /etc/glance/glance-api.conf keystone_authtoken project_name service
crudini --set /etc/glance/glance-api.conf keystone_authtoken username glance
crudini --set /etc/glance/glance-api.conf keystone_authtoken password glance
crudini --set /etc/glance/glance-api.conf paste_deploy flavor keystone
crudini --set /etc/glance/glance-api.conf glance_store stores file,http
crudini --set /etc/glance/glance-api.conf glance_store default_store file
crudini --set /etc/glance/glance-api.conf glance_store filesystem_store_datadir /var/lib/glance/images/    # 镜像存储目录
---------------------------------------------#初始化数据
/bin/sh -c "glance-manage db_sync" glance
---------------------------------------------#启动服务
chown glance.glance -R /var/log/glance/   # 设置目录及目录下的文件的权限,防止权限错误导致服务无法启动
systemctl enable openstack-glance-api && systemctl start openstack-glance-api
---------------------------------------------#验证,下载并执行上传镜像,node1执行
. admin-openrc
wget http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img
[root@node1 ~]# glance image-create --name "cirros" --file cirros-0.4.0-x86_64-disk.img --disk-format qcow2 --container-format bare --visibility=public
+------------------+----------------------------------------------------------------------------------+
| Property         | Value                                                                            |
+------------------+----------------------------------------------------------------------------------+
| checksum         | 443b7623e27ecf03dc9e01ee93f67afe                                                 |
| container_format | bare                                                                             |
| created_at       | 2022-03-01T06:47:15Z                                                             |
| disk_format      | qcow2                                                                            |
| id               | 377a35ff-8674-4154-b7c9-707255c7474c                                             |
| min_disk         | 0                                                                                |
| min_ram          | 0                                                                                |
| name             | cirros                                                                           |
| os_hash_algo     | sha512                                                                           |
| os_hash_value    | 6513f21e44aa3da349f248188a44bc304a3653a04122d8fb4535423c8e1d14cd6a153f735bb0982e |
|                  | 2161b5b5186106570c17a9e58b64dd39390617cd5a350f78                                 |
| os_hidden        | False                                                                            |
| owner            | c827c773e36d4149a93196b371cebfd9                                                 |
| protected        | False                                                                            |
| size             | 12716032                                                                         |
| status           | active                                                                           |
| tags             | []                                                                               |
| updated_at       | 2022-03-01T06:47:16Z                                                             |
| virtual_size     | 46137344                                                                         |
| visibility       | public                                                                           |
+------------------+----------------------------------------------------------------------------------+
[root@node1 ~]# glance image-list
+--------------------------------------+--------+
| ID                                   | Name   |
+--------------------------------------+--------+
| 377a35ff-8674-4154-b7c9-707255c7474c | cirros |
+--------------------------------------+--------+
# 在上面设置的镜像存储目录/var/lib/glance中可以看到刚刚上传的镜像
[root@node1 ~]# ls -lh /var/lib/glance/images/ -lh
total 13M
-rw-r-----. 1 glance glance 13M Mar  1 14:47 377a35ff-8674-4154-b7c9-707255c7474c
[root@node1 ~]# md5sum cirros-0.4.0-x86_64-disk.img /var/lib/glance/images/377a35ff-8674-4154-b7c9-707255c7474c 
443b7623e27ecf03dc9e01ee93f67afe  cirros-0.4.0-x86_64-disk.img
443b7623e27ecf03dc9e01ee93f67afe  /var/lib/glance/images/377a35ff-8674-4154-b7c9-707255c7474c

 

posted @ 2022-03-02 15:21  喝杯茶  阅读(387)  评论(0编辑  收藏  举报