openstack部署之glance

簡介

  Glance是Openstack的鏡像服務。可以讓用戶註冊、查找和檢索在Openstack環境中使用的虛擬鏡像。Openstack鏡像服務支持將鏡像文件存儲在各種類型的存儲環境中。例如本地文件系統或分佈式文件系統,如Openstack的對象存儲服務(Swift)。下邊我們開始部署Glance組件。

創建數據庫

與keystone部署一樣,需要先創建名爲glance的數據庫

$ mysql -u root -p
MariaDB [(none)]> CREATE DATABASE glance;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'glance';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'glance';

組件部署

Glance分爲兩個子服務,如下所示

  • Glance-api:接受雲系統鏡像的創建、刪除、讀取服務
  • Glance-Registry:雲系統的鏡像註冊服務

安裝

# yum install openstack-glance

配置

編輯/etc/glance/glance-api.conf文件

[database]
# ...
connection = mysql+pymysql://glance:[email protected]/glance
#...
[keystone_authtoken]
auth_uri = http://192.168.46.130:5000
auth_url = http://192.168.46.130:35357
memcached_servers = 192.168.46.130:11211 #memcached的端口
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = glance
password = glance
#...
[paste_deploy]
# ...
flavor = keystone
#...
[glance_store]
# ...
stores = file,http
default_store = file 
filesystem_store_datadir = /var/lib/glance/images/  #設置鏡像本地存儲

編輯 /etc/glance/glance-registry.conf ,需要修改的配置與/etc/glance/glance-api.conf類似

[database]
# ...
connection = mysql+pymysql://glance:[email protected]/glance
#...
[keystone_authtoken]
auth_uri = http://192.168.46.130:5000
auth_url = http://192.168.46.130:35357
memcached_servers = 192.168.46.130:11211  #memcached的端口
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = glance
password = glance
#...
[paste_deploy]
# ...
flavor = keystone

初始化glance數據庫

# 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

在keystone註冊Glance

經過以上操作可以說Glance已經基本部署完成了,但是這樣的話,其他組件是無法使用Glance的,接下來還需要在keystone中做註冊,因爲openstack的其他組件訪問Glance時,都是先到keystone上做認證,獲得訪問Glance的權限,也就是得到一個token,然後才能訪問Glance。

  • 先把環境變量設置上去,使用之前保存的腳本
source admin-openstack.sh
  • 創建glance用戶
$ openstack user create --domain default --password-prompt glance

User Password:
Repeat User Password:
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | 3f4e777c4062483ab8d9edd7dff829df |
| name                | glance                           |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+
  • 添加角色和項目
$ openstack role add --project service --user glance admin
  • 註冊服務
$ openstack service create --name glance --description "OpenStack Image" image  #不能亂改

+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Image                  |
| enabled     | True                             |
| id          | 8c2c7f1b9b5049ea9e63757b5533e6d2 |
| name        | glance                           |
| type        | image                            |
+-------------+----------------------------------+
  • 註冊endpoint
[root@localhost ~]# openstack endpoint create --region RegionOne image public http://192.168.46.130:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 3bf50e2feba3467c8ee661615f015376 |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | d408f9afadf24865b0213971a0a93efe |
| service_name | glance                           |
| service_type | image                            |
| url          | http://192.168.46.130:9292       |
+--------------+----------------------------------+
[root@localhost ~]# openstack endpoint create --region RegionOne  image internal http://192.168.46.130:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 6c36fa5d0f8841e899e022fea24e725f |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | d408f9afadf24865b0213971a0a93efe |
| service_name | glance                           |
| service_type | image                            |
| url          | http://192.168.46.130:9292       |
+--------------+----------------------------------+
[root@localhost ~]# openstack endpoint create --region RegionOne image admin http://192.168.46.130:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 6b6d54d2f0034a01b25ccd14f82425ca |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | d408f9afadf24865b0213971a0a93efe |
| service_name | glance                           |
| service_type | image                            |
| url          | http://192.168.46.130:9292       |
+--------------+----------------------------------+

以上三個endpoint是可以設置三個不同的IP的,public爲公網,internal爲內網,admin爲管理。可以設置三個不同的url分別部署在不同的主機上。本次我們只使用了一個主機部署,所以設置的都一樣。

驗證Glance安裝

至此Glance我們就完成部署了,下邊執行命令驗證Glance是否正常

[root@localhost ~]# openstack image list

[root@localhost ~]# 

如果以上命令正常執行,則說明Glance部署成功

加載鏡像

  • 設置環境變量
source admin-openstack.sh
  • 下載鏡像
$ wget http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img
  • 加載鏡像
$ openstack image create "cirros" \
  --file cirros-0.3.5-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                                               |
+------------------+------------------------------------------------------+
  • 查看鏡像
$ openstack image list

+--------------------------------------+--------+--------+
| ID                                   | Name   | Status |
+--------------------------------------+--------+--------+
| 38047887-61a7-41ea-9b49-27987d5e8bb9 | cirros | active |
+--------------------------------------+--------+--------+

其他

如果在部署過程中服務報錯,可以在/var/log/glance/目錄下查看glance的日誌,如下:

可以在日誌中查看ERROR的信息。當然在/var/log/keystone/下同樣可以看到keystone的日誌。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章