Image服务(glance)使用户能够发现,注册和检索虚拟机映像。它提供了一个 REST API,使您可以查询虚拟机图像元数据并检索实际图像。您可以将通过Image服务提供的虚拟机映像存储在各种位置,从简单的文件系统到OpenStack Object Storage等对象存储系统。
1.创建数据库中相关的glance数据,进行授权;
mysql> CREATE DATABASE glance; Query OK, 1 row affected (0.00 sec) mysql> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY '123'; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY '123' -> ; Query OK, 0 rows affected, 1 warning (0.00 sec)
2.创建glance用户,设置密码;(确认为admin用户)
[root@sxb2 ~]# . admin-openrc [root@sxb2 ~]# openstack user create --domain default --password-prompt glance User Password: Repeat User Password: +---------------------+----------------------------------+ | Field | Value | +---------------------+----------------------------------+ | domain_id | default | | enabled | True | | id | 60205d4f43ba4e4f8eaa9921928a880d | | name | glance | | options | {} | | password_expires_at | None | +---------------------+----------------------------------+
3.将glance添加到service项目中,以admin角色管理;
[root@sxb2 ~]# openstack role add --project service --user glance admin
4.创建galnce服务实体;
[root@sxb2 ~]# openstack service create --name glance --description "OpenStack Image" image +-------------+----------------------------------+ | Field | Value | +-------------+----------------------------------+ | description | OpenStack Image | | enabled | True | | id | ab36d61aaad041d8ac7ece6d9fbbf6b1 | | name | glance | | type | image | +-------------+----------------------------------+
5.创建glance服务API端点;
[root@sxb2 ~]# openstack endpoint create --region RegionOne image public http://192.168.88.10 [root@sxb2 ~]# openstack endpoint create --region RegionOne image internal http://192.168.88. [root@sxb2 ~]# openstack endpoint create --region RegionOne image admin http://192.168.88.102
6.安装openstack-glance软件;
yum install openstack-glance
7.配置glance.api配置文件;
[root@sxb2 ~]# vim /etc/glance/glance-api.conf [database] connection = mysql+pymysql://glance:123@controller/glance [keystone_authtoken] www_authenticate_uri = http://192.168.88.102:5000 auth_url = http://192.168.88.102:5000 memcached_servers = 192.168.88.102:11211 auth_type = password project_domain_name = Default user_domain_name = Default project_name = service username = glance password = 123 [paste_deploy] flavor = keystone [glance_store] stores = file,http default_store = file filesystem_store_datadir = /var/lib/glance/images/
8.修改glance-registry.conf文件;
[root@sxb2 ~]# vim /etc/glance/glance-registry.conf [database] connection = mysql+pymysql://glance:123@192.168.88.102/glance [keystone_authtoken] www_authenticate_uri = http://192.168.88.102:5000 auth_url = http://192.168.88.102:5000 memcached_servers = 192.168.88.102:11211 auth_type = password project_domain_name = Default user_domain_name = Default project_name = service username = glance password = 123 [paste_deploy] flavor = keystone
9.对glance数据库进行初始化;
[root@sxb2 ~]# su -s /bin/sh -c "glance-manage db_sync" glance
10.启动Image服务并将其配置为在系统引导时启动;
[root@sxb2 ~]# 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@sxb2 ~]# systemctl start openstack-glance-api.service openstack-glance-registry.service
到这里我们的lmage就配置完成了;接下来我们来测试下
1.我们下载测试文件;(确保以管理员省份运行)
[root@sxb2 ~]# . admin-openrc [root@sxb2 ~]# wget http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img
2.将我们下载好的测试文件,以qcow2的格式上载到;
[root@sxb2 ~]# openstack image create "cirros" --file cirros-0.4.0-x86_64-disk.img --disk-format qcow2 --container-format bare --public +------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Field | Value | +------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | checksum | 443b7623e27ecf03dc9e01ee93f67afe | | container_format | bare | | created_at | 2019-08-11T05:04:13Z | | disk_format | qcow2 | | file | /v2/images/d82b2e52-0f74-4d20-9b61-158c691a1760/file | | id | d82b2e52-0f74-4d20-9b61-158c691a1760 | | min_disk | 0 | | min_ram | 0 | | name | cirros | | owner | 0efc3e774118464eb39800063ad7a64b | | properties | os_hash_algo='sha512', os_hash_value='6513f21e44aa3da349f248188a44bc304a3653a04122d8fb4535423c8e1d14cd6a153f735bb0982e2161b5b5186106570c17a9e58b64dd39390617cd5a350f78', os_hidden='False' | | protected | False | | schema | /v2/schemas/image | | size | 12716032 | | status | active | | tags | | | updated_at | 2019-08-11T05:04:13Z | | virtual_size | None | | visibility | public | +------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2.确认上传图像并验证属性;
[root@sxb2 ~]# openstack image list +--------------------------------------+--------+--------+ | ID | Name | Status | +--------------------------------------+--------+--------+ | d82b2e52-0f74-4d20-9b61-158c691a1760 | cirros | active | +--------------------------------------+--------+--------+ [root@sxb2 ~]# ls /var/lib/glance/images/ d82b2e52-0f74-4d20-9b61-158c691a1760
当我们可以看到这个文件时,glance就算是完成了,下一章我们进行placement配置