镜像服务
镜像服务(glance)是用户能够发现,注册和检索虚拟机的镜像,它提供了一个REST API,使您能够查询虚拟机映像元数据并检索实际映像。可以将通过Image服务提供的虚拟机映像存储在各种位置,从简单文件系统到对象存储系统(如OpenStack对象存储)。镜像默认放在/var/lib/glance/images/。
下面说一下glance服务的安装及配置
1.创建数据库
[root@controller ~]# mysql -uroot -p123456
mysql> CREATE DATABASE glance;
mysql> GRANT ALL PRIVILEGES ON glance.* TO ‘glance‘@‘localhost‘ IDENTIFIED BY ‘GLANCE_DBPASS‘; mysql> GRANT ALL PRIVILEGES ON glance.* TO ‘glance‘@‘%‘ IDENTIFIED BY ‘GLANCE_DBPASS‘;
2.获取admin权限
[root@controller ~]# . admin-openrc
3.创建glance用户
[root@controller ~]# openstack user create --domain default --password-prompt glance User Password:123456 Repeat User Password:123456 +---------------------+----------------------------------+ | Field | Value | +---------------------+----------------------------------+ | domain_id | default | | enabled | True | | id | 09d8b7bbfe9748ffadff25bffc1b46cd | | name | glance | | password_expires_at | None | +---------------------+----------------------------------+
将admin角色添加到glance用户和服务项目中
[root@controller ~]# openstack role add --project service --user glance admin
创建glance服务实例
# openstack service create --name glance --description "OpenStack Image" image
[root@controller ~]# openstack service create --name glance > --description "OpenStack Image" image +-------------+----------------------------------+ | Field | Value | +-------------+----------------------------------+ | description | OpenStack Image | | enabled | True | | id | d6319246d7e3486d86b54634f07c1cb8 | | name | glance | | type | image | +-------------+----------------------------------+
4.创建image服务API端点
# openstack endpoint create --region RegionOne image public http://controller:9292
[root@controller ~]# openstack endpoint create --region RegionOne > image public http://controller:9292 +--------------+----------------------------------+ | Field | Value | +--------------+----------------------------------+ | enabled | True | | id | 621b1c8dabc9472591690d4dadbd4dff | | interface | public | | region | RegionOne | | region_id | RegionOne | | service_id | d6319246d7e3486d86b54634f07c1cb8 | | service_name | glance | | service_type | image | | url | http://controller:9292 | +--------------+----------------------------------+
# openstack endpoint create --region RegionOne image internal http://controller:9292
[root@controller ~]# openstack endpoint create --region RegionOne > image internal http://controller:9292 +--------------+----------------------------------+ | Field | Value | +--------------+----------------------------------+ | enabled | True | | id | f2d4366f844d415e9745c6d7d817d859 | | interface | internal | | region | RegionOne | | region_id | RegionOne | | service_id | d6319246d7e3486d86b54634f07c1cb8 | | service_name | glance | | service_type | image | | url | http://controller:9292 | +--------------+----------------------------------+
# openstack endpoint create --region RegionOne image admin http://controller:9292
[root@controller ~]# openstack endpoint create --region RegionOne > image admin http://controller:9292 +--------------+----------------------------------+ | Field | Value | +--------------+----------------------------------+ | enabled | True | | id | 48114b387628482f9ae11d0cdb29dce2 | | interface | admin | | region | RegionOne | | region_id | RegionOne | | service_id | d6319246d7e3486d86b54634f07c1cb8 | | service_name | glance | | service_type | image | | url | http://controller:9292 | +--------------+----------------------------------+
5.安装服务
[root@controller ~]# yum install openstack-glance -y
6.配置服务
修改/etc/glance/glance-api.conf
[root@controller ~]# cd /etc/glance/ [root@controller glance]# cp glance-api.conf glance-api.conf.bak [root@controller glance]# egrep -v "^#|^$" glance-api.conf.bak > glance-api.conf [root@controller glance]# vim glance-api.conf
[database] ... connection = mysql+pymysql://glance:GLANCE_DBPASS@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 = 123456 [paste_deploy] ... flavor = keystone
[glance_store] ... stores = file,http default_store = file filesystem_store_datadir = /var/lib/glance/images/
修改/etc/glance/glance-registry.conf
[root@controller ~]# cd /etc/glance/ [root@controller glance]# cp glance-registry.conf glance-registry.conf.bak [root@controller glance]# egrep -v "^#|^$" glance-registry.conf.bak glance-registry.conf
[database] ... connection = mysql+pymysql://glance:GLANCE_DBPASS@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 = 123456 [paste_deploy] ... flavor = keystone
7.填充数据库
[root@controller glance]# su -s /bin/sh -c "glance-manage db_sync" glance
8.启动服务
[root@controller glance]# systemctl enable openstack-glance-api.service openstack-glance-registry.service [root@controller glance]# systemctl start openstack-glance-api.service openstack-glance-registry.service
9.验证
下载镜像
[root@controller glance]# wget http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img
导入镜像
# openstack image create "cirros" --file cirros-0.3.4-x86_64-disk.img --disk-format qcow2 --container-format bare --public
[root@controller glance]# openstack image create "cirros" > --file cirros-0.3.4-x86_64-disk.img > --disk-format qcow2 --container-format bare > --public +------------------+------------------------------------------------------+ | Field | Value | +------------------+------------------------------------------------------+ | checksum | ee1eca47dc88f4879d8a229cc70a07c6 | | container_format | bare | | created_at | 2017-01-11T03:10:51Z | | disk_format | qcow2 | | file | /v2/images/2faf5e8a-890d-4c68-a391-a2911342a3af/file | | id | 2faf5e8a-890d-4c68-a391-a2911342a3af | | min_disk | 0 | | min_ram | 0 | | name | cirros | | owner | 3cf031774a844e4c8422cadb9d67785e | | protected | False | | schema | /v2/schemas/image | | size | 13287936 | | status | active | | tags | | | updated_at | 2017-01-11T03:10:52Z | | virtual_size | None | | visibility | public | +------------------+------------------------------------------------------+
[root@controller glance]# openstack image list +--------------------------------------+--------+--------+ | ID | Name | Status | +--------------------------------------+--------+--------+ | 2faf5e8a-890d-4c68-a391-a2911342a3af | cirros | active | +--------------------------------------+--------+--------+ 安装成功 [root@controller ~]# ls /var/lib/glance/images/ 2faf5e8a-890d-4c68-a391-a2911342a3af
本文出自 “linux运维” 博客,请务必保留此出处http://lijiawang.blog.51cto.com/10156897/1891009
原文地址:http://lijiawang.blog.51cto.com/10156897/1891009