Centos7 安裝kilo-4 controller(glance)

簡介

Glance是OpenStack鏡像服務,用來註冊、登陸和檢索虛擬機鏡像。
Glance服務提供了一個REST API,能夠查詢虛擬機鏡像元數據和檢索的實際鏡像。
通過鏡像服務提供的虛擬機鏡像可以存儲在不同的位置,從簡單的文件系統對象存儲到類似OpeenStack對象存儲系統。

本次安裝使用普通文件作爲後端,將上傳的鏡像放在/var/lib/image這個目錄中,用於存儲虛擬機的鏡像和快照(確保這個目錄有足夠的空間)

鏡像服務的組件:
Glance-API 承接鏡像的探索,檢索和存儲鏡像的API調用。
Glance-registry 存儲,處理和檢索有關鏡像的元數據,元數據大小、類型等。
Database 存儲鏡像元數據,你可以選擇你喜歡的數據庫,現在比較多的是mysql和sqlite
Storage repository for image files 鏡像存儲,支持各種存儲類型,包括普通文件系統,RADOS塊設備,HTTP,和亞馬遜的S3,(注意,有些存儲只支持只讀)

配置glance數據庫

mysql -uroot -pPASS -e  "CREATE DATABASE glance;"
mysql -uroot -pPASS -e "GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'glance';"
mysql -uroot -pPASS -e "GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'glance';"

創建user、service,endpoint

  • source 變量
source admin-openrc.sh
  • 創建 glance user
 openstack user create --password-prompt glance
User Password:
Repeat User Password:
+----------+----------------------------------+
| Field    | Value                            |
+----------+----------------------------------+
| email    | None                             |
| enabled  | True                             |
| id       | d9363e392a764cc0968405b3ba19fe8b |
| name     | glance                           |
| username | glance                           |
+----------+----------------------------------+
  • 給予glance user admin 角色
 openstack role add --project service --user glance admin

+-------+----------------------------------+
| Field | Value                            |
+-------+----------------------------------+
| id    | 53e5d390efe84b948ba5718f116b4861 |
| name  | admin                            |
+-------+----------------------------------+
  • 創建glance service
openstack service create --name glance --description "OpenStack Image service" image

+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Image service          |
| enabled     | True                             |
| id          | e4417d6d57654f96bf8cff0a3327a97c |
| name        | glance                           |
| type        | image                            |
+-------------+----------------------------------+
  • 創建 glance api endpoint
openstack endpoint create \
--publicurl http://controller:9292 \
--internalurl http://controller:9292 \
--adminurl http://controller:9292 \
--region RegionOne \
image

+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| adminurl     | http://controller:9292           |
| id           | f0b4177e0daa4dac939f91e3b9f09e26 |
| internalurl  | http://controller:9292           |
| publicurl    | http://controller:9292           |
| region       | RegionOne                        |
| service_id   | e4417d6d57654f96bf8cff0a3327a97c |
| service_name | glance                           |
| service_type | image                            |
+--------------+----------------------------------+

安裝glance軟件包

 yum -y install openstack-glance python-glance python-glanceclient

配置glance

  • glance-api.conf
openstack-config --set /etc/glance/glance-api.conf database  connection mysql://glance:glance@controller/glance

openstack-config --set /etc/glance/glance-api.conf keystone_authtoken  auth_uri http://controller:5000
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken  auth_url http://controller:35357
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken  auth_plugin  password
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken  project_domain_id  default
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken  user_domain_id default
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken  project_name service
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken  username glance
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken  password  glance

openstack-config --set /etc/glance/glance-api.conf paste_deploy flavor keystone

openstack-config --set /etc/glance/glance-api.conf glance_store default_store file
openstack-config --set /etc/glance/glance-api.conf glance_store filesystem_store_datadir /var/lib/glance/images/

openstack-config --set /etc/glance/glance-api.conf DEFAULT notification_driver noop
openstack-config --set /etc/glance/glance-api.conf DEFAULT verbose True
  • glance-registry.conf
openstack-config --set /etc/glance/glance-registry.conf database  connection mysql://glance:glance@controller/glance

openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken  auth_uri http://controller:5000
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken  auth_url http://controller:35357
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken  auth_plugin  password
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken  project_domain_id  default
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken  user_domain_id default
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken  project_name service
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken  username glance
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken  password  glance


openstack-config --set /etc/glance/glance-registry.conf paste_deploy flavor keystone


openstack-config --set /etc/glance/glance-registry.conf  glance_store default_store file
openstack-config --set /etc/glance/glance-registry.conf  glance_store filesystem_store_datadir /var/lib/glance/images/

openstack-config --set /etc/glance/glance-api.conf DEFAULT notification_driver noop
openstack-config --set /etc/glance/glance-api.conf DEFAULT verbose True

初始化 glance數據庫

su -s /bin/sh -c "glance-manage db_sync" glance

啓動glance並設置開啓啓動

systemctl enable openstack-glance-api.service openstack-glance-registry.service
systemctl restart openstack-glance-api.service openstack-glance-registry.service

驗證服務

  • 設置環境變量(glance api選用2.0)
echo "export OS_IMAGE_API_VERSION=2" | tee -a admin-openrc.sh demo-openrc.sh
source admin-openrc.sh
  • 創建本地目錄並下載測試鏡像
  mkdir /tmp/images
  wget -P /tmp/images http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img
  • 上傳鏡像並查看
glance image-create --name "cirros-0.3.4-x86_64" --file /tmp/images/cirros-0.3.4-x86_64-disk.img \
> --disk-format qcow2 --container-format bare --visibility public --progress

[=============================>] 100%
+------------------+--------------------------------------+
| Property         | Value                                |
+------------------+--------------------------------------+
| checksum         | ee1eca47dc88f4879d8a229cc70a07c6     |
| container_format | bare                                 |
| created_at       | 2015-09-10T04:26:06Z                 |
| disk_format      | qcow2                                |
| id               | 476d7b76-57d8-48be-a7e0-2130e718f157 |
| min_disk         | 0                                    |
| min_ram          | 0                                    |
| name             | cirros-0.3.4-x86_64                  |
| owner            | 6655a8db1705461384c78137e5e87c17     |
| protected        | False                                |
| size             | 13287936                             |
| status           | active                               |
| tags             | []                                   |
| updated_at       | 2015-09-10T04:26:07Z                 |
| virtual_size     | None                                 |
| visibility       | public                               |
+------------------+--------------------------------------+


glance image-list
+--------------------------------------+---------------------+
| ID                                   | Name                |
+--------------------------------------+---------------------+
| 476d7b76-57d8-48be-a7e0-2130e718f157 | cirros-0.3.4-x86_64 |
+--------------------------------------+---------------------+


ls /var/lib/glance/images/
476d7b76-57d8-48be-a7e0-2130e718f157

glance服務小結

項目 說明
服務名稱 glance
啓動命令 systemctl restart openstack-glance-api.service openstack-glance-registry.service
image存放目錄 /var/lib/glance/images/
api配置文件 /etc/glance/glance-api.conf
registry配置文件 /etc/glance/glance-registry.conf
api 日誌 /var/log/glance/api.log
registry日誌 /var/log/glance/registry.log
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章