私有云 Openstack Ocata版安装(二)glance组件的安装和配置

  • A+
所属分类:OpenStack  虚拟化/私有云
摘要

部署Openstack的服务器官方推荐两台以上,主要是创建的实例(Instances)实际上占用的是计算节点的资源,因此你的计算节点所拥有的VCPU、Memory,将决定你所创建的实例的最大Vcpu数和内存,或许是基于此种原因考虑,官方建议控制节点和计算节点分离,我此次部署是基于Vmware虚拟机,主要是用于测试环境,因此规划为单控制节点和两个计算节点,本系列会涉及到的部署组件为keystone,glance,nova,neutron,cinder,dashboard。我这次是在三台CentOS 7的服务器进行部署。

私有云 Openstack Ocata版安装(一)Controller部署:https://www.dwhd.org/20180213_234933.html

一:集群信息简介

Openstack Controller 192.168.200.101
172.18.100.1
172.28.100.1
192.168.200/24   192.168.200.2
172.18.0.0/16      172.18.0.1
172.28.0.0/16      172.28.0.1
4c8g100G
Openstack Computer 192.168.200.102
172.18.100.2
172.28.100.2
192.168.200/24   192.168.200.2
172.18.0.0/16      172.18.0.1
172.28.0.0/16      172.28.0.1
4c8g100G
Openstack Network 192.168.200.103
172.18.100.3
172.28.100.3
192.168.200/24   192.168.200.2
172.18.0.0/16      172.18.0.1
172.28.0.0/16      172.28.0.1
4c4g40G

二:安装和配置glance组件

本章介绍在 Controller node(管理节点)安装和配置镜像服务,代号(glance)。出于简单的目的,本次使用本地文件系统存储镜像。

2.1、先决条件

1. 创建数据库,完成下列步骤:

A. 使用数据库命令行客户端,以 root 身份登录数据库服务器。

B. 创建 glance 数据库

C. 授予数据库用户 glance 访问 glance 数据库的权限。

D. 退出数据库

[root@LB-VM-Node-192_168_200_101 ~]# mysql -uroot -pYmY0N2RiOTk4NTc1ZDM1ZWUz
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 40
Server version: 10.0.33-MariaDB-wsrep MariaDB Server, wsrep_25.21.rc3fc46e

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> CREATE DATABASE IF NOT EXISTS glance DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'ZWNhZjE0MDExMWJj';
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'controller' IDENTIFIED BY 'ZWNhZjE0MDExMWJj';
Query OK, 0 rows affected, 1 warning (0.00 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'ZWNhZjE0MDExMWJj';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> \q
Bye
[root@LB-VM-Node-192_168_200_101 ~]# 

私有云 Openstack Ocata版安装(二)glance组件的安装和配置

2. 执行 admin 凭据脚本,以便以 admin 身份执行后续命令:

[root@LB-VM-Node-192_168_200_101 ~]# . admin-openrc

3. 创建服务凭据,完成下列操作:

A. 创建 glance 用户

[root@LB-VM-Node-192_168_200_101 ~]# openstack user create --domain default --password-prompt glance
User Password:
Repeat User Password:
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | c67c0d468d33486ea0a0bb4ece8d2866 |
| name                | glance                           |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+
[root@LB-VM-Node-192_168_200_101 ~]# 

私有云 Openstack Ocata版安装(二)glance组件的安装和配置

B. 添加 admin 角色到 glance 用户和 service 项目

[root@LB-VM-Node-192_168_200_101 ~]# openstack role add --project service --user glance admin

C. 创建 glance 服务实体:

[root@LB-VM-Node-192_168_200_101 ~]# openstack service create --name glance --description "OpenStack Image" image
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Image                  |
| enabled     | True                             |
| id          | 83f39ed0bd274894ae6daf869ab5a767 |
| name        | glance                           |
| type        | image                            |
+-------------+----------------------------------+
[root@LB-VM-Node-192_168_200_101 ~]#

私有云 Openstack Ocata版安装(二)glance组件的安装和配置

4. 创建镜像服务 API 端点:

[root@LB-VM-Node-192_168_200_101 ~]# openstack endpoint create --region RegionOne image public http://controller:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 7744b6bc0a9a4bd78baf37fc34b530ed |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 83f39ed0bd274894ae6daf869ab5a767 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+
[root@LB-VM-Node-192_168_200_101 ~]# openstack endpoint create --region RegionOne image internal http://controller:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | a1cf053f2f704c05b85a9caa67ca0591 |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 83f39ed0bd274894ae6daf869ab5a767 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+
[root@LB-VM-Node-192_168_200_101 ~]# openstack endpoint create --region RegionOne image admin http://controller:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | b1ad498618c0456aa45b6189b97f9a1d |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 83f39ed0bd274894ae6daf869ab5a767 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+
[root@LB-VM-Node-192_168_200_101 ~]#

私有云 Openstack Ocata版安装(二)glance组件的安装和配置

2.2安装和配置组件

1. 安装软件包

[root@LB-VM-Node-192_168_200_101 ~]# yum install -y openstack-glance

私有云 Openstack Ocata版安装(二)glance组件的安装和配置

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

A. 在[database]小节,配置数据库访问:

[database]
# ...
connection = mysql+pymysql://glance:ZWNhZjE0MDExMWJj@controller/glance

私有云 Openstack Ocata版安装(二)glance组件的安装和配置

B. 在[keystone_authtoken]和[paste_deploy]小节配置身份服务访问信息:

[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 = lookback

 

[paste_deploy]

# ...

flavor = keystone

替换 GLANCE_DBPASS 为认证服务中 glance 用户的密码。
私有云 Openstack Ocata版安装(二)glance组件的安装和配置

私有云 Openstack Ocata版安装(二)glance组件的安装和配置

C. 在[glance_store]小节,配置使用本地系统存储和镜像文件存储路径:

[glance_store]

# ...

stores = file,http

default_store = file

filesystem_store_datadir = /var/lib/glance/images/

私有云 Openstack Ocata版安装(二)glance组件的安装和配置

[root@LB-VM-Node-192_168_200_101 ~]# sed -r '/^(#|$)/d' /etc/glance/glance-api.conf
[DEFAULT]
[cors]
[database]
connection = mysql+pymysql://glance:ZWNhZjE0MDExMWJj@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 = lookback
[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]
[root@LB-VM-Node-192_168_200_101 ~]#

私有云 Openstack Ocata版安装(二)glance组件的安装和配置

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

A. 在[database]小节,配置数据库访问:

[database]

# ...

connection = mysql+pymysql://glance:ZWNhZjE0MDExMWJj@controller/glance

私有云 Openstack Ocata版安装(二)glance组件的安装和配置

B. 在[keystone_authtoken]和[paste_deploy]小节,配置身份服务访问信息:

[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 = lookback

 

[paste_deploy]

# ...

flavor = keystone

私有云 Openstack Ocata版安装(二)glance组件的安装和配置

私有云 Openstack Ocata版安装(二)glance组件的安装和配置

[root@LB-VM-Node-192_168_200_101 ~]# sed -r '/^(#|$)/d' /etc/glance/glance-registry.conf
[DEFAULT]
[database]
connection = mysql+pymysql://glance:ZWNhZjE0MDExMWJj@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 = lookback
[matchmaker_redis]
[oslo_messaging_amqp]
[oslo_messaging_kafka]
[oslo_messaging_notifications]
[oslo_messaging_rabbit]
[oslo_messaging_zmq]
[oslo_policy]
[paste_deploy]
flavor = keystone
[profiler]
[root@LB-VM-Node-192_168_200_101 ~]#

私有云 Openstack Ocata版安装(二)glance组件的安装和配置

4. 初始化镜像服务数据库

[root@LB-VM-Node-192_168_200_101 ~]# su -s /bin/sh -c "glance-manage db_sync" glance
/usr/lib/python2.7/site-packages/oslo_db/sqlalchemy/enginefacade.py:1328: OsloDBDeprecationWarning: EngineFacade is deprecated; please use oslo_db.sqlalchemy.enginefacade
  expire_on_commit=expire_on_commit, _conf=conf)
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade  -> liberty, liberty initial
INFO  [alembic.runtime.migration] Running upgrade liberty -> mitaka01, add index on created_at and updated_at columns of 'images' table
INFO  [alembic.runtime.migration] Running upgrade mitaka01 -> mitaka02, update metadef os_nova_server
INFO  [alembic.runtime.migration] Running upgrade mitaka02 -> ocata01, add visibility to and remove is_public from images
INFO  [alembic.runtime.migration] Running upgrade ocata01 -> pike01, drop glare artifacts tables
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
Upgraded database to: pike01, current revision(s): pike01
[root@LB-VM-Node-192_168_200_101 ~]#

私有云 Openstack Ocata版安装(二)glance组件的安装和配置

验证是否初始化成功:

[root@LB-VM-Node-192_168_200_101 ~]# mysql -uroot -pYmY0N2RiOTk4NTc1ZDM1ZWUz glance
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 48
Server version: 10.0.33-MariaDB-wsrep MariaDB Server, wsrep_25.21.rc3fc46e

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [glance]> show tables;
+----------------------------------+
| Tables_in_glance                 |
+----------------------------------+
| alembic_version                  |
| 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                            |
+----------------------------------+
15 rows in set (0.00 sec)

MariaDB [glance]> \q
Bye
[root@LB-VM-Node-192_168_200_101 ~]# 

私有云 Openstack Ocata版安装(二)glance组件的安装和配置

3.3完成安装

启动镜像服务并设置开机自动启动:

[root@LB-VM-Node-192_168_200_101 ~]# 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@LB-VM-Node-192_168_200_101 ~]# systemctl start openstack-glance-api.service openstack-glance-registry.service
[root@LB-VM-Node-192_168_200_101 ~]#

3.4确认安装

使用 CirrOS 镜像确认镜像服务是否安装正常。CirrOS 是一个小型Linux 镜像,可以用来测试你的 OpenStack 环境。

1. 执行 admin 凭据脚本,以便以 admin 身份执行后续命令:

[root@LB-VM-Node-192_168_200_101 ~]# . admin-openrc

2. 下载镜像文件

[root@LB-VM-Node-192_168_200_101 ~]# wget http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img
--2018-02-14 04:14:00--  http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img
正在解析主机 download.cirros-cloud.net (download.cirros-cloud.net)... 64.90.42.85, 2607:f298:6:a036::bd6:a72a
正在连接 download.cirros-cloud.net (download.cirros-cloud.net)|64.90.42.85|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:13267968 (13M) 
正在保存至: “cirros-0.3.5-x86_64-disk.img”

100%[========================================================================================================================================================================>] 13,267,968  1.47MB/s 用时 12s

2018-02-14 04:14:13 (1.03 MB/s) - 已保存 “cirros-0.3.5-x86_64-disk.img” [13267968/13267968])

[root@LB-VM-Node-192_168_200_101 ~]# 

私有云 Openstack Ocata版安装(二)glance组件的安装和配置

3. 上传镜像文件到镜像服务,使用 QCOW2 磁盘格式,bare 容器格式,添加公共可见选项,是所有项目可以访问该镜像:

[root@LB-VM-Node-192_168_200_101 ~]# openstack image create "cirros" --file cirros-0.3.5-x86_64-disk.img --disk-format qcow2 --container-format bare --public
HTTPInternalServerError (HTTP 500)
[root@LB-VM-Node-192_168_200_101 ~]# 

开始我这边在上传镜像的时候,一直遇到500错误,排查了glance和keystone的所有配置细节,并没有发现错误,于是仔细的查看glance-api的日志后发现一个疑点的地方

2018-02-14 14:53:04.116 31192 INFO eventlet.wsgi.server [-] 192.168.200.101 - - [14/Feb/2018 14:53:04] "GET /v2/schemas/image HTTP/1.1" 500 139 0.043173
2018-02-14 14:54:25.574 31191 WARNING keystoneauth.identity.generic.base [-] Failed to discover available identity versions when contacting http://controller:35357. Attempting to parse version from URL.: ConnectFailure: Unable to establish connection to http://controller:35357: HTTPConnectionPool(host='controller', port=35357): Max retriesexceeded with url: / (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x40cdfd0>: Failed to establish a new connection: [Errno -2] No address found',))
2018-02-14 14:54:25.574 31191 INFO eventlet.wsgi.server [-] Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/eventlet/wsgi.py", line 490, in handle_one_response
    result = self.application(self.environ, start_response)
  File "/usr/lib/python2.7/site-packages/webob/dec.py", line 131, in __call__
    resp = self.call_func(req, *args, **self.kwargs)

私有云 Openstack Ocata版安装(二)glance组件的安装和配置

开始我认为是hostname的问题,因为我的hostname和hosts文件里写的是不一样的,于是我把hostname修改为controller,发现错误依旧,这时候我又发现 我的hosts文件里面的Controller是首字母C是大写的,当我把这个加了一个小写的controller的时候奇迹就出现了。

[root@LB-VM-Node-192_168_200_101 ~]# openstack image create "cirros"   --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-02-14T10:32:44Z                                 |
| disk_format      | qcow2                                                |
| file             | /v2/images/62659fab-2181-46bd-8e71-b096077a0398/file |
| id               | 62659fab-2181-46bd-8e71-b096077a0398                 |
| min_disk         | 0                                                    |
| min_ram          | 0                                                    |
| name             | cirros                                               |
| owner            | 7eb5c96f93bf422bb175de7ea22e290b                     |
| protected        | False                                                |
| schema           | /v2/schemas/image                                    |
| size             | 13267968                                             |
| status           | active                                               |
| tags             |                                                      |
| updated_at       | 2018-02-14T10:32:44Z                                 |
| virtual_size     | None                                                 |
| visibility       | public                                               |
+------------------+------------------------------------------------------+
[root@LB-VM-Node-192_168_200_101 ~]#

私有云 Openstack Ocata版安装(二)glance组件的安装和配置
查看日志也是正常的了
私有云 Openstack Ocata版安装(二)glance组件的安装和配置

4. 确认镜像已经上传并验证属性:

[root@LB-VM-Node-192_168_200_101 ~]# openstack image list
+--------------------------------------+--------+--------+
| ID                                   | Name   | Status |
+--------------------------------------+--------+--------+
| 62659fab-2181-46bd-8e71-b096077a0398 | cirros | active |
+--------------------------------------+--------+--------+
[root@LB-VM-Node-192_168_200_101 ~]# 

私有云 Openstack Ocata版安装(二)glance组件的安装和配置

到此我们就安装配置好了keystone和glance了

[root@LB-VM-Node-192_168_200_101 ~]# openstack service list --long
+----------------------------------+----------+----------+-----------------+---------+
| ID                               | Name     | Type     | Description     | Enabled |
+----------------------------------+----------+----------+-----------------+---------+
| 83f39ed0bd274894ae6daf869ab5a767 | glance   | image    | OpenStack Image | True    |
| 979284b23b2641c2a8f457a9f9099952 | keystone | identity |                 | True    |
+----------------------------------+----------+----------+-----------------+---------+
[root@LB-VM-Node-192_168_200_101 ~]#

私有云 Openstack Ocata版安装(二)glance组件的安装和配置

lookback

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: