一、搭建高可用OpenStack(Queen版)集群之部署镜像管理服务(Glance)控制节点集群
一、glance简介
1、概述
镜像服务允许用户发现、注册和获取虚拟机镜像。它提供了一个API,允许查询虚拟机镜像的metadata 并获取一个现存的镜像。可以将虚拟机镜像存储到各种位置,从简单的文件系统到对象存储系统。
2、组件
- glance-api:接收镜像API的调用,诸如镜像发现、恢复、存储
- glance-registry:存储、处理和恢复镜像的元数据,元数据包括项诸如大小和类型
- 数据库:存放镜像源数据,诸如MySQL、SQLite
- 镜像文件的存储仓库:支持多种类型的仓库,它们有普通文件系统、对象存储、RADOS块存储、HTTP
- 元数据定义服务:通用API,是用于为厂商、管理员、服务、及用户自定义元数据
二、部署镜像管理服务(Glance)集群
1、创建glance数据库
在任意控制节点创建数据库,后台数据自动同步
mysql -u root -p
CREATE DATABASE glance; GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY '123456'; GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY '123456'; flush privileges; exit;
2、创建glance-api
在任意控制节点操作
调用keystone服务需要认证信息,加载环境变量脚本即可
source admin-openrc
1、创建service项目
创建1个project,glance/nova/neutron等服务加入到此project;
service项目在”default” domain中
[root@controller01 ~]# openstack project create --domain default --description "Service Project" service +-------------+----------------------------------+ | Field | Value | +-------------+----------------------------------+ | description | Service Project | | domain_id | default | | enabled | True | | id | 7752660121674958a585f72a19985515 | | is_domain | False | | name | service | | parent_id | default | | tags | [] | +-------------+----------------------------------+
2、创建glance用户
glance用户在”default” domain中
[root@controller01 ~]# openstack user create --domain default --password=glance_pass glance +---------------------+----------------------------------+ | Field | Value | +---------------------+----------------------------------+ | domain_id | default | | enabled | True | | id | a76531c04b164a419236327c68479935 | | name | glance | | options | {} | | password_expires_at | None | +---------------------+----------------------------------+
3、glance用户赋权
为glance用户赋予admin权限(这个没有返回值)
openstack role add --project service --user glance admin
4、创建glance服务实体
服务实体类型”image”
[root@controller01 ~]# openstack service create --name glance --description "OpenStack Image" image +-------------+----------------------------------+ | Field | Value | +-------------+----------------------------------+ | description | OpenStack Image | | enabled | True | | id | 684a84377989420aa3f47bd4e29198c1 | | name | glance | | type | image | +-------------+----------------------------------+
5、创建glance-api
注意--region与初始化admin用户时生成的region一致;
api地址统一采用vip,如果public/internal/admin分别使用不同的vip,请注意区分;
服务类型为image;
public api
[root@controller01 ~]# openstack endpoint create --region RegionTest image public http://controller:9292 +--------------+----------------------------------+ | Field | Value | +--------------+----------------------------------+ | enabled | True | | id | 66384f7d0b214308a7a423c60a1c66b4 | | interface | public | | region | RegionTest | | region_id | RegionTest | | service_id | 684a84377989420aa3f47bd4e29198c1 | | service_name | glance | | service_type | image | | url | http://controller:9292 | +--------------+----------------------------------+
internal api
[root@controller01 ~]# openstack endpoint create --region RegionTest image internal http://controller:9292 +--------------+----------------------------------+ | Field | Value | +--------------+----------------------------------+ | enabled | True | | id | 55c5b766d84042f78313fbd6b35770a9 | | interface | internal | | region | RegionTest | | region_id | RegionTest | | service_id | 684a84377989420aa3f47bd4e29198c1 | | service_name | glance | | service_type | image | | url | http://controller:9292 | +--------------+----------------------------------+
admin api
[root@controller01 ~]# openstack endpoint create --region RegionTest image admin http://controller:9292 +--------------+----------------------------------+ | Field | Value | +--------------+----------------------------------+ | enabled | True | | id | c46fd8676c76426790b50e05384b990e | | interface | admin | | region | RegionTest | | region_id | RegionTest | | service_id | 684a84377989420aa3f47bd4e29198c1 | | service_name | glance | | service_type | image | | url | http://controller:9292 | +--------------+----------------------------------+
3、安装glance
在全部控制节点安装glance
yum install openstack-glance python-glance python-glanceclient -y
4、配置glance-api.conf
在全部控制节点操作
注意:
- ”bind_host”参数,根据节点修改;
- glance-api.conf文件的权限:root:glance
cp -rp /etc/glance/glance-api.conf{,.bak} egrep -v "^$|^#" /etc/glance/glance-api.conf
[DEFAULT] enable_v1_api = false bind_host = 10.20.9.189 [cors] [database] connection = mysql+pymysql://glance:123456@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 = controller01:11211,controller02:11211,controller03:11211 auth_type = password project_domain_name = default user_domain_name = default project_name = service username = glance password = glance_pass [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]
创建镜像存储目录并赋权限:/var/lib/glance/images是默认的存储目录
mkdir -p /var/lib/glance/images chown glance:nobody /var/lib/glance/images
5、配置glance-registry.conf(optional)
官方文档指出:glance-registry服务与其api在Q版已经弃用,并且在S版时完全删除,本章节可忽略;
在全部控制节点操作
注意:
- ”bind_host”参数,根据节点修改;
- glance-registry.conf文件的权限:root:glance
cp -rp /etc/glance/glance-registry.conf{,.bak} egrep -v "^$|^#" /etc/glance/glance-registry.conf
[DEFAULT] bind_host = 10.20.9.189 [database] connection = mysql+pymysql://glance:123456@controller/glance [keystone_authtoken] auth_uri = http://controller:5000 auth_url = http://controller:35357 memcached_servers = controller01:11211,controller02:11211,controller03:11211 auth_type = password project_domain_name = default user_domain_name = default project_name = service username = glance password = glance_pass [matchmaker_redis] [oslo_messaging_amqp] [oslo_messaging_kafka] [oslo_messaging_notifications] [oslo_messaging_rabbit] [oslo_messaging_zmq] [oslo_policy] [paste_deploy] flavor = keystone [profiler]
6、同步glance数据库
任意控制节点操作
忽略输出的“deprecated”信息
su -s /bin/sh -c "glance-manage db_sync" glance
查看验证
mysql -h controller01 -uglance -p123456 -e "use glance;show tables;"
7、 启动服务
在全部控制节点操作
glance-registry在Q版已弃用;
systemctl enable openstack-glance-api.service systemctl restart openstack-glance-api.service systemctl status openstack-glance-api.service
Q之前的版本加上设置openstack-glance-registry
systemctl enable openstack-glance-registry.service systemctl restart openstack-glance-registry.service systemctl status openstack-glance-registry.service
查看端口
netstat -tunlp | grep python2
8、验证
在不启用ceph存储时,通常采用nfs共享存储做image的后端存储,如可将controller01节点的本地存储做共享,controller02/03节点远端挂载即可。
这里后续使用ceph存储,暂时使用本地验证。
1、下载镜像
wget http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img
2、上传镜像
- “上传”指将已下载的原始镜像经过一定的格式转换上传到image服务;
- 格式指定为qcow2,bare;设置public权限;
- 镜像生成后,在指定的存储目录下生成以镜像id命名的镜像文件
. admin-openrc
[root@controller01 ~]# openstack image create "cirros-qcow2" \ --file ~/cirros-0.3.5-x86_64-disk.img \ --disk-format qcow2 --container-format bare \ --public #结果如下 +------------------+------------------------------------------------------+ | Field | Value | +------------------+------------------------------------------------------+ | checksum | f8ab98ff5e73ebab884d80c9dc9c7290 | | container_format | bare | | created_at | 2018-09-08T15:54:45Z | | disk_format | qcow2 | | file | /v2/images/42e6c0e8-ce18-4651-8eb6-50fc0a6a6eac/file | | id | 42e6c0e8-ce18-4651-8eb6-50fc0a6a6eac | | min_disk | 0 | | min_ram | 0 | | name | cirros-qcow2 | | owner | 109783812ec540e982640e382f967065 | | protected | False | | schema | /v2/schemas/image | | size | 13267968 | | status | active | | tags | | | updated_at | 2018-09-08T15:54:46Z | | virtual_size | None | | visibility | public | +------------------+------------------------------------------------------+
3、查看镜像
[root@controller01 ~]# openstack image list +--------------------------------------+--------------+--------+ | ID | Name | Status | +--------------------------------------+--------------+--------+ | 42e6c0e8-ce18-4651-8eb6-50fc0a6a6eac | cirros-qcow2 | active | +--------------------------------------+--------------+--------+
9、设置pcs资源
在任意控制节点操作
1、添加资源openstack-glance-api与openstack-glance-registry
pcs resource create openstack-glance-api systemd:openstack-glance-api --clone interleave=true #下面的可以不操作 pcs resource create openstack-glance-registry systemd:openstack-glance-registry --clone interleave=true
2、查看pcs资源
# pcs resource vip (ocf::heartbeat:IPaddr2): Started controller01 Clone Set: lb-haproxy-clone [lb-haproxy] Started: [ controller01 ] Stopped: [ controller02 controller03 ] Clone Set: openstack-keystone-clone [openstack-keystone] Started: [ controller01 controller02 controller03 ] Clone Set: openstack-glance-api-clone [openstack-glance-api] Started: [ controller01 controller02 controller03 ] Clone Set: openstack-glance-registry-clone [openstack-glance-registry] Started: [ controller01 controller02 controller03 ]