4.1 Glance說明
4.1.1 Glance服務(wù)功能
- OpenStack鏡像服務(wù)(Glance)使用戶能夠發(fā)現(xiàn)、注冊(cè)并檢索虛擬機(jī)鏡像(.img文件);
- 它提供了一個(gè)
REST API接口,使用戶可以查詢虛擬機(jī)鏡像源數(shù)據(jù)和檢索一個(gè)實(shí)際的鏡像文件; - 不論是簡(jiǎn)單的文件系統(tǒng)還是 OpenStack 對(duì)象存儲(chǔ),你都可以通過鏡像服務(wù)在不同位置存儲(chǔ)虛擬鏡像
- 默認(rèn)情況下,上傳的虛擬機(jī)鏡像存儲(chǔ)路徑為
/var/lib/glance/images/
4.1.2 組件說明
-
glance-api
一個(gè)用來接收鏡像、發(fā)現(xiàn)、檢索和存儲(chǔ)的API接口;
-
glance-registry
用來存儲(chǔ)、處理和檢索鏡像的元數(shù)據(jù);
元數(shù)據(jù)包換對(duì)象的大小和類型;
glance-registry是一個(gè)OpenStack鏡像服務(wù)使用的內(nèi)部服務(wù),不要透露給用戶;
-
DataBase
用戶存儲(chǔ)鏡像的元數(shù)據(jù)的大小、類型,支持大多數(shù)數(shù)據(jù)庫,一般選擇
MySQL或SQLite; -
Storage repository for image files
鏡像文件的存儲(chǔ)倉庫;
支持包括普通文件系統(tǒng)在內(nèi)的各種存儲(chǔ)類型;
包括對(duì)象存儲(chǔ)、塊設(shè)備、HTTP、Amazon S3,但有些存儲(chǔ)只支持只讀訪問;
-
Image Identifiers
Image URL,格式<Glance Server Location>/images/<ID>;全局唯一;
-
Image Status
-
Queued鏡像ID已被保留,鏡像還沒有上傳 -
Saving鏡像正在被上傳 -
Active鏡像可以使用 -
Killed鏡像損壞或者不可用 -
Deleted鏡像被刪除
-
-
Disk Format
-
RawThis si unstructured disk image format -
VhdVMare、XEN、Microsoft、VirtualBox -
Vmdkcommon format -
VdiVirtualBox、QEMU emulator -
ISOoptical disc -
Qcow2QEMU emulator -
AkiAmazon Kernel Image -
AriAmazon RamDisk Image -
AmiAmazon Machine Image
-
-
Container Format
BareOvfAkiAmiAri
4.2 部署 Glance
4.2.1 創(chuàng)建Clance數(shù)據(jù)庫
CREATE DATABASE glance;
GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'glance';
GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'glance';
FLUSH PRIVILEGES;
4.2.2 創(chuàng)建Glance用戶
加載
admin憑證,來獲取管理員命令的執(zhí)行權(quán)限
source admin-openrc
創(chuàng)建
glance用戶
openstack user create --domain default --password-prompt glance
User Password:glance
Repeat User Password:glance
+---------------------+----------------------------------+
| Field | Value |
+---------------------+----------------------------------+
| domain_id | default |
| enabled | True |
| id | 4f080a83b50d4a118cf8912f2caff239 |
| name | glance |
| options | {} |
| password_expires_at | None |
+---------------------+----------------------------------+
給
glance用戶分配admin角色,并加入到service項(xiàng)目
openstack role add --project service --user glance admin
創(chuàng)建
glance服務(wù)
openstack service create --name glance --description "OpenStack Image" image
+-------------+----------------------------------+
| Field | Value |
+-------------+----------------------------------+
| description | OpenStack Image |
| enabled | True |
| id | 926ff884210448eba132cb949a974d95 |
| name | glance |
| type | image |
+-------------+----------------------------------+
創(chuàng)建
glanceAPI 端點(diǎn)
openstack endpoint create --region RegionOne image public http://controller:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | ea975e2fa8c04cbeafe3ad31fc838202 |
| interface | public |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 926ff884210448eba132cb949a974d95 |
| service_name | glance |
| service_type | image |
| url | http://controller:9292 |
+--------------+----------------------------------+
openstack endpoint create --region RegionOne image internal http://controller:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | 0d0fb6f4838c461f89fd465018aef4a4 |
| interface | internal |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 926ff884210448eba132cb949a974d95 |
| service_name | glance |
| service_type | image |
| url | http://controller:9292 |
+--------------+----------------------------------+
openstack endpoint create --region RegionOne image admin http://controller:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | 0b924b6956b84495bc92f28ad58791f3 |
| interface | admin |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 926ff884210448eba132cb949a974d95 |
| service_name | glance |
| service_type | image |
| url | http://controller:9292 |
+--------------+----------------------------------+
4.2.3 安裝配置Glance
# 安裝Glance
yum install -y openstack-glance
# 配置Glance
vim /etc/glance/glance-api.conf
配置數(shù)據(jù)庫連接
[database]
...
connection = mysql+pymysql://glance:glance@controller.alec.com/glance
# 用戶 密碼
配置認(rèn)證服務(wù)訪問
[keystone_authtoken]
www_authenticate_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 = glance
...
[paste_deploy]
flavor = keystone
配置本地文件系統(tǒng)存儲(chǔ)和鏡像文件位置
[glance_store]
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/
4.2.4 初始化數(shù)據(jù)庫
su -s /bin/sh -c "glance-manage db_sync" glance
4.2.5 啟動(dòng)服務(wù)
systemctl start openstack-glance-api
systemctl enable openstack-glance-api
4.3 驗(yàn)證服務(wù)
獲取admin憑證執(zhí)行admin命令
source admin-openrc
4.3.1 最快測(cè)試方法
手動(dòng)生成一個(gè).img文件,傳到Glance上;
dd if=/dev/zero of=test.img bs=1M count=10
openstack image create "test" --file test.img --disk-format qcow2 --container-format bare --public
4.3.2 官方測(cè)試方法
下載鏡像
wget http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img
使用
qcow2磁盤格式、bare容器格式 上傳到glance服務(wù),并設(shè)置為public;讓所有項(xiàng)目都可以訪問;
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 | 2020-07-18T15:21:52Z |
| disk_format | qcow2 |
| file | /v2/images/2ab0cd11-0aa3-4735-a85f-2c348de0a89d/file |
| id | 2ab0cd11-0aa3-4735-a85f-2c348de0a89d |
| min_disk | 0 |
| min_ram | 0 |
| name | cirros |
| owner | c6f8d8041d5c4f128c4d6c489156b875 |
| protected | False |
| schema | /v2/schemas/image |
| size | 13287936 |
| status | active |
| tags | |
| updated_at | 2020-07-18T15:21:53Z |
| virtual_size | None |
| visibility | public |
+------------------+------------------------------------------------------+
查看上傳后的鏡像信息
openstack image list
+--------------------------------------+--------+--------+
| ID | Name | Status |
+--------------------------------------+--------+--------+
| 2ab0cd11-0aa3-4735-a85f-2c348de0a89d | cirros | active |
+--------------------------------------+--------+--------+