之(三) Glance安裝

手動安裝Openstack Mikita的第三部分: 鏡像服務Glance安裝. 這部分內容主要是對OpenStack Installation Guide for Red Hat Enterprise Linux and CentOS在Glance這部分內容的實踐總結.

The Image service (glance) enables users to discover, register, and retrieve virtual machine images. It offers a REST API that enables you to query virtual machine image metadata and retrieve an actual image. You can store virtual machine images made available through the Image service in a variety of locations, from simple file systems to object-storage systems like OpenStack Object Storage.

爲了簡化操作, 我們將Glance服務安裝在controller節點. 默認的鏡像目錄爲 /var/lib/glance/images/ . 以下操作均在controller節點進行.

一. 安裝前準備

1. 爲Glance創建數據庫

[root@controller ~]# mysql -u root -p

CREATE DATABASE glance;
GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' \
  IDENTIFIED BY 'GLANCE_DBPASS';
GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' \
  IDENTIFIED BY 'GLANCE_DBPASS';

其中, GLANCE_DBPASS是Glance訪問數據庫時使用的密碼.

2. 創建Service和API Endpoint

(1) 獲取admin-only CLI指令的權限

[root@controller ~]# . admin-openrc

(2) 創建glance用戶

[root@controller ~]# openstack user create --domain default --password-prompt glance

User Password:
Repeat User Password:
+-----------+----------------------------------+
| Field     | Value                            |
+-----------+----------------------------------+
| domain_id | 23445595d52c44be995b0b393870b5ef |
| enabled   | True                             |
| id        | dee5c1d866804d2a83d6f5f62c329dc4 |
| name      | glance                           |
+-----------+----------------------------------+

這裏glance用戶的密碼爲: zzr.

(3) 把glance用戶增加到admin角色和service租戶

[root@controller ~]# openstack role add --project service --user glance admin

(4) 創建image服務

[root@controller ~]# openstack service create --name glance \
  --description "OpenStack Image" image

+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Image                  |
| enabled     | True                             |
| id          | 9df122e5374742cb9bfd1bec48622f30 |
| name        | glance                           |
| type        | image                            |
+-------------+----------------------------------+

(5) 創建image服務的Endpoints

  • public endpoint
[root@controller ~]# openstack endpoint create --region RegionOne \
  image public http://controller:9292

+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 7ddc527f399f4592943c0ac687e313ed |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 9df122e5374742cb9bfd1bec48622f30 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+
  • internal endpoint
[root@controller ~]# openstack endpoint create --region RegionOne \
  image internal http://controller:9292

+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 70f89821d1054a64ba044ac35554a082 |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 9df122e5374742cb9bfd1bec48622f30 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+
  • admin endpoint
[root@controller ~]# openstack endpoint create --region RegionOne \
  image admin http://controller:9292

+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 98f67ed0b6ab454a915d5c585b66b22d |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 9df122e5374742cb9bfd1bec48622f30 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+

二. 安裝glance組件

1. 安裝glance

[root@controller ~]# yum install openstack-glance -y

2. 配置glance

編輯文件 /etc/glance/glance-api.conf :

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

[paste_deploy]
...
flavor = keystone

[glance_store]
...
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/

其中, zzr爲上一步驟中爲glance用戶設置的密碼.

編輯文件 /etc/glance/glance-registry.conf .

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

[paste_deploy]
...
flavor = keystone

[keystone_authtoken]的內容, 除了以上增加的內容外, 其它的全部刪除.

(3) 同步glance配置成數據庫

以glance用戶的身份執行指令 glance-manage db_sync , 同步glance的配置到數據庫:

[root@controller ~]# su -s /bin/sh -c "glance-manage db_sync" glance

(4) 開啓Image服務

[root@controller ~]# # systemctl enable openstack-glance-api.service \
  openstack-glance-registry.service
[root@controller ~]# # systemctl start openstack-glance-api.service \
  openstack-glance-registry.service

3. 驗證

(1) 獲取admin-only CLI指令的權限

[root@controller ~]# . admin-openrc

(2) 獲取鏡像

[root@controller ~]# wget http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img

(3) 上傳鏡像到Image service

使用QCOW2硬盤格式. public可視, 從而所有project可以看到它.

[root@controller ~]# openstack image create "cirros" \
  --file cirros-0.3.4-x86_64-disk.img \
  --disk-format qcow2 --container-format bare \
  --public

+------------------+------------------------------------------------------+
| Field            | Value                                                |
+------------------+------------------------------------------------------+
| checksum         | ee1eca47dc88f4879d8a229cc70a07c6                     |
| container_format | bare                                                 |
| created_at       | 2016-08-01T11:26:58Z                                 |
| disk_format      | qcow2                                                |
| file             | /v2/images/57d1498f-cbd2-4314-9114-6f74c11d5952/file |
| id               | 57d1498f-cbd2-4314-9114-6f74c11d5952                 |
| min_disk         | 0                                                    |
| min_ram          | 0                                                    |
| name             | cirros                                               |
| owner            | f8207344afbc4983837fccd7ad29c3d7                     |
| protected        | False                                                |
| schema           | /v2/schemas/image                                    |
| size             | 13287936                                             |
| status           | active                                               |
| tags             |                                                      |
| updated_at       | 2016-08-01T11:26:59Z                                 |
| virtual_size     | None                                                 |
| visibility       | public                                               |
+------------------+------------------------------------------------------+

(4) 查看現有鏡像

[root@controller ~]# openstack image list

+--------------------------------------+--------+--------+
| ID                                   | Name   | Status |
+--------------------------------------+--------+--------+
| 38047887-61a7-41ea-9b49-27987d5e8bb9 | cirros | active |
+--------------------------------------+--------+--------+

參考文獻

  1. OpenStack Installation Guide for Red Hat Enterprise Linux and CentOS
  2. OpenStack Mitaka 安裝 for CentOS — Kyle.Bai
  3. OpenStack Liberty
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章