3. 安装 glance(控制节点)— OpenStack Queens 三节点部署

Glance服务只需安装在控制节点上

在keystone中为Glance添加用户等

添加用户

root@controller ~(keystone)# openstack user create --domain default --project service --password root glance
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| default_project_id  | 2fae0cd7579441f88cab61f4291bfd17 |
| domain_id           | default                          |
| enabled             | True                             |
| id                  | 56f3de0fac494f2983a356a679844512 |
| name                | glance                           |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+

为Glance用户添加管理员角色

root@controller ~(keystone)# openstack role add --project service --user glance admin

创建Glance service

root@controller ~(keystone)# openstack service create --name glance --description "OpenStack Image service" image
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Image service          |
| enabled     | True                             |
| id          | 25843c2b6d54411e8ca477d696b67cb7 |
| name        | glance                           |
| type        | image                            |
+-------------+----------------------------------+

添加glance的endpoint(public)

root@controller ~(keystone)# openstack endpoint create --region RegionOne image public http://10.0.0.7:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 85261c82ff964c29b03bf80b62c9b2a5 |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 25843c2b6d54411e8ca477d696b67cb7 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://10.0.0.7:9292             |
+--------------+----------------------------------+

添加glance的endpoint(internal)

root@controller ~(keystone)# openstack endpoint create --region RegionOne image internal http://10.0.0.7:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | eb7adda169a6488b8268efc8836b407a |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 25843c2b6d54411e8ca477d696b67cb7 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://10.0.0.7:9292             |
+--------------+----------------------------------+

添加glance的endpoint(admin)

root@controller ~(keystone)# openstack endpoint create --region RegionOne image admin http://10.0.0.7:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 00c227c00a8349b28dca2d4b400f27c4 |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 25843c2b6d54411e8ca477d696b67cb7 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://10.0.0.7:9292             |
+--------------+----------------------------------+

为glance创建数据库和用户

root@controller ~(keystone)# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 63
Server version: 10.0.38-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04

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

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

MariaDB [(none)]> create database glance;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all privileges on glance.* to glance@'localhost' identified by 'root';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> grant all privileges on glance.* to glance@'%' identified by 'root';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit
Bye

安装配置Glance

安装glance

root@controller ~(keystone)# apt -y install glance

配置glance,由于官方配置文件修改较为麻烦,这里直接创建一个新的配置文件

root@controller ~(keystone)# mv /etc/glance/glance-api.conf /etc/glance/glance-api.conf.org
root@controller ~(keystone)# vi /etc/glance/glance-api.conf

# 添加以下内容,保存退出
[DEFAULT]
bind_host = 0.0.0.0

[glance_store]
default_store = file
filesystem_store_datadir = /var/lib/glance/images/

[database]
connection = mysql+pymysql://glance:root@controller/glance

[keystone_authtoken]
auth_uri = http://controller:5000
auth_url = http://controller:5000
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = glance
password = root

[paste_deploy]
flavor = keystone
root@controller ~(keystone)# mv /etc/glance/glance-registry.conf /etc/glance/glance-registry.conf.org
root@controller ~(keystone)# vi /etc/glance/glance-registry.conf

# 添加以下内容,保存退出
[DEFAULT]
bind_host = 0.0.0.0

[database]
# MariaDB connection info
connection = mysql+pymysql://glance:root@controller/glance

# Keystone auth info
[keystone_authtoken]
auth_uri = http://controller:5000
auth_url = http://controller:5000
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = glance
password = root

[paste_deploy]
flavor = keystone

由于配置文件是新建的,需要将权限加回去

root@controller ~(keystone)# chmod 644 /etc/glance/glance-api.conf /etc/glance/glance-registry.conf
root@controller ~(keystone)# chown glance. /etc/glance/glance-api.conf /etc/glance/glance-registry.conf

同步数据库

root@controller ~(keystone)# su -s /bin/bash glance -c "glance-manage db_sync"
...
...
Database is synced successfully.

重启服务

root@controller ~(keystone)# systemctl restart glance-api glance-registry

在glance中添加镜像

下载官方用于测试的一个小系统Cirros

root@controller ~(keystone)# wget http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img

添加该镜像到镜像服务

root@controller ~(keystone)# openstack image create "cirros" \
--file cirros-0.4.0-x86_64-disk.img \
--disk-format qcow2 --container-format bare \
--public
+------------------+------------------------------------------------------+
| Field            | Value                                                |
+------------------+------------------------------------------------------+
| checksum         | 443b7623e27ecf03dc9e01ee93f67afe                     |
| container_format | bare                                                 |
| created_at       | 2020-04-26T06:22:43Z                                 |
| disk_format      | qcow2                                                |
| file             | /v2/images/9e0275a2-2363-461e-83e0-fe5ffa066002/file |
| id               | 9e0275a2-2363-461e-83e0-fe5ffa066002                 |
| min_disk         | 0                                                    |
| min_ram          | 0                                                    |
| name             | cirros                                               |
| owner            | 460e4247a8984b2cbf1b35c3da7e6708                     |
| protected        | False                                                |
| schema           | /v2/schemas/image                                    |
| size             | 12716032                                             |
| status           | active                                               |
| tags             |                                                      |
| updated_at       | 2020-04-26T06:22:44Z                                 |
| virtual_size     | None                                                 |
| visibility       | public                                               |
+------------------+------------------------------------------------------+

查看镜像列表

root@controller ~(keystone)# openstack image list
+--------------------------------------+--------+--------+
| ID                                   | Name   | Status |
+--------------------------------------+--------+--------+
| 9e0275a2-2363-461e-83e0-fe5ffa066002 | cirros | active |
+--------------------------------------+--------+--------+

参考

posted @ 2020-04-26 14:24  zhaoyixin96  阅读(444)  评论(0编辑  收藏  举报