1. 程式人生 > >安裝和配置映象服務glance

安裝和配置映象服務glance

安裝glace

sudo apt-get install glance

安裝glance客戶端

sudo apt-get install python-glanceclient

建立一個數據庫用來儲存映象

[email protected]:/$ MYSQL_ROOT_PASSWORD=openstack
[email protected]:/$ mysql -uroot -p$MYSQL_ROOT_PASSWORD -e 'create database glance;'

為該資料庫建立一個使用者

[email protected]:/$ MYSQL_GLANCE_PASSWORD=openstack
[email protected]
:/$ mysql -uroot -p$MYSQL_ROOT_PASSWORD -e "GRANT ALL PRIVILEGES ON glance.* to 'glance'@'%' identified by '${MYSQL_GLANCE_PASSWORD}';" [email protected]:/$ mysql -uroot -p$MYSQL_ROOT_PASSWORD -e "GRANT ALL PRIVILEGES ON glance.* to 'glance'@'localhost' identified by '${MYSQL_GLANCE_PASSWORD}';" mysqladmin -uroot -popenstack flush-privileges

修改glance配置檔案

sudo sed -i "s,^sql_connection.*,sql_connection = mysql://glance:${MYSQL_GLANCE_PASSWORD}@172.16.0.200/glance," /etc/glance/glance-{registry,api}.conf

重啟glance-registry和glance-api服務

[email protected]:/$ sudo stop glance-registry
[email protected]:/$ sudo start glance-registry
[email protected]
:/$ sudo stop glance-api [email protected]:/$ sudo start glance-api

設定版本為0

sudo glance-manage version_control 0

插入正確的表

sudo glance-manage db_sync

配置glance使用之前在keystone中為其設定的使用者 編輯/etc/glance/glance-api-paste.ini檔案,修改如下內容

[filter:authtoken]
paste.filter_factory = keystoneclient.middleware.auth_token:filter_factory
#delay_auth_decision = true
admin_tenant_name = service
admin_user = glance
admin_password = glance

然後配置/etc/glance/glance-api.conf檔案

[keystone_authtoken]
auth_host = 172.16.0.200
auth_port = 35357
auth_protocol = http
admin_tenant_name = service
admin_user = glance
admin_password = glance

[paste_deploy]
# Name of the paste configuration file that defines the available pipelines
config_file = /etc/glance/glance-api-paste.ini

# Partial name of a pipeline in your paste configuration file with the
# service name removed. For example, if your paste section name is
# [pipeline:glance-api-keystone], you would configure the flavor below
# as 'keystone'.
flavor=keystone

同樣的配置/etc/glance/glance-registry-paste.ini檔案

[filter:authtoken]
paste.filter_factory = keystoneclient.middleware.auth_token:filter_factory
admin_tenant_name = service
admin_user = glance
admin_password = glance

/etc/glance/glance-registry.conf檔案

[keystone_authtoken]
auth_host = 172.16.0.200
auth_port = 35357
auth_protocol = http
admin_tenant_name = service
admin_user = glance
admin_password = glance

[paste_deploy]
# Name of the paste configuration file that defines the available pipelines
config_file = /etc/glance/glance-registry-paste.ini

# Partial name of a pipeline in your paste configuration file with the
# service name removed. For example, if your paste section name is
# [pipeline:glance-registry-keystone], you would configure the flavor below
# as 'keystone'.
flavor=keystone

最後重啟glace-api和glance-registry

[email protected]:/$ sudo restart glance-api
[email protected]:/$ sudo restart glance-registry

在安裝有python-glanceclient的機器中使用glance來管理映象 首先配置以下變數

[email protected]:~# export OS_TENANT_NAME=cookbook
[email protected]:~# export OS_USERNAME=admin
[email protected]:~# export OS_PASSWORD=openstack
[email protected]:~# export OS_AUTH_URL=http://172.16.0.200:5000/v2.0
[email protected]:~# export OS_NO_CACHE=1

然後使用glance客戶端註冊這個映象

[email protected]:~/cookbook# glance image-create --name='ubuntu-12.04-server-cloudimg-amd64' --disk-format=qcow2 --container-format=bare --public <ubuntu-12.04-server-cloudimg-amd64-disk1.img

去掉--public可以上傳一個私有映象,即只有上傳者擁有許可權 使用glance image-update $IMAGE_ID --is-public True可以將映象設為公開,這樣其他使用者也就可以使用該映象了。 可以通過下面的命令註冊一個遠端映象

[email protected]:~/cookbook# glance image-create --name='Ubuntu 12.04 x86_64 server' --disk-format=qcow2 --container-format=bare --public --location http://202.117.xx.xxx:8080/linux/precise-server-cloudimg-amd64-disk1.img
+------------------+--------------------------------------+
| Property         | Value                                |
+------------------+--------------------------------------+
| checksum         | None                                 |
| container_format | bare                                 |
| created_at       | 2015-12-24T11:43:21                  |
| deleted          | False                                |
| deleted_at       | None                                 |
| disk_format      | qcow2                                |
| id               | 7d35d68a-a288-40ad-93e1-5a273f3456f5 |
| is_public        | True                                 |
| min_disk         | 0                                    |
| min_ram          | 0                                    |
| name             | Ubuntu 12.04 x86_64 server           |
| owner            | 526768eb6b704acfbe555f195a4bac75     |
| protected        | False                                |
| size             | 263586304                            |
| status           | active                               |
| updated_at       | 2015-12-24T11:43:21                  |
+------------------+--------------------------------------+

可以使用glance member-create $IMAGE_ID $TENANT_ID與其他租戶共享私有映象。