云环境下会有很多用户同时创建很多虚拟机,同时还要创建的很快,比如同一时间创建100台虚拟机最多不能超过10分钟,否则顾客体验会很差,所以云环境下需要更高效的解决方案,这就是 Image。Image 是一个模板,里面包含了基本的操作系统和其他的软件,不含有唯一标识的设置,比如MAC地址与IP地址等。对于公有云,每种操作系统都应该至少有一个image模板,而私有云不做限制。但是为了使用方便,当把公有云的image安装了自己需要的软件之后可以拍摄快照,把快照镜像作为自己的私有镜像来使用。
Glance提供 Image Service服务,功能是管理 Image,让用户能够发现、获取和保存 Image。提供 REST API (request应用接口)让用户能够查询和获取 image 的元数据(描述数据的数据)和 image 本身支持多种方式存储 image,包括普通的文件系统、Swift、Amazon S3 等对 Instance 执行 Snapshot 创建新的 image。
#glance image-list 或 #ls -l // 列出所有的镜像
这是一种非结构化的磁盘映像格式
这是VHD磁盘格式,是VMware,Xen,Microsoft,VirtualBox和其他公司的虚拟机监视器使用的一种常见磁盘格式
这是VHDX磁盘格式,它是vhd格式的增强版本,除了其他功能外,还支持更大的磁盘大小。
许多常见的虚拟机监视器支持的另一种常见磁盘格式
VirtualBox虚拟机监视器和QEMU仿真器支持的磁盘格式
光盘(例如CDROM)的数据内容的存档格式。
Virtuozzo支持并用于运行OS容器的磁盘格式
QEMU仿真器支持的一种磁盘格式,可以动态扩展并支持“写时复制”
这表明Glance中存储的是Amazon内核映像
这表明Glance中存储的是Amazon ramdisk映像
这表明Glance中存储的是Amazon机器映像
[root@ct ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 26
Server version: 10.3.20-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> CREATE DATABASE glance;
Query OK, 1 row affected (0.136 sec)
MariaDB [(none)]> grant all privileges on glance.* to 'glance'@'localhost' identified by 'glance_dbpass';
Query OK, 0 rows affected (0.304 sec)
MariaDB [(none)]> grant all privileges on glance.* to 'glance'@'%' identified by 'glance_dbpass';
Query OK, 0 rows affected (0.003 sec)
MariaDB [(none)]> flush privileges
创建用户前,需要首先执行管理员环境变量脚本(此处已经在~/.bashrc 中定义过了)可以参考之前部署**------openstack部署前篇
创建用户glance
[root@ct ~]# openstack user create --domain default --password glance_pass glance
[root@ct ~]# openstack role add --project service --user glance admin /////注册glance的API,需要对service项目有admin权限
[root@ct ~]# openstack service create --name glance --description "OpenStack image" image+-------------+----------------------------------+
| Field | Value |
+-------------+----------------------------------+
| description | OpenStack image |
| enabled | True |
| id | 979b156197614c11b85d337895862498 |
| name | glance ##名称 |
| type | image ##类型 |
+-------------+----------------------------------+
查看
[root@ct ~]# openstack service list
+----------------------------------+----------+----------+
| ID | Name | Type |
+----------------------------------+----------+----------+
| 63f2acafa789462282ee61a531ee3c4b | keystone | identity |
| 979b156197614c11b85d337895862498 | glance | image |
+----------------------------------+----------+----------+
OpenStack使用三种API端点代表三种服务:admin、internal、public
public
[root@ct ~]# openstack endpoint create --region regionone image public http://ct:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | b43d9ca884ff4095b87dd80bd5c42143 |
| interface | public |
| region | regionone |
| region_id | regionone |
| service_id | 979b156197614c11b85d337895862498 |
| service_name | glance |
| service_type | image |
| url | http://ct:9292 |
+--------------+----------------------------------+
admin
[root@ct ~]# openstack endpoint create --region regionone image admin http://ct:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | 1f14f1d58c414cc88349b3505afae38f |
| interface | admin |
| region | regionone |
| region_id | regionone |
| service_id | 979b156197614c11b85d337895862498 |
| service_name | glance |
| service_type | image |
| url | http://ct:9292 |
+--------------+----------------------------------+
internal
[root@ct ~]# openstack endpoint create --region regionone image internal http://ct:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | 2579dfc448454acb908010628f1c6b42 |
| interface | internal |
| region | regionone |
| region_id | regionone |
| service_id | 979b156197614c11b85d337895862498 |
| service_name | glance |
| service_type | image |
| url | http://ct:9292 |
+--------------+----------------------------------+
[root@ct ~]# yum -y install openstack-glance
传入
openstack-config --set /etc/glance/glance-api.conf database connection mysql+pymysql://glance:GLANCE_DBPASS@ct/glance
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken www_authenticate_uri http://ct:5000
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_url http://ct:5000
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken memcached_servers ct:11211
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_type password
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_domain_name Default
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken user_domain_name Default
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_name service
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken username glance
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken password GLANCE_PASS
openstack-config --set /etc/glance/glance-api.conf paste_deploy flavor keystone
openstack-config --set /etc/glance/glance-api.conf glance_store stores file,http
openstack-config --set /etc/glance/glance-api.conf glance_store default_store file
openstack-config --set /etc/glance/glance-api.conf glance_store filesystem_store_datadir /var/lib/glance/images/
列出查看
[root@ct glance]# grep '^[^#]' glance-api.conf
[DEFAULT]
[cinder]
[cors]
[database]
connection = mysql+pymysql://glance:GLANCE_DBPASS@ct/glance
[file]
[glance.store.http.store]
[glance.store.rbd.store]
[glance.store.sheepdog.store]
[glance.store.swift.store]
[glance.store.vmware_datastore.store]
[glance_store]
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/
[image_format]
[keystone_authtoken]
www_authenticate_uri = http://ct:5000
auth_url = http://ct:5000
memcached_servers = ct:11211
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = glance
password = GLANCE_PASS
[oslo_concurrency]
[oslo_messaging_amqp]
[oslo_messaging_kafka]
[oslo_messaging_notifications]
[oslo_messaging_rabbit]
[oslo_middleware]
[oslo_policy]
[paste_deploy]
flavor = keystone
[profiler]
[store_type_location_strategy]
[task]
[taskflow_executor]
文件备份
[root@ct glance]# cp -a /etc/glance/glance-api.conf{
,.bak}
修改/etc/glance/glance-registry.conf
openstack-config --set /etc/glance/glance-registry.conf database connection mysql+pymysql://glance:GLANCE_DBPASS@ct/glance
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken www_authenticate_uri http://ct:5000
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken auth_url http://ct:5000
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken memcached_servers ct:11211
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken auth_type password
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken project_domain_name Default
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken user_domain_name Default
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken project_name service
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken username glance
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken password GLANCE_PASS
openstack-config --set /etc/glance/glance-registry.conf paste_deploy flavor keystone
openstack-config --set /etc/glance/glance-registry.conf glance_store stores file,http
openstack-config --set /etc/glance/glance-registry.conf glance_store default_store file
openstack-config --set /etc/glance/glance-registry.conf glance_store filesystem_store_datadir /var/lib/glance/images/
文件备份
cp -a /etc/glance/glance-registry.conf{
,.bak}
[root@ct glance]# su -s /bin/sh -c "glance-manage db_sync" glance
[root@ct glance]# systemctl enable openstack-glance-api.service
Created symlink from /etc/systemd/system/multi-user.target.wants/openstack-glance-api.service to /usr/lib/systemd/system/openstack-glance-api.service.
[root@ct glance]# systemctl start openstack-glance-api.service
查看端口
[root@ct glance]# netstat -natp | grep 9292
tcp 0 0 0.0.0.0:9292 0.0.0.0:* LISTEN 65234/python2
-h:值对符号连接/软链接的文件修改
[root@ct glance]# chown -hR glance:glance /var/lib/glance/
镜像导入
wget http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img
上传镜像到镜像服务,使用qcow2磁盘格式:
# openstack image create "cirros" \ #创建的镜像的名字为cirros
--file cirros-0.3.5-x86_64-disk.img \ #镜像来自一个文件
--disk-format qcow2 --container-format bare \ #镜像以qcow2磁盘格式上传,类型为一般的类型
--public #镜像是否共享出去
验证镜像是否上传成功
openstack image list 或者 # glance image-list
疑难小结
可能会出现错误
k.img –disk-format qcow2 –container-format bare –public
500 Internal Server Error: The server has either erred or is incapable of performing the requested operation. (HTTP 500)
可能是你之前的配置有错误,唯一的方法就是检查以前的错误。改过之后记住要重新初始化数据库,检查一下数据库中有没有表,比如这样,我检查一下glance中的表
然后重点检查
1./etc/glance/glance-api.conf
2./etc/glance/glance-registry.conf
这两个配置文件。
如果还不对,那就是你的keystone配置的有问题。