Common operations of openstack mirroring
Download the official mirror
Openstack has a document that lists the downloading methods of virtual machine images of some commonly used operating systems. Most of these images contain cloud-init software packages and support SSH key login (usually password login is not supported). Reference: https://docs.openstack.org/image-guide/obtain-images.html
Change the password of the mirror root user
If you want to set a default root password for virtual machine images such as CentOS, you can refer to the openstack documentation: https://docs.openstack.org/image-guide/modify-images.html
The steps to modify the CentOS virtual machine image and set a default root password are as follows:
# yum install -y libguestfs-tools
# guestfish --rw -a /var/lib/libvirt/images/CentOS-7-x86_64-GenericCloud-1805.qcow2
# 注意: 运行guestfish命令的用户必须和虚拟机镜像文件的属主是同一个,否则接下来的操作会失败。
# guestfish命令运行后示例如下:
Welcome to guestfish, the guest filesystem shell for
editing virtual machine filesystems and disk images.
Type: 'help' for help on commands
'man' to read the manual
'quit' to quit the shell
><fs> run
><fs> list-filesystems
/dev/sda1: xfs
><fs> mount /dev/sda1 /
><fs> vi /etc/shadow # 将root后的两个冒号之间的内容改成新的加密字符串,可以从别的主机上的/etc/shadow文件中复制过来。
><fs> quit
Upload the image to openstack
Use a user to execute a touch admin-openrc
command on the host to create a new admin-openrc file and add the environment variables required to access openstack. Examples of file contents are as follows:
export OS_PROJECT_DOMAIN_NAME=Default
export OS_USER_DOMAIN_NAME=Default
export OS_PROJECT_NAME=admin
export OS_USERNAME=admin
export OS_PASSWORD=adminpassword
export OS_AUTH_URL=http://controller:5000/v3
export OS_IDENTITY_API_VERSION=3
export OS_IMAGE_API_VERSION=2
Then run the following command to upload an image:
$ . admin-openrc
$ glance image-create --name CentOS-7-1805 --file /var/lib/libvirt/images/CentOS-7-x86_64-GenericCloud-1805.qcow2 --disk-format qcow2 --container-format bare --progress
Now this image can be used for the virtual machine example.
Mirror metadata maintenance
Reference: https://docs.openstack.org/image-guide/image-metadata.html
Many people forget to execute glance-manage db_load_metadefs
this command after setting up openstack , resulting in not seeing the metadata list when creating a virtual machine instance .
Make a virtual machine image
Reference: https://docs.openstack.org/image-guide/create-images-manually.html