1、执行环境变量
. admin-openrc.sh
2、下载镜像
wget http://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-1907.qcow2
//可以替换为国内镜像
wget http://mirrors.nju.edu.cn/centos-cloud/centos/7/images/CentOS-7-x86_64-GenericCloud-1907.qcow2
查询对应版本
3、上传镜像前修改密码
[email protected]:~/image# virt-customize -a CentOS-7-x86_64-GenericCloud-1907.qcow2 --root-password password:123456
[ 0.0] Examining the guest ...
[ 28.3] Setting a random seed
[ 28.3] Setting passwords
[ 29.8] Finishing off
4、执行上传
方法1:上传镜像
glance image-create --name "centos7.7" --file CentOS-7-x86_64-GenericCloud-1907.qcow2 \
--disk-format qcow2 --container-format bare --visibility public --progress
[=============================>] 100%
+------------------+----------------------------------------------------------------------------------+
| Property | Value |
+------------------+----------------------------------------------------------------------------------+
| checksum | 160aa274e7a69f2edb50e2d89f54270b |
| container_format | bare |
| created_at | 2021-01-28T04:57:11Z |
| disk_format | qcow2 |
| id | 19050d6c-f920-483e-8581-bc71eb9387b3 |
| min_disk | 0 |
| min_ram | 0 |
| name | centos7.7 |
| os_hash_algo | sha512 |
| os_hash_value | a1062533d0317b4c0b64cf0fd08cbfa48c6df6fbd513abd1f12b1cd9726fe01113d9221e525fe0c0 |
| | f265f5448849fa07c46a95b687dcf7d51342431f05ede881 |
| os_hidden | False |
| owner | e89bc3f0c7c34deeb36b7b5b8aed0dac |
| protected | False |
| size | 942407680 |
| status | active |
| tags | [] |
| updated_at | 2021-01-28T04:57:16Z |
| virtual_size | Not available |
| visibility | public |
+------------------+----------------------------------------------------------------------------------+
方法二 上传镜像
openstack image create "CentOS7.7-image" \
--file CentOS-7-x86_64-GenericCloud-1907.qcow2 \
--disk-format qcow2 --container-format bare \
--public
5、创建实例
centos官方提供openstack镜像,默认用户是centos
二、下载镜像
# openstack image list
+--------------------------------------+---------------+--------+
| ID | Name | Status |
+--------------------------------------+---------------+--------+
| 6dc3dbbe-080a-4f81-9c39-f5faba41f2b1 | Centos7.7 | active |
| ea920ae1-9dfd-4b5b-83c9-9673535ecb82 | centos7.7_raw | active |
+--------------------------------------+---------------+--------+
#glance image-download --file ./centos7.7.1908.raw ea920ae1-9dfd-4b5b-83c9-9673535ecb82
二、将raw格式镜像转换为vmdk格式镜像
下载的是raw原始虚拟机镜像文件,如果要查看raw文件中的内容可以先把raw文件转换为vmdk文件,然后再用vmware虚拟机打开vmdk文件。
raw文件转化为vmdk文件需要qemu-img命令
# qemu-img convert -f raw centos7.7.1908.raw -O vmdk centos7.7.1908.vmdk
#ls
centos7.7.1908.raw centos7.7.1908.vmdk
支持的格式有:vvfat vpc vmdk vhdx vdi ssh sheepdog rbd raw host_cdrom host_floppy host_device file qed qcow2 qcow parallels nbd iscsi gluster dmg tftp ftps ftp https http cloop bochs blkverify blkdebug