鏡像服務使用戶可以發現、註冊和檢索虛擬機鏡像。它提供了一個REST API,使您可以查詢虛擬機鐿像元數據並檢索實際鐿像。您能夠將鏡像服務提供的虛擬機鏡像存儲在各類位置,從簡單的文件系統到對象存儲系統(如OpenStack對象存儲)。
OpenStack鏡像服務是基礎設施即服務(IaaS)的核心。它接受對磁盤或服務器鏡像的API請求,以及來自最終用戶或OpenStack計算組件的元數據定義。它還支持在各類存儲庫類型上存儲磁盤或服務器鏡像,包括OpenStack對象存儲。
爲了支持緩存,OpenStack鏡像服務上運行了許多週期性進程。複製服務經過集羣確保一致性和可用性。其餘週期性過程包括審覈員、更新人員和收割者。
OpenStack鏡像服務包括如下組件: mysql
安裝鏡像服務以前, 咱們必須創建數據庫,服務憑據,API端點.linux
○ 鏈接到數據庫,能夠在本機也可使用mysql客戶端鏈接: $ mysql -u root -proot123 ○ 創建glance數據庫: MariaDB [(none)]> CREATE DATABASE glance; ○ 授予相應的權限給glance數據庫,密碼統一爲用戶名後加123: MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'glance123';
$ . admin-openrc
創建服務的憑據,完成下列步驟:sql
○ 創建glance用戶: # openstack user create --domain default --password-prompt glance User Password: glance123 Repeat User Password:glance123 +---------------------+----------------------------------+ | Field | Value | +---------------------+----------------------------------+ | domain_id | default | | enabled | True | | id | 288f544d71f04eefb7389bd8af685b3b | | name | glance | | options | {} | | password_expires_at | None | +---------------------+----------------------------------+ ○ 添加管理員角色給glance用戶和service project: # openstack role add --project service --user glance admin 注意:此輸出無信息 ○ 創建glance服務實體 # openstack service create --name glance --description "OpenStack Image" image +-------------+----------------------------------+ | Field | Value | +-------------+----------------------------------+ | description | OpenStack Image | | enabled | True | | id | 4dba7578eae342d88c131e1c90768518 | | name | glance | | type | image | +-------------+----------------------------------+ ○ 創建鏡像服務API端點: # openstack endpoint create --region RegionOne image public http://stack.flex.net:9292 +--------------+----------------------------------+ | Field | Value | +--------------+----------------------------------+ | enabled | True | | id | 340be3625e9b4239a6415d034e98aace | | interface | public | | region | RegionOne | | region_id | RegionOne | | service_id | 8c2c7f1b9b49ea9e63757b5533e6d2 | | service_name | glance | | service_type | image | | url | http://controller:9292 | +--------------+----------------------------------+ # openstack endpoint create --region RegionOne image internal http://stack.flex.net:9292 +--------------+----------------------------------+ | Field | Value | +--------------+----------------------------------+ | enabled | True | | id | a6e4b153c2ae4c919eccfdbb7dceb5d2 | | interface | internal | | region | RegionOne | | region_id | RegionOne | | service_id | 8c2c7f1b9b49ea9e63757b5533e6d2 | | service_name | glance | | service_type | image | | url | http://controller:9292 | +--------------+----------------------------------+ # openstack endpoint create --region RegionOne image admin http://stack.flex.net:9292 +--------------+----------------------------------+ | Field | Value | +--------------+----------------------------------+ | enabled | True | | id | 0c37ed58103f4300a84ff125a539032d | | interface | admin | | region | RegionOne | | region_id | RegionOne | | service_id | 8c2c7f1b949ea9e63757b5533e6d2 | | service_name | glance | | service_type | image | | url | http://controller:9292 | +--------------+----------------------------------+
# yum install openstack-glance
vi編輯/etc/glance/glance-api.conf而且完成下列修改:數據庫
○ 在[database]區域, 配置數據庫訪問: [database] # ... connection = mysql+pymysql://glance:glance123@dbs.flex.net/glance ○ 在[keystone_authtoken]和[paste_deploy]區域, 配置身份認證服務訪問: [keystone_authtoken] # ... www_authenticate_uri = http://stack.flex.net:5000 auth_url = http://stack.flex.net:5000 memcached_servers = dbs.flex.net:11211 auth_type = password project_domain_name = Default user_domain_name = Default project_name = service username = glance password = glance123 [paste_deploy] # ... flavor = keystone 注意: 註釋或移除在掉在[keystone_authtoken]區域中的其它的選項. ○ 在[glance_store]區域, 配置本地文件存儲和鏡像文件的位置: [glance_store] # ... stores = file,http default_store = file filesystem_store_datadir = /var/lib/glance/images/
編輯/etc/glance/glance-registry.conf而且完成下列修改:api
○ In the [database] section, configure database access: [database] # ... connection = mysql+pymysql://glance:glance123@dbs.flex.net/glance ○ In the [keystone_authtoken] and [paste_deploy] sections, configure Identity service access: [keystone_authtoken] # ... www_authenticate_uri = http://stack.flex.net:5000 auth_url = http://stack.flex.net:5000 memcached_servers = dbs.flex.net:11211 auth_type = password project_domain_name = Default user_domain_name = Default project_name = service username = glance password = glance123 [paste_deploy] # ... flavor = keystone 注意: 註釋或移除在掉在[keystone_authtoken]區域中的其它的選項.
# su -s /bin/sh -c "glance-manage db_sync" glance
容許系統引導時自動啓動服務並啓動服務:緩存
# systemctl enable openstack-glance-api.service \ openstack-glance-registry.service # systemctl start openstack-glance-api.service \ openstack-glance-registry.service
使用cirros作爲鏡像服務校驗操做,這是一個很小的linux鏡像,幫助咱們測試openstack環境,執行下列的命令在controller節點上.服務器
$ . admin-openrc
$ wget http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img
上傳鏡像使用qcow2磁盤格式,bare 格式和公開權限訪問:dom
$ openstack image create "cirros" \ --file cirros-0.4.0-x86_64-disk.img \ --disk-format qcow2 --container-format bare \ --public +------------------+------------------------------------------------------+ | Field | Value | +------------------+------------------------------------------------------+ | checksum | 133eae9fb1c98f45894a4e60d8736619 | | container_format | bare | | created_at | 2015-03-26T16:52:10Z | | disk_format | qcow2 | | file | /v2/images/cc5c6982-4910-471e-b864-1098015901b5/file | | id | cc5c6982-4910-471e-b864-1098015901b5 | | min_disk | 0 | | min_ram | 0 | | name | cirros | | owner | ae7a98326b9c455588edd2656d723b9d | | protected | False | | schema | /v2/schemas/image | | size | 13200896 | | status | active | | tags | | | updated_at | 2015-03-26T16:52:10Z | | virtual_size | None | | visibility | public | +------------------+------------------------------------------------------+
確認上傳的鏡像和ID:ide
$ openstack image list +--------------------------------------+--------+--------+ | ID | Name | Status | +--------------------------------------+--------+--------+ | 38047887-61a7-41ea-9b49-27987d5e8bb9 | cirros | active | +--------------------------------------+--------+--------+