OpenStack 鏡像服務 Glance部署(七)


創建虛擬機我們需要有glance的支持,因為glance是提供鏡像的服務。

Glance有兩個比較重要的服務:

  • Glance-api:接受雲系統鏡像的構建、刪除、讀取請求
  • Glance-Registry:雲系統的鏡像注冊服務

我們需要配置glance-api的配置文件和glance-registry配置文件 。glance不需要配置消息隊列,但是glance需要配置keystone(認證中心)。

提示:默認情況下上傳鏡像存放在/var/lib/glance/images下

 

一)在keystone上服務注冊 

1.1 創建glance服務實體

root@controller ~]# source admin-openrc

[root@controller ~]# openstack service create --name glance --description "OpenStack Image" image

+-------------+----------------------------------+
| Field | Value |
+-------------+----------------------------------+
| description | OpenStack Image |
| enabled | True |
| id | 1ebbfc83e7f6485eb761be2d7924493b |
| name | glance |
| type | image |
+-------------+----------------------------------+

1.2  創建Compute服務api端點(公有、私有、admin)

[root@controller ~]# openstack endpoint create --region RegionOne \
>   image public http://controller:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 869d2403d3f64d4e9b38014b8d3bf8df |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 1ebbfc83e7f6485eb761be2d7924493b |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+
 [root@controller ~]# openstack endpoint create --region RegionOne \
>   image internal http://controller:9292

+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 0f4ac6d92e5f4e18bfbce90b0b2ab604 |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 1ebbfc83e7f6485eb761be2d7924493b |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+

[root@controller ~]#  openstack endpoint create --region RegionOne \
>   image admin http://controller:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 77075f68191b4cd8aa8fb1c030417458 |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 1ebbfc83e7f6485eb761be2d7924493b |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+

  

二).安裝配置glance

2.1安裝glance軟件包

# yum install openstack-glance -y

2.2  配置glance-api配置文件

 vim /etc/glance/glance-api.conf
[database]
connection = mysql+pymysql://glance:redhat@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 = redhat                      # 密碼


[glance_store]
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/

3.3 配置glance-registry配置文件

 # vim /etc/glance/glance-registry.conf 
 [database]
connection = mysql+pymysql://glance:redhat@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 = redhat

[paste_deploy]
flavor = keystone

  

3.4 同步數據庫

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

驗證是否成功

# mysql -u glance -predhat -e "use glance;show tables;"

3.5、啟動服務並設置開機自啟動

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

3.6 、下載測試鏡像源

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

使用 QCOW2 磁盤格式, bare 容器格式上傳鏡像到鏡像服務並設置公共可見,這樣所有的項目都可以訪問它

# source admin-openrc

[root@controller ~]# openstack image create "cirros" \
> --file /root/cirros-0.3.4-x86_64-disk.img \
> --disk-format qcow2 --container-format bare \
> --public
+------------------+------------------------------------------------------+
| Field | Value |
+------------------+------------------------------------------------------+
| checksum | ee1eca47dc88f4879d8a229cc70a07c6 |
| container_format | bare |
| created_at | 2018-04-13T07:50:12Z |
| disk_format | qcow2 |
| file | /v2/images/c952e002-680e-45e1-9337-08d2c3a9abe6/file |
| id | c952e002-680e-45e1-9337-08d2c3a9abe6 |
| min_disk | 0 |
| min_ram | 0 |
| name | cirros |
| owner | 24a37179b1844e8897e77a0c44cc8d25 |
| protected | False |
| schema | /v2/schemas/image |
| size | 13287936 |
| status | active |
| tags | |
| updated_at | 2018-04-13T07:50:12Z |
| virtual_size | None |
| visibility | public |
+------------------+------------------------------------------------------+

檢查是否上傳成功

openstack image list
[root@controller ~]# glance image-list
+--------------------------------------+--------+
| ID | Name |
+--------------------------------------+--------+
| c952e002-680e-45e1-9337-08d2c3a9abe6 | cirros |
+--------------------------------------+--------+
[root@controller ~]# ls /var/lib/glance/images/
c952e002-680e-45e1-9337-08d2c3a9abe6

備注:鏡像存放在/var/lib/glance/images下


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2021 ITdaan.com