安装glace
sudo apt-get install glance
安装glance客户端
sudo apt-get install python-glanceclient
创建一个数据库用来存储镜像
vagrant@controller:/$ MYSQL_ROOT_PASSWORD=openstack
vagrant@controller:/$ mysql -uroot -p$MYSQL_ROOT_PASSWORD -e 'create database glance;'
为该数据库创建一个用户
vagrant@controller:/$ MYSQL_GLANCE_PASSWORD=openstack
vagrant@controller:/$ mysql -uroot -p$MYSQL_ROOT_PASSWORD -e "GRANT ALL PRIVILEGES ON glance.* to 'glance'@'%' identified by '${MYSQL_GLANCE_PASSWORD}';"
vagrant@controller:/$ 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服务
vagrant@controller:/$ sudo stop glance-registry
vagrant@controller:/$ sudo start glance-registry
vagrant@controller:/$ sudo stop glance-api
vagrant@controller:/$ 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
vagrant@controller:/$ sudo restart glance-api
vagrant@controller:/$ sudo restart glance-registry
在安装有python-glanceclient
的机器中使用glance来管理镜像
首先配置以下变量
root@paradise:~# export OS_TENANT_NAME=cookbook
root@paradise:~# export OS_USERNAME=admin
root@paradise:~# export OS_PASSWORD=openstack
root@paradise:~# export OS_AUTH_URL=http://172.16.0.200:5000/v2.0
root@paradise:~# export OS_NO_CACHE=1
从下面的地址下载镜像文件
http://uec-images.ubuntu.com/precise/current/precise-server-cloudimg-amd64-disk1.img
https://cloud-images.ubuntu.com/releases/12.04.4/release-20120424/ubuntu-12.04-server-cloudimg-amd64-disk1.img
然后使用glance客户端注册这个镜像
root@paradise:~/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
可以将镜像设为公开,这样其他用户也就可以使用该镜像了。
可以通过下面的命令注册一个远程镜像
root@paradise:~/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
与其他租户共享私有镜像。