openstack--4--控制節點安裝配置glance


Glance相關介紹


 

image Service 的功能是管理 Image,讓用戶能夠發現、獲取和保存 Image。
在 OpenStack 中,提供 Image Service 的是 Glance,其具體功能如下:
1. 提供 REST API 讓用戶能夠查詢和獲取 image 的元數據和 image 本身
2. 支持多種方式存儲 image,包括普通的文件系統、Swift、Amazon S3 等
3. 對 Instance 執行 Snapshot 創建新的 image

上面是 Glance 的架構圖

glance-api
glance-api 是系統后台運行的服務進程。 對外提供 REST API,響應 image 查詢、獲取和存儲的調用。
glance-api 不會真正處理請求。 如果是與 image metadata(元數據)相關的操作,glance-api 會把請求轉發給 glance-registry;
如果是與 image 自身存取相關的操作,glance-api 會把請求轉發給該 image 的 store backend。

glance-registry
glance-registry 是系統后台運行的服務進程。 負責處理和存取 image 的 metadata,例如 image 的大小和類型。

glance-store
image 的元數據 通過glance-registry 存放在 db 中; image 的chunk 數據 通過 glance-store 存放在各種 backend store 中,並從中獲取
支持多種方式存儲 image,包括普通的文件系統、Swift、Amazon S3、GlusterFS 等

 

registry在api后面,它的作用和mysql打交道,存儲鏡像的屬性registry監聽9191端口,glance-api監聽9292端口
配置glance服務,要配置2個配置文件,1個api和1個registry
glance不需要配置消息隊列,但是需要配置keystone
鏡像默認在下面路徑下,這個目錄是 /var/lib/glance/images/。

 

安裝並配置組件


 

安裝軟件包
[root@linux-node1 ~]# yum install openstack-glance -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * epel: mirror01.idc.hinet.net
 * extras: mirrors.163.com
 * updates: mirrors.163.com
Package 1:openstack-glance-12.0.0-1.el7.noarch already installed and latest version
Nothing to do
[root@linux-node1 ~]# 

  

配置部分---數據庫部分

1、編輯文件 /etc/glance/glance-api.conf:
在 [database] 部分,配置數據庫訪問(大概在641行):

[root@linux-node1 ~]# vim /etc/glance/glance-api.conf
connection = mysql+pymysql://glance:glance@192.168.56.11/glance

2、編輯文件 /etc/glance/glance-registry.conf:
在 [database] 部分,配置數據庫訪問(382行左右):

[root@linux-node1 ~]# vim /etc/glance/glance-registry.conf
connection = mysql+pymysql://glance:glance@192.168.56.11/glance
3、同步數據庫。
有警告,openstack有警告沒關系,只要不是error即可
[root@linux-node1 ~]# su -s /bin/sh -c "glance-manage db_sync" glance
Option "verbose" from group "DEFAULT" is deprecated for removal.  Its value may be silently ignored in the future.
/usr/lib/python2.7/site-packages/oslo_db/sqlalchemy/enginefacade.py:1056: OsloDBDeprecationWarning: EngineFacade is deprecated; please use oslo_db.sqlalchemy.enginefacade
  expire_on_commit=expire_on_commit, _conf=conf)
[root@linux-node1 ~]# 
檢查同步結果
[root@linux-node1 ~]# mysql -h192.168.56.11 -uglance -pglance -e "use glance;show tables;"
+----------------------------------+
| Tables_in_glance                 |
+----------------------------------+
| artifact_blob_locations          |
| artifact_blobs                   |
| artifact_dependencies            |
| artifact_properties              |
| artifact_tags                    |
| artifacts                        |
| image_locations                  |
| image_members                    |
| image_properties                 |
| image_tags                       |
| images                           |
| metadef_namespace_resource_types |
| metadef_namespaces               |
| metadef_objects                  |
| metadef_properties               |
| metadef_resource_types           |
| metadef_tags                     |
| migrate_version                  |
| task_info                        |
| tasks                            |
+----------------------------------+
[root@linux-node1 ~]# 

  

 

配置部分---設置keystone

編輯文件 /etc/glance/glance-api.conf 並完成如下動作
在 [keystone_authtoken] 和 [paste_deploy] 部分,配置認證服務訪問:

 [keystone_authtoken]下添加下面參數

auth_uri = http://192.168.56.11:5000
auth_url = http://192.168.56.11:35357
memcached_servers = 192.168.56.11:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = glance
password = glance

 

 下面模塊下改成如下

 

以上操作,配置文件更改的部分如下
[root@linux-node1 ~]# grep -n "^[a-Z]"  /etc/glance/glance-api.conf
641:connection = mysql+pymysql://glance:glance@192.168.56.11/glance
1112:auth_uri = http://192.168.56.11:5000
1113:auth_url = http://192.168.56.11:35357
1114:memcached_servers = 192.168.56.11:11211
1115:auth_type = password
1116:project_domain_name = default
1117:user_domain_name = default
1118:project_name = service
1119:username = glance
1120:password = glance
1695:flavor = keystone
[root@linux-node1 ~]# 

  

編輯/etc/glance/glance-registry.conf
在 [keystone_authtoken] 和 [paste_deploy] 部分,配置認證服務訪問,配置內容和上面一樣:

 

 

 

glance-registry.conf 修改的地方
[root@linux-node1 ~]# grep -n "^[a-Z]"  /etc/glance/glance-registry.conf 
382:connection = mysql+pymysql://glance:glance@192.168.56.11/glance
837:auth_uri = http://192.168.56.11:5000
838:auth_url = http://192.168.56.11:35357
839:memcached_servers = 192.168.56.11:11211
840:auth_type = password
841:project_domain_name = default
842:user_domain_name = default
843:project_name = service
844:username = glance
845:password = glance
1402:flavor = keystone
[root@linux-node1 ~]# 

  

 

配置部分----設置鏡像位置

/etc/glance/glance-api.conf
在 [glance_store] 部分,配置本地文件系統存儲和鏡像文件位置
在下面模塊下取消這3行的注釋,可以通過搜索定位

[glance_store]
...
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/
 
 
最終/etc/glance/glance-api.conf改動如下
[root@linux-node1 ~]# grep -n "^[a-Z]"  /etc/glance/glance-api.conf
641:connection = mysql+pymysql://glance:glance@192.168.56.11/glance
741:stores = file,http
746:default_store = file
1025:filesystem_store_datadir = /var/lib/glance/images
1112:auth_uri = http://192.168.56.11:5000
1113:auth_url = http://192.168.56.11:35357
1114:memcached_servers = 192.168.56.11:11211
1115:auth_type = password
1116:project_domain_name = default
1117:user_domain_name = default
1118:project_name = service
1119:username = glance
1120:password = glance
1695:flavor = keystone
[root@linux-node1 ~]# 

  

 

 啟動glance相關服務


 

glance配置部分完畢,可以啟動glance服務了
[root@linux-node1 ~]# systemctl enable openstack-glance-api.service  openstack-glance-registry.service
Created symlink from /etc/systemd/system/multi-user.target.wants/openstack-glance-api.service to /usr/lib/systemd/system/openstack-glance-api.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/openstack-glance-registry.service to /usr/lib/systemd/system/openstack-glance-registry.service.
[root@linux-node1 ~]# systemctl start openstack-glance-api.service  openstack-glance-registry.service
[root@linux-node1 ~]# 

查看監聽狀態
registry監聽9191端口
glance-api監聽9292端口

[root@linux-node1 ~]# netstat -lntp 
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:9191            0.0.0.0:*               LISTEN      9299/python2        
tcp        0      0 0.0.0.0:5000            0.0.0.0:*               LISTEN      7352/httpd          
tcp        0      0 0.0.0.0:25672           0.0.0.0:*               LISTEN      4916/beam.smp       
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      1615/mysqld         
tcp        0      0 0.0.0.0:11211           0.0.0.0:*               LISTEN      7479/memcached      
tcp        0      0 0.0.0.0:9292            0.0.0.0:*               LISTEN      9298/python2        
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      7352/httpd          
tcp        0      0 0.0.0.0:4369            0.0.0.0:*               LISTEN      1/systemd           
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      1745/dnsmasq        
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1160/sshd           
tcp        0      0 0.0.0.0:15672           0.0.0.0:*               LISTEN      4916/beam.smp       
tcp        0      0 0.0.0.0:35357           0.0.0.0:*               LISTEN      7352/httpd          
tcp6       0      0 :::5672                 :::*                    LISTEN      4916/beam.smp       
tcp6       0      0 :::22                   :::*                    LISTEN      1160/sshd           
[root@linux-node1 ~]# 

  

 

在keystone上做服務注冊


 

 下面3步在之前都已經做了

1、之前glance的數據庫創建完畢
2、 glance 用戶創建完畢
openstack user create --domain default --password-prompt glance
3、添加 admin 角色到 glance 用戶和 service 項目上。
openstack role add --project service --user glance admin

 

接下來創建實體
1、創建glance服務實體,操作之前先source環境變量

[root@linux-node1 ~]# source admin-openstack.sh 
[root@linux-node1 ~]# openstack service create --name glance  --description "OpenStack Image" image
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Image                  |
| enabled     | True                             |
| id          | a7cdacff3e804796a7dbf466c616c5ec |
| name        | glance                           |
| type        | image                            |
+-------------+----------------------------------+
[root@linux-node1 ~]# 

  

2、創建鏡像服務的 API 端點
public,internal,admin 這3個,端口一致
(keystone的admin端口特殊,和public以及internal不一樣)

公共的

[root@linux-node1 ~]# openstack endpoint create --region RegionOne  image public http://192.168.56.11:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 4bfca46d433c4f2ebfc2c57ab6f50004 |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | a7cdacff3e804796a7dbf466c616c5ec |
| service_name | glance                           |
| service_type | image                            |
| url          | http://192.168.56.11:9292        |
+--------------+----------------------------------+
[root@linux-node1 ~]# 

 

內部的  

[root@linux-node1 ~]# openstack endpoint create --region RegionOne  image internal http://192.168.56.11:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | c16ae753c62c427194ae2b70655623c5 |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | a7cdacff3e804796a7dbf466c616c5ec |
| service_name | glance                           |
| service_type | image                            |
| url          | http://192.168.56.11:9292        |
+--------------+----------------------------------+
[root@linux-node1 ~]# 

 

管理的  

[root@linux-node1 ~]# openstack endpoint create --region RegionOne   image admin http://192.168.56.11:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 27ed39831e434c73ab2b400f1a1a4ab6 |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | a7cdacff3e804796a7dbf466c616c5ec |
| service_name | glance                           |
| service_type | image                            |
| url          | http://192.168.56.11:9292        |
+--------------+----------------------------------+
[root@linux-node1 ~]# 

  

3、查看鏡像列表

下面為空很正常,因為還沒導入鏡像呢

[root@linux-node1 ~]# openstack image list

[root@linux-node1 ~]# glance image-list
+----+------+
| ID | Name |
+----+------+
+----+------+
[root@linux-node1 ~]# 

  

4、導入鏡像

下載小鏡像

wget http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img

  

使用  QCOW2 磁盤格式,  bare 容器格式上傳鏡像到鏡像服務並設置公共可見,這樣所有的項目都可以訪問它
命令如下,注意操作時鏡像是在本目錄下,如果不是本目錄需要寫絕對路徑
openstack image create "cirros" \
  --file cirros-0.3.4-x86_64-disk.img \
  --disk-format qcow2 --container-format bare \
  --public
 
操作如下
[root@linux-node1 ~]# 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       | 2017-02-17T16:26:40Z                                |
| disk_format      | qcow2                                               |
| file             | /v2/images/9969eaa3-0296-48cc-a42e-                 |
|                  | a02251b778a6/file                                   |
| id               | 9969eaa3-0296-48cc-a42e-a02251b778a6                |
| min_disk         | 0                                                   |
| min_ram          | 0                                                   |
| name             | cirros                                              |
| owner            | e88437b3330145e1a713469130b4c3cd                    |
| protected        | False                                               |
| schema           | /v2/schemas/image                                   |
| size             | 13287936                                            |
| status           | active                                              |
| tags             |                                                     |
| updated_at       | 2017-02-17T16:26:40Z                                |
| virtual_size     | None                                                |
| visibility       | public                                              |
+------------------+-----------------------------------------------------+
[root@linux-node1 ~]# 

 

5、導入完畢,查看

[root@linux-node1 ~]# openstack image list
+--------------------------------------+--------+--------+
| ID                                   | Name   | Status |
+--------------------------------------+--------+--------+
| 9969eaa3-0296-48cc-a42e-a02251b778a6 | cirros | active |
+--------------------------------------+--------+--------+
[root@linux-node1 ~]# glance image-list
+--------------------------------------+--------+
| ID                                   | Name   |
+--------------------------------------+--------+
| 9969eaa3-0296-48cc-a42e-a02251b778a6 | cirros |
+--------------------------------------+--------+
[root@linux-node1 ~]# 

  

 文件在此路徑下,文件名和鏡像ID一致

[root@linux-node1 images]# cd /var/lib/glance/images/
[root@linux-node1 images]# ls -l
total 12980
-rw-r----- 1 glance glance 13287936 Feb 18 00:26 9969eaa3-0296-48cc-a42e-a02251b778a6
[root@linux-node1 images]# 

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM