创建虚拟机我们需要有glance的支持,因为glance是提供镜像的服务。
Glance有两个比较重要的服务:
- Glance-api:接受云系统镜像的构建、删除、读取请求
- Glance-Registry:云系统的镜像注册服务
我们需要配置glance-api的配置文件和glance-registry配置文件 。glance不需要配置消息队列,但是glance需要配置keystone(认证中心)。
提示:默认情况下上传镜像存放在/var/lib/glance/images下
一)在keystone上服务注册
1.1 创建glance服务实体
root@controller ~]# source admin-openrc [root@controller ~]# openstack service create --name glance --description "OpenStack Image" image +-------------+----------------------------------+ | Field | Value | +-------------+----------------------------------+ | description | OpenStack Image | | enabled | True | | id | 1ebbfc83e7f6485eb761be2d7924493b | | name | glance | | type | image | +-------------+----------------------------------+
1.2 创建Compute服务api端点(公有、私有、admin)
[root@controller ~]# openstack endpoint create --region RegionOne > image public http://controller:9292 +--------------+----------------------------------+ | Field | Value | +--------------+----------------------------------+ | enabled | True | | id | 869d2403d3f64d4e9b38014b8d3bf8df | | interface | public | | region | RegionOne | | region_id | RegionOne | | service_id | 1ebbfc83e7f6485eb761be2d7924493b | | service_name | glance | | service_type | image | | url | http://controller:9292 | +--------------+----------------------------------+ [root@controller ~]# openstack endpoint create --region RegionOne > image internal http://controller:9292 +--------------+----------------------------------+ | Field | Value | +--------------+----------------------------------+ | enabled | True | | id | 0f4ac6d92e5f4e18bfbce90b0b2ab604 | | interface | internal | | region | RegionOne | | region_id | RegionOne | | service_id | 1ebbfc83e7f6485eb761be2d7924493b | | service_name | glance | | service_type | image | | url | http://controller:9292 | +--------------+----------------------------------+ [root@controller ~]# openstack endpoint create --region RegionOne > image admin http://controller:9292 +--------------+----------------------------------+ | Field | Value | +--------------+----------------------------------+ | enabled | True | | id | 77075f68191b4cd8aa8fb1c030417458 | | interface | admin | | region | RegionOne | | region_id | RegionOne | | service_id | 1ebbfc83e7f6485eb761be2d7924493b | | service_name | glance | | service_type | image | | url | http://controller:9292 | +--------------+----------------------------------+
二).安装配置glance
2.1安装glance软件包
# yum install openstack-glance -y
2.2 配置glance-api配置文件
vim /etc/glance/glance-api.conf [database] connection = mysql+pymysql://glance:redhat@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 = redhat
# 密码
[glance_store] stores = file,http default_store = file filesystem_store_datadir = /var/lib/glance/images/
3.3 配置glance-registry配置文件
# vim /etc/glance/glance-registry.conf [database] connection = mysql+pymysql://glance:redhat@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 = redhat [paste_deploy] flavor = keystone
3.4 同步数据库
su -s /bin/sh -c "glance-manage db_sync" glance
验证是否成功
# mysql -u glance -predhat -e "use glance;show tables;"
3.5、启动服务并设置开机自启动
systemctl enable openstack-glance-api.service systemctl enable openstack-glance-registry.service systemctl start openstack-glance-api.service systemctl start openstack-glance-registry.service
3.6 、下载测试镜像源
wget http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img
使用 QCOW2 磁盘格式, bare 容器格式上传镜像到镜像服务并设置公共可见,这样所有的项目都可以访问它
# source admin-openrc [root@controller ~]# openstack image create "cirros" > --file /root/cirros-0.3.4-x86_64-disk.img > --disk-format qcow2 --container-format bare > --public +------------------+------------------------------------------------------+ | Field | Value | +------------------+------------------------------------------------------+ | checksum | ee1eca47dc88f4879d8a229cc70a07c6 | | container_format | bare | | created_at | 2018-04-13T07:50:12Z | | disk_format | qcow2 | | file | /v2/images/c952e002-680e-45e1-9337-08d2c3a9abe6/file | | id | c952e002-680e-45e1-9337-08d2c3a9abe6 | | min_disk | 0 | | min_ram | 0 | | name | cirros | | owner | 24a37179b1844e8897e77a0c44cc8d25 | | protected | False | | schema | /v2/schemas/image | | size | 13287936 | | status | active | | tags | | | updated_at | 2018-04-13T07:50:12Z | | virtual_size | None | | visibility | public | +------------------+------------------------------------------------------+
检查是否上传成功
openstack image list [root@controller ~]# glance image-list +--------------------------------------+--------+ | ID | Name | +--------------------------------------+--------+ | c952e002-680e-45e1-9337-08d2c3a9abe6 | cirros | +--------------------------------------+--------+ [root@controller ~]# ls /var/lib/glance/images/ c952e002-680e-45e1-9337-08d2c3a9abe6
备注:镜像存放在/var/lib/glance/images下