openstack核心组件——glance— 镜像服务(6) 云计算openstack核心组件——glance— 镜像服务(6)

云计算openstack核心组件——glance— 镜像服务(6)

 
一、glance介绍:
      
      Glance是Openstack项目中负责镜像管理的模块,其功能包括虚拟机镜像的查找、注册和检索等。 Glance提供Restful API可以查询虚拟机镜像的metadata及获取镜像。 Glance可以将镜像保存到多种后端存储上,比如简单的文件存储或者对象存储。
 
理解 Image
 
要理解 Image Service,先得搞清楚什么是 Image 以及为什么要用 Image?
 
在传统 IT 环境下,安装一个系统要么从安装 CD 从头安装,要么用 Ghost 等克隆工具恢复。这两种方式有如下几个问题:
 
  1. 如果要安装的系统多了效率就很低
  2. 时间长,工作量大
  3. 安装完还要进行手工配置,比如安装其他的软件,设置 IP 等
  4. 备份和恢复系统不灵活
 
云环境下需要更高效的方案,这就是 Image。 Image 是一个模板,里面包含了基本的操作系统和其他的软件。
 
举例来说,有家公司需要为每位员工配置一套办公用的系统,一般需要一个 Win7 系统再加 MS office 软件。 OpenStack 是这么玩的:
 
  1. 先手工安装好这么一个虚机
  2. 然后对虚机执行 snapshot,这样就得到了一个 image
  3. 当有新员工入职需要办公环境时,立马启动一个或多个该 image 的 instance(虚机)就可以了
 
在这个过程中,第 1 步跟传统方式类似,需要手工操作和一定时间,但第 2、3 步非常快,全自动化,一般都是秒级别。而且 2、3 步可以循环做。 比如公司新上了一套 OA 系统,每个员工的 PC 上都得有客户端软件。 那么可以在某个现有虚机中先手工安装好 OA 客户端,然后执行 snapshot 操作,得到新的 image,以后可以就直接使用新 image 创建虚机了。另外,snapshot 还有备份的作用,能够非常方便的恢复系统。
 
理解Image Service
Image Service 的功能是管理 Image,让用户能够发现、获取和保存 Image。在 OpenStack 中,提供 Image Service 的是 Glance,其具体功能如下:
 
  1. 提供 REST API 让用户能够查询和获取 image 的元数据和 image 本身
  2. 支持多种方式存储 image,包括普通的文件系统、Swift、Amazon S3 等
  3. 对 Instance 执行 Snapshot 创建新的 image
     
Glance 架构
上面是 Glance 的架构图

glance-api

glance-api 是系统后台运行的服务进程。 对外提供 REST API,响应 image 查询、获取和存储的调用。
 
glance-api 不会真正处理请求。 如果操作是与 image metadata(元数据)相关,glance-api 会把请求转发给 glance-registry; 如果操作是与 image 自身存取相关,glance-api 会把请求转发给该 image 的 store backend。
 
在控制节点上可以查看 glance-api 进程
 

glance-registry

glance-registry 是系统后台运行的服务进程。 负责处理和存取 image 的 metadata,例如 image 的大小和类型。在控制节点上可以查看 glance-registry 进程
 
 
Glance 支持多种格式的 image,包括
 

Database

Image 的 metadata 会保持到 database 中,默认是 MySQL。 在控制节点上可以查看 glance 的 database 信息
 

Store backend

Glance 自己并不存储 image。 真正的 image 是存放在 backend 中的。 Glance 支持多种 backend,包括:
 
  1. A directory on a local file system(这是默认配置)
  2. GridFS
  3. Ceph RBD
  4. Amazon S3
  5. Sheepdog
  6. OpenStack Block Storage (Cinder)
  7. OpenStack Object Storage (Swift)
  8. VMware ESX
 
具体使用哪种 backend,是在 /etc/glance/glance-api.conf 中配置的
其他 backend 的配置可参考http://docs.openstack.org/liberty/config-reference/content/configuring-image-service-backends.html
 
查看目前已经存在的 image
 
 
查看保存目录
 
 
每个 image 在目录下都对应有一个文件,文件以 image 的 ID 命名。
 
二、glance创建镜像:
 
        OpenStack 为终端用户提供了 Web UI(Horizon)和命令行 CLI 两种交换界面。两种方式我们都要会用。可能有些同学觉得既然有更友好的 Web UI 了,干嘛还要用 CLI? 这里有下面的理由:
1、Web UI 的功能没有 CLI 全,有些操作只提供了 CLI。 即便是都有的功能,CLI 可以使用的参数更多
2、一般来说,CLI 返回结果更快,操作起来更高效
4、CLI 可放在脚本中进行批处理
5、有些耗时的操作 CLI 更合适,比如创建镜像(后面将涉及)
(1)Web UI 创建 image
(2)CLI 创建 image
将上传的镜像传到控制节点
执行image上传镜像命令:
openstack image create "cirros"   --file cirros-0.3.3-x86_64-disk.img.img   --disk-format qcow2 --container-format bare --public
三、glance配置文件:
vim /etc/glance/glance-api.conf
 
[DEFAULT]
 
[cors]
[cors.subdomain]
 
[database]
connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance
 
[glance_store]
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/
 
[image_format]
 
[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
 
[matchmaker_redis]
 
[oslo_concurrency]
 
[oslo_messaging_amqp]
 
[oslo_messaging_kafka]
 
[oslo_messaging_notifications]
 
[oslo_messaging_rabbit]
 
[oslo_messaging_zmq]
 
[oslo_middleware]
 
[oslo_policy]
 
[paste_deploy]
flavor = keystone
 
[profiler]
 
[store_type_location_strategy]
 
[task]
 
[taskflow_executor]

vim /etc/glance/glance-registry.conf

[DEFAULT]
 
[database]
connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance
 
[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
 
[matchmaker_redis]
 
[oslo_messaging_amqp]
 
[oslo_messaging_kafka]
 
[oslo_messaging_notifications]
 
[oslo_messaging_rabbit]
 
[oslo_messaging_zmq]
 
[oslo_policy]
 
[paste_deploy]
flavor = keystone
 
[profiler]

布建openstack的glance 

1. mysql -u root -p

2. CREATE DATABASE glance;

3.

GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' \ IDENTIFIED BY '123';

GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' \ IDENTIFIED BY '123';

3.source openrc

创建用户 设置角色 设置服务 创建三种服务端点

(internal内部 admin管理 public公共)

4. 退出数据库 创建 glance用户 domain项目

openstack user create --domain default --password=glance glance

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

| Field | Value |

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

| domain_id | default |

| enabled | True |

| id | bcaefe90e2ce41879fde9c81332a2229 |

| name | glance |

| options | {} |

| password_expires_at | None |

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

5把glance的用户 设置在service的项目中 设置admin的权限管理员

openstack role add --project service --user glance admin

6.创建服务

openstack service create --name glance \ --description "OpenStack Image" image

问题解决

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

> image internal http://node1:9292

Missing value auth-url required for auth plugin password

[root@node1 ~]# source openrc

7创建服务端点

openstack endpoint create --region RegionOne \

image public http://node1:9292

服务端点列表 显示两种方式

1 openstack endpoint list

2 openstack catalog list

删除不要的服务端点

openstack endpoint delete 加上ID 号

8 创建内部服务端点

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

 9 创建管理端点

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

openstack endpoint list 有3个glance

10 yum install openstack-glance -y

11 cd /etc/glance/

ls

LL

修改这两个配置文件 注意属主 属组

cp glance-api.conf glance-api.conf.beifen 备份一根文件进行修改

cp glance-rgistry.conf glance-registry.conf.beifen

12 之前的全部删除掉

vim glance-api.conf glance—store 进行后台存储

[DEFAULT]

[cors]

[cors.subdomain]

[database]

connection = mysql+pymysql://glance:GLANCE_DBPASS@node1/glance

[glance_store]

stores = file,http

default_store = file

filesystem_store_datadir = /var/lib/glance/images/

[image_format]

[keystone_authtoken]

auth_uri = http://node1:5000

auth_url = http://node1:35357

memcached_servers = node1:11211

auth_type = password

project_domain_name = default

user_domain_name = default

project_name = service

username = glance

password = glance

[matchmaker_redis]

[oslo_concurrency]

[oslo_messaging_amqp]

[oslo_messaging_kafka]

[oslo_messaging_notifications]

[oslo_messaging_rabbit]

[oslo_messaging_zmq]

[oslo_middleware]

[oslo_policy]

[paste_deploy] 认证模板

flavor = keystone

[profiler]

[store_type_location_strategy]

[task]

[taskflow_executor]

13 之前的全部删除掉

vim glance-rgistry.conf 元数据有关的工作交给rgistry

[DEFAULT]

[database]

connection = mysql+pymysql://glance:GLANCE_DBPASS@node1/glance

[keystone_authtoken]

auth_uri = http://node1:5000

auth_url = http://node1:35357

memcached_servers = node1:11211

auth_type = password

project_domain_name = default

user_domain_name = default

project_name = service

username = glance

password = glance

[matchmaker_redis]

[oslo_messaging_amqp]

[oslo_messaging_kafka]

[oslo_messaging_notifications]

[oslo_messaging_rabbit]

[oslo_messaging_zmq]

[oslo_policy]

[paste_deploy]

flavor = keystone

[profiler]

14 导入表内容同步数据库

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

15 glance-api glance-registry 开机自启

# systemctl enable openstack-glance-api.service \ openstack-glance-registry.service # systemctl start openstack-glance-api.service \ openstack-glance-registry.service

查看状态

# systemctl status openstack-glance-api.service \ openstack-glance-registry.service # systemctl status openstack-glance-api.service \ openstack-glance-registry.service

创建镜像

16 wget http://download2.yunwei.edu/shell/openstack_app.tar.gz

17 ls

[root@node1 ~]# ls

1234.txt 2 3 5 7 9 apache-tomcat-9.0.20.zip openstack_app.tar.gz pjh.txt

1.txt 2.txt 4 6 8 anaconda-ks.cfg openrc openstack-ocata yum-repo.sh

18 tar zxf openstack_app.tar.gz

19 ls

[root@node1 openstack-ocata]# ls

cirros-0.3.3-x86_64-disk.img openstack-compute-yilai

20 openstack image create "cirros" \ --file cirros-0.3.3-x86_64-disk.img \ --disk-format qcow2 --container-format bare \ --public

| Field | Value |

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

| checksum | 133eae9fb1c98f45894a4e60d8736619 |

| container_format | bare |

| created_at | 2019-08-03T01:22:51Z |

| disk_format | qcow2 |

| file | /v2/images/6a99c72d-e083-471d-a6f7-787cd05f8e56/file |

| id | 6a99c72d-e083-471d-a6f7-787cd05f8e56 |

| min_disk | 0 |

| min_ram | 0 |

| name | cirros |

| owner | 77539b5d86c6419d88e99140ed0f84a1 |

| protected | False |

| schema | /v2/schemas/image |

| size | 13200896 |

| status | active |

| tags | |

| updated_at | 2019-08-03T01:22:52Z |

| virtual_size | None |

| visibility | public |

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

21 openstack image list

glance image-list

一、glance介绍:
      
      Glance是Openstack项目中负责镜像管理的模块,其功能包括虚拟机镜像的查找、注册和检索等。 Glance提供Restful API可以查询虚拟机镜像的metadata及获取镜像。 Glance可以将镜像保存到多种后端存储上,比如简单的文件存储或者对象存储。
 
理解 Image
 
要理解 Image Service,先得搞清楚什么是 Image 以及为什么要用 Image?
 
在传统 IT 环境下,安装一个系统要么从安装 CD 从头安装,要么用 Ghost 等克隆工具恢复。这两种方式有如下几个问题:
 
  1. 如果要安装的系统多了效率就很低
  2. 时间长,工作量大
  3. 安装完还要进行手工配置,比如安装其他的软件,设置 IP 等
  4. 备份和恢复系统不灵活
 
云环境下需要更高效的方案,这就是 Image。 Image 是一个模板,里面包含了基本的操作系统和其他的软件。
 
举例来说,有家公司需要为每位员工配置一套办公用的系统,一般需要一个 Win7 系统再加 MS office 软件。 OpenStack 是这么玩的:
 
  1. 先手工安装好这么一个虚机
  2. 然后对虚机执行 snapshot,这样就得到了一个 image
  3. 当有新员工入职需要办公环境时,立马启动一个或多个该 image 的 instance(虚机)就可以了
 
在这个过程中,第 1 步跟传统方式类似,需要手工操作和一定时间,但第 2、3 步非常快,全自动化,一般都是秒级别。而且 2、3 步可以循环做。 比如公司新上了一套 OA 系统,每个员工的 PC 上都得有客户端软件。 那么可以在某个现有虚机中先手工安装好 OA 客户端,然后执行 snapshot 操作,得到新的 image,以后可以就直接使用新 image 创建虚机了。另外,snapshot 还有备份的作用,能够非常方便的恢复系统。
 
理解Image Service
Image Service 的功能是管理 Image,让用户能够发现、获取和保存 Image。在 OpenStack 中,提供 Image Service 的是 Glance,其具体功能如下:
 
  1. 提供 REST API 让用户能够查询和获取 image 的元数据和 image 本身
  2. 支持多种方式存储 image,包括普通的文件系统、Swift、Amazon S3 等
  3. 对 Instance 执行 Snapshot 创建新的 image
     
Glance 架构
上面是 Glance 的架构图

glance-api

glance-api 是系统后台运行的服务进程。 对外提供 REST API,响应 image 查询、获取和存储的调用。
 
glance-api 不会真正处理请求。 如果操作是与 image metadata(元数据)相关,glance-api 会把请求转发给 glance-registry; 如果操作是与 image 自身存取相关,glance-api 会把请求转发给该 image 的 store backend。
 
在控制节点上可以查看 glance-api 进程
 

glance-registry

glance-registry 是系统后台运行的服务进程。 负责处理和存取 image 的 metadata,例如 image 的大小和类型。在控制节点上可以查看 glance-registry 进程
 
 
Glance 支持多种格式的 image,包括
 

Database

Image 的 metadata 会保持到 database 中,默认是 MySQL。 在控制节点上可以查看 glance 的 database 信息
 

Store backend

Glance 自己并不存储 image。 真正的 image 是存放在 backend 中的。 Glance 支持多种 backend,包括:
 
  1. A directory on a local file system(这是默认配置)
  2. GridFS
  3. Ceph RBD
  4. Amazon S3
  5. Sheepdog
  6. OpenStack Block Storage (Cinder)
  7. OpenStack Object Storage (Swift)
  8. VMware ESX
 
具体使用哪种 backend,是在 /etc/glance/glance-api.conf 中配置的
其他 backend 的配置可参考http://docs.openstack.org/liberty/config-reference/content/configuring-image-service-backends.html
 
查看目前已经存在的 image
 
 
查看保存目录
 
 
每个 image 在目录下都对应有一个文件,文件以 image 的 ID 命名。
 
二、glance创建镜像:
 
        OpenStack 为终端用户提供了 Web UI(Horizon)和命令行 CLI 两种交换界面。两种方式我们都要会用。可能有些同学觉得既然有更友好的 Web UI 了,干嘛还要用 CLI? 这里有下面的理由:
1、Web UI 的功能没有 CLI 全,有些操作只提供了 CLI。 即便是都有的功能,CLI 可以使用的参数更多
2、一般来说,CLI 返回结果更快,操作起来更高效
4、CLI 可放在脚本中进行批处理
5、有些耗时的操作 CLI 更合适,比如创建镜像(后面将涉及)
(1)Web UI 创建 image
(2)CLI 创建 image
将上传的镜像传到控制节点
执行image上传镜像命令:
openstack image create "cirros"   --file cirros-0.3.3-x86_64-disk.img.img   --disk-format qcow2 --container-format bare --public
三、glance配置文件:
vim /etc/glance/glance-api.conf
 
[DEFAULT]
 
[cors]
[cors.subdomain]
 
[database]
connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance
 
[glance_store]
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/
 
[image_format]
 
[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
 
[matchmaker_redis]
 
[oslo_concurrency]
 
[oslo_messaging_amqp]
 
[oslo_messaging_kafka]
 
[oslo_messaging_notifications]
 
[oslo_messaging_rabbit]
 
[oslo_messaging_zmq]
 
[oslo_middleware]
 
[oslo_policy]
 
[paste_deploy]
flavor = keystone
 
[profiler]
 
[store_type_location_strategy]
 
[task]
 
[taskflow_executor]

vim /etc/glance/glance-registry.conf

[DEFAULT]
 
[database]
connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance
 
[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
 
[matchmaker_redis]
 
[oslo_messaging_amqp]
 
[oslo_messaging_kafka]
 
[oslo_messaging_notifications]
 
[oslo_messaging_rabbit]
 
[oslo_messaging_zmq]
 
[oslo_policy]
 
[paste_deploy]
flavor = keystone
 
[profiler]

布建openstack的glance 

1. mysql -u root -p

2. CREATE DATABASE glance;

3.

GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' \ IDENTIFIED BY '123';

GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' \ IDENTIFIED BY '123';

3.source openrc

创建用户 设置角色 设置服务 创建三种服务端点

(internal内部 admin管理 public公共)

4. 退出数据库 创建 glance用户 domain项目

openstack user create --domain default --password=glance glance

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

| Field | Value |

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

| domain_id | default |

| enabled | True |

| id | bcaefe90e2ce41879fde9c81332a2229 |

| name | glance |

| options | {} |

| password_expires_at | None |

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

5把glance的用户 设置在service的项目中 设置admin的权限管理员

openstack role add --project service --user glance admin

6.创建服务

openstack service create --name glance \ --description "OpenStack Image" image

问题解决

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

> image internal http://node1:9292

Missing value auth-url required for auth plugin password

[root@node1 ~]# source openrc

7创建服务端点

openstack endpoint create --region RegionOne \

image public http://node1:9292

服务端点列表 显示两种方式

1 openstack endpoint list

2 openstack catalog list

删除不要的服务端点

openstack endpoint delete 加上ID 号

8 创建内部服务端点

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

 9 创建管理端点

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

openstack endpoint list 有3个glance

10 yum install openstack-glance -y

11 cd /etc/glance/

ls

LL

修改这两个配置文件 注意属主 属组

cp glance-api.conf glance-api.conf.beifen 备份一根文件进行修改

cp glance-rgistry.conf glance-registry.conf.beifen

12 之前的全部删除掉

vim glance-api.conf glance—store 进行后台存储

[DEFAULT]

[cors]

[cors.subdomain]

[database]

connection = mysql+pymysql://glance:GLANCE_DBPASS@node1/glance

[glance_store]

stores = file,http

default_store = file

filesystem_store_datadir = /var/lib/glance/images/

[image_format]

[keystone_authtoken]

auth_uri = http://node1:5000

auth_url = http://node1:35357

memcached_servers = node1:11211

auth_type = password

project_domain_name = default

user_domain_name = default

project_name = service

username = glance

password = glance

[matchmaker_redis]

[oslo_concurrency]

[oslo_messaging_amqp]

[oslo_messaging_kafka]

[oslo_messaging_notifications]

[oslo_messaging_rabbit]

[oslo_messaging_zmq]

[oslo_middleware]

[oslo_policy]

[paste_deploy] 认证模板

flavor = keystone

[profiler]

[store_type_location_strategy]

[task]

[taskflow_executor]

13 之前的全部删除掉

vim glance-rgistry.conf 元数据有关的工作交给rgistry

[DEFAULT]

[database]

connection = mysql+pymysql://glance:GLANCE_DBPASS@node1/glance

[keystone_authtoken]

auth_uri = http://node1:5000

auth_url = http://node1:35357

memcached_servers = node1:11211

auth_type = password

project_domain_name = default

user_domain_name = default

project_name = service

username = glance

password = glance

[matchmaker_redis]

[oslo_messaging_amqp]

[oslo_messaging_kafka]

[oslo_messaging_notifications]

[oslo_messaging_rabbit]

[oslo_messaging_zmq]

[oslo_policy]

[paste_deploy]

flavor = keystone

[profiler]

14 导入表内容同步数据库

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

15 glance-api glance-registry 开机自启

# systemctl enable openstack-glance-api.service \ openstack-glance-registry.service # systemctl start openstack-glance-api.service \ openstack-glance-registry.service

查看状态

# systemctl status openstack-glance-api.service \ openstack-glance-registry.service # systemctl status openstack-glance-api.service \ openstack-glance-registry.service

创建镜像

16 wget http://download2.yunwei.edu/shell/openstack_app.tar.gz

17 ls

[root@node1 ~]# ls

1234.txt 2 3 5 7 9 apache-tomcat-9.0.20.zip openstack_app.tar.gz pjh.txt

1.txt 2.txt 4 6 8 anaconda-ks.cfg openrc openstack-ocata yum-repo.sh

18 tar zxf openstack_app.tar.gz

19 ls

[root@node1 openstack-ocata]# ls

cirros-0.3.3-x86_64-disk.img openstack-compute-yilai

20 openstack image create "cirros" \ --file cirros-0.3.3-x86_64-disk.img \ --disk-format qcow2 --container-format bare \ --public

| Field | Value |

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

| checksum | 133eae9fb1c98f45894a4e60d8736619 |

| container_format | bare |

| created_at | 2019-08-03T01:22:51Z |

| disk_format | qcow2 |

| file | /v2/images/6a99c72d-e083-471d-a6f7-787cd05f8e56/file |

| id | 6a99c72d-e083-471d-a6f7-787cd05f8e56 |

| min_disk | 0 |

| min_ram | 0 |

| name | cirros |

| owner | 77539b5d86c6419d88e99140ed0f84a1 |

| protected | False |

| schema | /v2/schemas/image |

| size | 13200896 |

| status | active |

| tags | |

| updated_at | 2019-08-03T01:22:52Z |

| virtual_size | None |

| visibility | public |

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

21 openstack image list

glance image-list

猜你喜欢

转载自www.cnblogs.com/it-peng/p/11363332.html