openstack核心組件——glance— 鏡像服務(6)

雲計算openstack核心組件——glance— 鏡像服務(6)

 
1、glance介紹:
      
      Glance是Openstack項目中負責鏡像管理的模塊,其功能包括虛擬機鏡像的查找、註冊和檢索等。 Glance提供Restful API能夠查詢虛擬機鏡像的metadata及獲取鏡像。 Glance能夠將鏡像保存到多種後端存儲上,好比簡單的文件存儲或者對象存儲。
 
理解 Image
 
要理解 Image Service,先得搞清楚什麼是 Image 以及爲何要用 Image?
 
在傳統 IT 環境下,安裝一個系統要麼從安裝 CD 從頭安裝,要麼用 Ghost 等克隆工具恢復。這兩種方式有以下幾個問題:
 
  1. 若是要安裝的系統多了效率就很低
  2. 時間長,工做量大
  3. 安裝完還要進行手工配置,好比安裝其餘的軟件,設置 IP 等
  4. 備份和恢復系統不靈活
 
雲環境下須要更高效的方案,這就是 Image。 Image 是一個模板,裏面包含了基本的操做系統和其餘的軟件。
 
舉例來講,有家公司須要爲每位員工配置一套辦公用的系統,通常須要一個 Win7 系統再加 MS office 軟件。 OpenStack 是這麼玩的:
 
  1. 先手工安裝好這麼一個虛機
  2. 而後對虛機執行 snapshot,這樣就獲得了一個 image
  3. 當有新員工入職須要辦公環境時,立馬啓動一個或多個該 image 的 instance(虛機)就能夠了
 
在這個過程當中,第 1 步跟傳統方式相似,須要手工操做和必定時間,但第 二、3 步很是快,全自動化,通常都是秒級別。並且 二、3 步能夠循環作。 好比公司新上了一套 OA 系統,每一個員工的 PC 上都得有客戶端軟件。 那麼能夠在某個現有虛機中先手工安裝好 OA 客戶端,而後執行 snapshot 操做,獲得新的 image,之後能夠就直接使用新 image 建立虛機了。另外,snapshot 還有備份的做用,可以很是方便的恢復系統。
 
理解Image Service
Image Service 的功能是管理 Image,讓用戶可以發現、獲取和保存 Image。在 OpenStack 中,提供 Image Service 的是 Glance,其具體功能以下:
 
  1. 提供 REST API 讓用戶可以查詢和獲取 image 的元數據和 image 自己
  2. 支持多種方式存儲 image,包括普通的文件系統、Swift、Amazon S3 等
  3. 對 Instance 執行 Snapshot 建立新的 image
     
Glance 架構
上面是 Glance 的架構圖

glance-api

glance-api 是系統後臺運行的服務進程。 對外提供 REST API,響應 image 查詢、獲取和存儲的調用。
 
glance-api 不會真正處理請求。 若是操做是與 image metadata(元數據)相關,glance-api 會把請求轉發給 glance-registry; 若是操做是與 image 自身存取相關,glance-api 會把請求轉發給該 image 的 store backend。
 
在控制節點上能夠查看 glance-api 進程
 

glance-registry

glance-registry 是系統後臺運行的服務進程。 負責處理和存取 image 的 metadata,例如 image 的大小和類型。在控制節點上能夠查看 glance-registry 進程
 
 
Glance 支持多種格式的 image,包括
 

Database

Image 的 metadata 會保持到 database 中,默認是 MySQL。 在控制節點上能夠查看 glance 的 database 信息
 

Store backend

Glance 本身並不存儲 image。 真正的 image 是存放在 backend 中的。 Glance 支持多種 backend,包括:
 
  1. A directory on a local file system(這是默認配置)
  2. GridFS
  3. Ceph RBD
  4. Amazon S3
  5. Sheepdog
  6. OpenStack Block Storage (Cinder)
  7. OpenStack Object Storage (Swift)
  8. VMware ESX
 
具體使用哪一種 backend,是在 /etc/glance/glance-api.conf 中配置的
其餘 backend 的配置可參考http://docs.openstack.org/liberty/config-reference/content/configuring-image-service-backends.html
 
查看目前已經存在的 image
 
 
查看保存目錄
 
 
每一個 image 在目錄下都對應有一個文件,文件以 image 的 ID 命名。
 
2、glance建立鏡像:
 
        OpenStack 爲終端用戶提供了 Web UI(Horizon)和命令行 CLI 兩種交換界面。兩種方式咱們都要會用。可能有些同窗以爲既然有更友好的 Web UI 了,幹嗎還要用 CLI? 這裏有下面的理由:
一、Web UI 的功能沒有 CLI 全,有些操做只提供了 CLI。 即使是都有的功能,CLI 可使用的參數更多
二、通常來講,CLI 返回結果更快,操做起來更高效
四、CLI 可放在腳本中進行批處理
五、有些耗時的操做 CLI 更合適,好比建立鏡像(後面將涉及)
(1)Web UI 建立 image
(2)CLI 建立 image
將上傳的鏡像傳到控制節點
執行image上傳鏡像命令:
openstack image create "cirros"   --file cirros-0.3.3-x86_64-disk.img.img   --disk-format qcow2 --container-format bare --public
3、glance配置文件:
vim /etc/glance/glance-api.conf
 
[DEFAULT]
 
[cors]
[cors.subdomain]
 
[database]
connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance
 
[glance_store]
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/
 
[image_format]
 
[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 = glance
 
[matchmaker_redis]
 
[oslo_concurrency]
 
[oslo_messaging_amqp]
 
[oslo_messaging_kafka]
 
[oslo_messaging_notifications]
 
[oslo_messaging_rabbit]
 
[oslo_messaging_zmq]
 
[oslo_middleware]
 
[oslo_policy]
 
[paste_deploy]
flavor = keystone
 
[profiler]
 
[store_type_location_strategy]
 
[task]
 
[taskflow_executor]

vim /etc/glance/glance-registry.confhtml

 

[DEFAULT]
 
[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 = glance
 
[matchmaker_redis]
 
[oslo_messaging_amqp]
 
[oslo_messaging_kafka]
 
[oslo_messaging_notifications]
 
[oslo_messaging_rabbit]
 
[oslo_messaging_zmq]
 
[oslo_policy]
 
[paste_deploy]
flavor = keystone
 
[profiler]

 

布建openstack的glance node

1. mysql -u root -pmysql

2. CREATE DATABASE glance;redis

 

3.sql

GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' \ IDENTIFIED BY '123';shell

 

GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' \ IDENTIFIED BY '123';數據庫

3.source openrcapache

 

建立用戶 設置角色 設置服務 建立三種服務端點vim

(internal內部 admin管理 public公共)後端

 

4. 退出數據庫 建立 glance用戶 domain項目

 

openstack user create --domain default --password=glance glance

+---------------------+----------------------------------+

| Field | Value |

+---------------------+----------------------------------+

| domain_id | default |

| enabled | True |

| id | bcaefe90e2ce41879fde9c81332a2229 |

| name | glance |

| options | {} |

| password_expires_at | None |

+---------------------+----------------------------------+

 

5把glance的用戶 設置在service的項目中 設置admin的權限管理員

openstack role add --project service --user glance admin

 

6.建立服務

openstack service create --name glance \ --description "OpenStack Image" image

 

 

問題解決

[root@node1 ~]# openstack endpoint create --region RegionOne \

> image internal http://node1:9292

Missing value auth-url required for auth plugin password

[root@node1 ~]# source openrc

 

7建立服務端點

openstack endpoint create --region RegionOne \

image public http://node1:9292

服務端點列表 顯示兩種方式

1 openstack endpoint list

 

2 openstack catalog list

 

 

刪除不要的服務端點

openstack endpoint delete 加上ID 號

 

8 建立內部服務端點

openstack endpoint create --region RegionOne \ image internal http://node1:9292

 

 

 9 建立管理端點

openstack endpoint create --region RegionOne \ image admin http://node1:9292

 

openstack endpoint list 有3個glance

 

 

 

 

10 yum install openstack-glance -y

11 cd /etc/glance/

ls

 

LL

修改這兩個配置文件 注意屬主 屬組

 

 

cp glance-api.conf glance-api.conf.beifen 備份一根文件進行修改

cp glance-rgistry.conf glance-registry.conf.beifen

 

12 以前的所有刪除掉

vim glance-api.conf glance—store 進行後臺存儲

 

[DEFAULT]

 

[cors]

[cors.subdomain]

 

[database]

connection = mysql+pymysql://glance:GLANCE_DBPASS@node1/glance

 

[glance_store]

stores = file,http

default_store = file

filesystem_store_datadir = /var/lib/glance/images/

 

[image_format]

 

[keystone_authtoken]

auth_uri = http://node1:5000

auth_url = http://node1:35357

memcached_servers = node1:11211

auth_type = password

project_domain_name = default

user_domain_name = default

project_name = service

username = glance

password = glance

 

[matchmaker_redis]

 

[oslo_concurrency]

 

[oslo_messaging_amqp]

 

[oslo_messaging_kafka]

 

[oslo_messaging_notifications]

 

[oslo_messaging_rabbit]

 

[oslo_messaging_zmq]

 

[oslo_middleware]

 

[oslo_policy]

 

[paste_deploy] 認證模板

flavor = keystone

 

[profiler]

 

[store_type_location_strategy]

 

[task]

 

[taskflow_executor]

 

 

13 以前的所有刪除掉

vim glance-rgistry.conf 元數據有關的工做交給rgistry

 

[DEFAULT]

 

[database]

connection = mysql+pymysql://glance:GLANCE_DBPASS@node1/glance

 

[keystone_authtoken]

auth_uri = http://node1:5000

auth_url = http://node1:35357

memcached_servers = node1:11211

auth_type = password

project_domain_name = default

user_domain_name = default

project_name = service

username = glance

password = glance

 

[matchmaker_redis]

 

[oslo_messaging_amqp]

 

[oslo_messaging_kafka]

 

[oslo_messaging_notifications]

 

[oslo_messaging_rabbit]

 

[oslo_messaging_zmq]

 

[oslo_policy]

 

[paste_deploy]

flavor = keystone

 

[profiler]

 

14 導入表內容同步數據庫

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

 

 

15 glance-api glance-registry 開機自啓

# systemctl enable openstack-glance-api.service \ openstack-glance-registry.service # systemctl start openstack-glance-api.service \ openstack-glance-registry.service

 

 

查看狀態

# systemctl status openstack-glance-api.service \ openstack-glance-registry.service # systemctl status openstack-glance-api.service \ openstack-glance-registry.service

 

 

建立鏡像

16 wget http://download2.yunwei.edu/shell/openstack_app.tar.gz

 

17 ls

[root@node1 ~]# ls

1234.txt 2 3 5 7 9 apache-tomcat-9.0.20.zip openstack_app.tar.gz pjh.txt

1.txt 2.txt 4 6 8 anaconda-ks.cfg openrc openstack-ocata yum-repo.sh

 

18 tar zxf openstack_app.tar.gz

 

 

19 ls

[root@node1 openstack-ocata]# ls

cirros-0.3.3-x86_64-disk.img openstack-compute-yilai

 

20 openstack image create "cirros" \ --file cirros-0.3.3-x86_64-disk.img \ --disk-format qcow2 --container-format bare \ --public

 

| Field | Value |

+------------------+------------------------------------------------------+

| checksum | 133eae9fb1c98f45894a4e60d8736619 |

| container_format | bare |

| created_at | 2019-08-03T01:22:51Z |

| disk_format | qcow2 |

| file | /v2/images/6a99c72d-e083-471d-a6f7-787cd05f8e56/file |

| id | 6a99c72d-e083-471d-a6f7-787cd05f8e56 |

| min_disk | 0 |

| min_ram | 0 |

| name | cirros |

| owner | 77539b5d86c6419d88e99140ed0f84a1 |

| protected | False |

| schema | /v2/schemas/image |

| size | 13200896 |

| status | active |

| tags | |

| updated_at | 2019-08-03T01:22:52Z |

| virtual_size | None |

| visibility | public |

+------------------+------------------------------------------------------+

 

 

21 openstack image list

glance image-list

相關文章
相關標籤/搜索