OpenStack镜像的构建

目录

  1. 概述
  2. 获取镜像
  3. 手动构建镜像
  4. 构建docker容器
  5. 安装
    1. 依赖环境
    2. DIB
  6. 测试
  7. 高级
    1. Elements
    2. 自定义elements
  8. Trove镜像构建
    1. 下载Trove
    2. 设置变量
      1. 设置变量
      2. 构建镜像
      3. 注册镜像
    3. 出现问题
      1. command not found
      2. apt-update失败
      3. 其他错误

概述

OpenStack镜像的构建有许多种方法,可以直接利用别人构建好的镜像,也可以手动构建,也可以使用镜像构建工具实现镜像构建的自动化,这里主要讲后面两种。

获取镜像

关于如何获取镜像,OpenStack官网上已经说的足够清楚了,这里就不赘述了,可以直接去官网查看。

手动构建镜像

这里以构建centos 7的镜像为例子,我的环境也是centos7。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
yum -y install qemu-kvm libvirt virt-install bridge-utils
modprobe kvm
# make sure modules are loaded
lsmod | grep kvm
systemctl start libvirtd
systemctl enable libvirtd


virt-install \
--name centos7 \
--ram 1024 \
--disk path=/var/kvm/images/centos7.img,size=30 \
--vcpus 1 \
--os-type linux \
--os-variant centos7.0 \
--network bridge=br0 \
--graphics none \
--console pty,target_type=serial \
--location 'https://mirrors.huaweicloud.com/centos/7/os/x86_64/' \
--extra-args 'console=ttyS0,115200n8 serial'

dracut-initqueue[744]: Warning: dracut-initqueue timeout - starting timeout scripts

virt-install \
--name centos7 \
--ram 1024 \
--disk path=/var/kvm/images/centos7.img,format=qcow2\
--vcpus 1 \
--os-type linux \
--os-variant rhel7 \
--network bridge=br0 \
--graphics none \
--console pty,target_type=serial \
--location 'https://mirrors.huaweicloud.com/centos/7/os/x86_64/' \
--extra-args 'console=ttyS0,115200n8 serial'


virt-install \
--name centos7 \
--ram 1024 \
--disk path=/var/kvm/images/centos7.img,size=30 \
--vcpus 1 \
--os-type linux \
--os-variant rhel7 \
--network bridge=br0 \
--graphics none \
--console pty,target_type=serial \
--location 'http://ftp.iij.ad.jp/pub/linux/centos/7/os/x86_64/' \
--extra-args 'console=ttyS0,115200n8 serial'

virt-install \
--name centos7 \
--ram 1024 \
--disk path=/var/kvm/images/centos7.img,format=qcow2 \
--vcpus 1 \
--os-type linux \
--os-variant rhel7 \
--graphics none \
--console pty,target_type=serial \
--location=/var/kvm/images/CentOS-7-x86_64-NetInstall-2009.iso \
--extra-args 'console=ttyS0,115200n8 serial'


virt-install --virt-type kvm --name centos --ram 1024 \
--disk /var/kvm/images/centos.qcow2,format=qcow2 \
--vcpus 1 \
--network network=default \
--graphics vnc,listen=0.0.0.0 --noautoconsole \
--os-type=linux --os-variant=centos7.0 \
--location=/var/kvm/images/CentOS-7-x86_64-NetInstall-2009.iso

diskimage-builder(简称为DIB)是一个用于自动构建自定义的操作系统镜像的工具,以便在云和其他环境中使用。

构建docker容器

利用docker容器来搭建镜像的环境,这里选择centos镜像,同时将本地目录和容器内的文件目录做一个映射。

1
docker run -itd --privileged=true --name centos -v $PWD:/root centos:7 /sbin/init

安装

依赖环境

进入容器内安装DIB的依赖环境。

1
2
3
4
5
docker exec -it centos bash
yum update
yum install -y epel-release
yum install -y python3 git sudo # DIB需要Python3支持
pip3 install -U pip setuptools wheel

安装qemu-img和kpartx。

1
2
apt-get install qemu-utils kpartx squashfs-tools e4fsprogs # ubuntu
yum install -y qemu-img kpartx squashfs-tools e4fsprogs # centos

DIB

从github将DIB下载下来。

1
git clone https://github.com/openstack/diskimage-builder.git

切换到最近的tag上,我这里是3.7.0。

1
2
cd diskimge-builder
git checkout -b v3.7.0 3.7.0

设置虚环境

1
2
pip install virtualenv
mkdir venv && cd venv && virtualenv -p /usr/bin/python3 diskimage-builder

安装diskimage-builder。

1
cd /root/diskimage-builder && /root/venv/diskimage-builder/bin/pip install -e .

测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

[root@centos-linux ~]# disk-image-create -h
Usage: disk-image-create [OPTION]... [ELEMENT]...

Options:
-a i386|amd64|armhf|arm64 -- set the architecture of the image(default amd64)
-o imagename -- set the imagename of the output image file(default image)
-t qcow2,tar,tgz,squashfs,vhd,docker,aci,raw -- set the image types of the output image files (default qcow2)
File types should be comma separated. VHD outputting requires the vhd-util
executable be in your PATH. ACI outputting requires the ACI_MANIFEST
environment variable be a path to a manifest file.
-x -- turn on tracing (use -x -x for very detailed tracing).
-u -- uncompressed; do not compress the image - larger but faster
-c -- clear environment before starting work
--logfile -- save run output to given logfile (implies DIB_QUIET=1)
--checksum -- generate MD5 and SHA256 checksum files for the created image
--image-size size -- image size in GB for the created image
--image-extra-size size -- extra image size in GB for the created image
--image-cache directory -- location for cached images(default ~/.cache/image-create)
--max-online-resize size -- max number of filesystem blocks to support when resizing.
Useful if you want a really large root partition when the image is deployed.
Using a very large value may run into a known bug in resize2fs.
Setting the value to 274877906944 will get you a 1PB root file system.
Making this value unnecessarily large will consume extra disk space
on the root partition with extra file system inodes.
--min-tmpfs size -- minimum size in GB needed in tmpfs to build the image
--mkfs-journal-size -- filesystem journal size in MB to pass to mkfs.
--mkfs-options -- option flags to be passed directly to mkfs.
Options should be passed as a single string value.
--no-tmpfs -- do not use tmpfs to speed image build
--offline -- do not update cached resources
--qemu-img-options -- option flags to be passed directly to qemu-img.
Options need to be comma separated, and follow the key=value pattern.
--root-label label -- label for the root filesystem. Defaults to 'cloudimg-rootfs'.
--ramdisk-element -- specify the main element to be used for building ramdisks.
Defaults to 'ramdisk'. Should be set to 'dracut-ramdisk' for platforms such
as RHEL and CentOS that do not package busybox.
--install-type -- specify the default installation type. Defaults to 'source'. Set to 'package' to use package based installations by default.
--docker-target -- specify the repo and tag to use if the output type is docker. Defaults to the value of output imagename
-n skip the default inclusion of the 'base' element
-p package[,p2...] [-p p3] -- extra packages to install in the image. Runs once, after 'install.d' phase. Can be specified multiple times
-h|--help -- display this help and exit
--version -- display version and exit

Environment Variables:
(this is not a complete list)

* ELEMENTS_PATH: specify external locations for the elements. As for $PATH
* DIB_NO_TIMESTAMP: no timestamp prefix on output. Useful if capturing output
* DIB_QUIET: 1=do not output log output to stdout; 0=always ouptut to stdout. See --logfile

NOTE: At least one distribution root element must be specified.

NOTE: If using the VHD output format you need to have a patched version of vhd-util installed for the image
to be bootable. The patch is available here: https://github.com/emonty/vhd-util/blob/master/debian/patches/citrix
and a PPA with the patched tool is available here: https://launchpad.net/~openstack-ci-core/+archive/ubuntu/vhd-util

Examples:
disk-image-create -a amd64 -o ubuntu-amd64 vm ubuntu
export ELEMENTS_PATH=~/source/tripleo-image-elements/elements
disk-image-create -a amd64 -o fedora-amd64-heat-cfntools vm fedora heat-cfntools

创建ubuntu镜像。

1
/root/venv/diskimage-builder/bin/disk-image-create -a amd64 -o ubuntu-amd64 vm ubuntu

高级

Elements

DIB中的elements

DIB中有大量的元件。DIB的元件在diskimage-builder项目中的/diskimage_builder/elements的目录下。

自定义elements

可以自行编写elements来满足构建镜像的要求。

1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/bash

set -e
set -o xtrace

source $_LIB/die

[ -n "$TMP_HOOKS_PATH" ] || die "Temp hook path not set"
[ -n "$HOST_USERNAME" ] || die "HOST_USERNAME not set"

cp -r ${PATH_TROVE} ${TMP_HOOKS_PATH}/
REQUIREMENTS_FILE=${TROVESTACK_SCRIPTS}/files/requirements/centos-requirements.txt
sudo -Hiu ${HOST_USERNAME} dd if=${REQUIREMENTS_FILE} of=${TMP_HOOKS_PATH}/requirements.txt
  1. Trove中的elements

除了DIB提供的元件,Trove也提供自己所支持的数据库的元件。可以在trove项目下的integration/scripts/files/elements中找到trove的相关元件。

Trove镜像构建

下载Trove

从github上将trove项目下载到本地,位置和DIB存放的一致,都在/root下。

1
git clone https://git.openstack.org/openstack/trove.git

设置变量

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/sh

export DIB_DISTRIBUTION_MIRROR=http://mirrors.huaweicloud.com/centos
export DIB_CLOUD_IMAGES=http://mirrors.nju.edu.cn/centos-cloud/centos/7/images

export DIB_RELEASE=7
export DIB_YUM_REPO_CONF=/home/wkt/projects/CentOS-Base.repo
export DIB_EPEL_MIRROR=https://mirrors.huaweicloud.com/epel/

export HOST_USERNAME=root
export TMP_HOOKS_PATH=
export HOST_SCP_USERNAME
export GUEST_USERNAME
export CONTROLLER_IP
export TROVESTACK_SCRIPTS=/home/wkt/projects/boncloud-trove/integration/scripts
export SERVICE_TYPE=redis
export PATH_TROVE=/home/wkt/projects/boncloud-trove
export ESCAPED_PATH_TROVE
export SSH_DIR
export GUEST_LOGDIR
export ESCAPED_GUEST_LOGDIR
export DATASTORE_PKG_LOCATION
export BRANCH_OVERRIDE
export DIB_CLOUD_INIT_DATASOURCES="ConfigDrive, OpenStack"
export PATH_DISKIMAGEBUILDER=/home/wkt/projects/diskimage-builder/diskimage_builder
export PATH_TRIPLEO_ELEMENTS=/home/wkt/projects/tripleo-image-elements

export ELEMENTS_PATH=$TROVESTACK_SCRIPTS/files/elements
export ELEMENTS_PATH+=:$PATH_DISKIMAGEBUILDER/elements
export ELEMENTS_PATH+=:$PATH_TRIPLEO_ELEMENTS/elements
export DIB_APT_CONF_DIR=/etc/apt/apt.conf.d
export DIB_CLOUD_INIT_ETC_HOSTS=true

export DIB_DEV_USER_USERNAME=
export DIB_DEV_USER_PASSWORD=
export DIB_DEV_USER_PWDLESS_SUDO
export DIB_CLOUD_INIT_ALLOW_SSH_PWAUTH=true

export DIB_ROOT_PASSWORD=199412
QEMU_IMG_OPTIONS="--qemu-img-options compat=1.1"
VM=centos-amd64-redis-5-0-10
DISTRO=centos
SERVICE_TYPE=redis

source /root/venv/diskimage-builder/bin/activate

disk-image-create -a amd64 -o "${VM}" -x ${QEMU_IMG_OPTIONS} ${DISTRO} base vm \
cloud-init cloud-init-datasources epel ${DISTRO}-guest ${DISTRO}-${SERVICE_TYPE}

设置变量

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/sh
export HOST_USERNAME=root
export HOST_SCP_USERNAME=root
export GUEST_USERNAME=root
export CONTROLLER_IP=10.0.0.1
export TROVESTACK_SCRIPTS=/opt/stack/trove/integration/scripts
export PATH_TROVE=/opt/stack/trove
export ESCAPED_PATH_TROVE='\/opt\/stack\/trove'
export SSH_DIR=~/.ssh/
export GUEST_LOGDIR=/var/log/trove/
export ESCAPED_GUEST_LOGDIR='\/var\/log\/trove\/'
export DIB_CLOUD_INIT_DATASOURCES="ConfigDrive"
export DATASTORE_PKG_LOCATION=""

export RELEASE=xenial

export PATH_DISKIMAGEBUILDER=/opt/stack/diskimage-builder/diskimage_builder
export ELEMENTS_PATH=$TROVESTACK_SCRIPTS/files/elements
export ELEMENTS_PATH+=:$PATH_DISKIMAGEBUILDER/elements
export DIB_APT_CONF_DIR=/etc/apt/apt.conf.d
export DIB_CLOUD_INIT_ETC_HOSTS=true
  • 说明
  1. HOST_USERNAME

HOST_USERNAME is the name of the user on the Trove host machine. It is used to identify the location of the authorized_keys, id_rsa, and id_rsa_pub files that are to be in guest image creation.

  1. HOST_SCP_USERNAME

HOST_SCP_USERNAME is the name of the user on the Trove host machine used to connect from the guest while copying the guest agent code during the upstart process.

  1. GUEST_USERNAME

GUEST_USERNAME is the name of the user on the Trove guest who will run the guest agent and perform a number of other jobs. This user is created during the image build process if it does not exist.

  1. CONTROLLER_IP

CONTROLLER_IP

  1. TROVESTACK_SCRIPTS

TROVESTACK_SCRIPTS is the pointer to files in the trove project.

  1. SERVICE_TYPE

SERVICE_TYPE

  1. PATH_TROVE

PATH_TROVE is the path to the Trove source code and this is used in the rsync of code to the guest.

  1. ESCAPED_PATH_TROVE

ESCAPED_PATH_TROVE is the escaped version of PATH_TROVE and is used for much the same purpose as PATH_TROVE.

  1. SSH_DIR

SSH_DIR is a path to the .ssh directory for the user on the host and is used in the image creation process to obtain the authorized_keys, id_rsa and id_rsa_pub files.

  1. GUEST_LOGDIR

GUEST_LOGDIR is the location on the guest where the Trove log file is to be stored.

  1. ESCAPED_GUEST_LOGDIR

ESCAPED_GUEST_LOGDIR is the escaped version of GUEST_LOGDIR.

  1. DIB_CLOUD_INIT_DATASOURCES

DIB_CLOUD_INIT_DATASOURCES . The DIB element cloud-init-datasources uses this value to determine the data sources that must be queried during first boot to obtain instance metadata.

  1. DATASTORE_PKG_LOCATION

DATASTORE_PKG_LOCATION is not used in the creation of the Mysql instance but is used by some databases (currently DB2 and Vertica) to identify the location of a downloaded package containing the database. Other databases merely obtain this using apt-get or appropriate package management command. This variable is used for databases that do not allow this, and for example, require the user to click on a license agreement in order to obtain the database software.

  1. BRANCH_OVERRIDE

BRANCH_OVERRIDE

  1. RELEASE

RELEASE是我自己后加入的,不加的话会有报错,后面会提到。

构建镜像

构建镜像使用的命令是disk-image-create。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
(diskimage-builder) wkt@controller-1:~$ disk-image-create --help
Usage: disk-image-create [OPTION]... [ELEMENT]...

Options:
-a i386|amd64|armhf|arm64 -- set the architecture of the image(default amd64)
-o imagename -- set the imagename of the output image file(default image)
-t qcow2,tar,tgz,squashfs,vhd,docker,aci,raw -- set the image types of the output image files (default qcow2)
File types should be comma separated. VHD outputting requires the vhd-util
executable be in your PATH. ACI outputting requires the ACI_MANIFEST
environment variable be a path to a manifest file.
-x -- turn on tracing (use -x -x for very detailed tracing).
-u -- uncompressed; do not compress the image - larger but faster
-c -- clear environment before starting work
--logfile -- save run output to given logfile
--checksum -- generate MD5 and SHA256 checksum files for the created image
--image-size size -- image size in GB for the created image
--image-cache directory -- location for cached images(default ~/.cache/image-create)
--max-online-resize size -- max number of filesystem blocks to support when resizing.
Useful if you want a really large root partition when the image is deployed.
Using a very large value may run into a known bug in resize2fs.
Setting the value to 274877906944 will get you a 1PB root file system.
Making this value unnecessarily large will consume extra disk space
on the root partition with extra file system inodes.
--min-tmpfs size -- minimum size in GB needed in tmpfs to build the image
--mkfs-options -- option flags to be passed directly to mkfs.
Options should be passed as a single string value.
--no-tmpfs -- do not use tmpfs to speed image build
--offline -- do not update cached resources
--qemu-img-options -- option flags to be passed directly to qemu-img.
Options need to be comma separated, and follow the key=value pattern.
--root-label label -- label for the root filesystem. Defaults to 'cloudimg-rootfs'.
--ramdisk-element -- specify the main element to be used for building ramdisks.
Defaults to 'ramdisk'. Should be set to 'dracut-ramdisk' for platforms such
as RHEL and CentOS that do not package busybox.
--install-type -- specify the default installation type. Defaults to 'source'. Set to 'package' to use package based installations by default.
--docker-target -- specify the repo and tag to use if the output type is docker. Defaults to the value of output imagename
-n skip the default inclusion of the 'base' element
-p package[,p2...] [-p p3] -- extra packages to install in the image. Runs once, after 'install.d' phase. Can be specified mulitple times
-h|--help -- display this help and exit
--version -- display version and exit

Environment Variables:
(this is not a complete list)

* ELEMENTS_PATH: specify external locations for the elements. As for $PATH
* DIB_NO_TIMESTAMP: no timestamp prefix on output. Useful if capturing output
* DIB_QUIET: do not output log output to stdout. See --logfile

NOTE: At least one distribution root element must be specified.

NOTE: If using the VHD output format you need to have a patched version of vhd-util installed for the image
to be bootable. The patch is available here: https://github.com/emonty/vhd-util/blob/master/debian/patches/citrix
and a PPA with the patched tool is available here: https://launchpad.net/~openstack-ci-core/+archive/ubuntu/vhd-util

Examples:
disk-image-create -a amd64 -o ubuntu-amd64 vm ubuntu
export ELEMENTS_PATH=~/source/tripleo-image-elements/elements
disk-image-create -a amd64 -o fedora-amd64-heat-cfntools vm fedora heat-cfntools

一旦设置好前面的变量可以用下面的命令创建Mysql数据库的Trove Guest镜像。

1
disk-image-create -a amd64 -o ubuntu-xenial-mysql -x --qemu-img-options compat=1.1 ubuntu vm cloud-init-datasources ubuntu-guest ubuntu-xenial-guest ubuntu-mysql ubuntu-xenial-mysql

这会默认生成qcow2格式的镜像,并储存在当前路径下。

出错的话,可以查看出现问题

注册镜像

构建了镜像就需要在Glance和Trove中注册。首先,在Glance注册一个Guest镜像。获得镜像的id

1
openstack image create ubuntu-xenial-mysql --file ubuntu-xenial-mysql.qcow2 --disk-format qcow2 --container-format bare --public --property image_type=distribution --property image_label=Test --property expected_size=10 --property hw_qemu_guest_agent='yes’

进入到trove-api的Docker中。

1
2
root@controller-1:~# docker ps | grep trove
root@controller-1:~# docker exec -it trove_api bash

docker-ps

注册新的数据库类型

1
trove-manage --config-file=/etc/trove/trove.conf datastore_update mysql ''

已经存在数据库类型可跳过此步。

更新mysql数据库的版本信息

1
trove-manage --config-file=/etc/trove/trove.conf datastore_version_update mysql <版本> mysql <镜像id> '' 1
  1. 第一个参数
    指的是数据库的类型

  2. 第二个参数
    指的是数据库的版本号

  3. 第三个参数
    指的是数据库管理类的名字,可以根据类名关联到Trove guest agent内的特定数据库类型。对Mysql而言,其对应的管理类就是trove.guestagent.datastore.mysql.manager.Manager。Trove支持的每一个数据库都有相应的Manage类,其类名可以在各种Trove配置文件中通过参数进行配置。

  4. 第四个参数
    指的是镜像的id。此id是之前的openstack image create命令输出中提供的。

  5. 第五个参数
    是传递到guest agent的prepare()信息中的安装包名称列表,通常用于guest agent安装最新的软件包或更新软件包到最新版本。这里为空。

  6. 第六个参数
    将数据库版本标记为活跃。

可以通过执行trove-manage datastore_version_update -h命令获取所有的帮助信息。

出现问题

command not found

  • 执行代码
    1
    disk-image-create -a amd64 -o ubuntu-xenial-mysql -x --qemu-img-options compat=1.1 ubuntu vm cloud-init-datasources ubuntu-guest ubuntu-xenial-guest ubuntu-mysql ubuntu-xenial-mysql
  • 出错日志
    1
    2
    2018-09-11 02:34:15.980 | + die 'RELEASE must be set to a valid Ubuntu release (e.g. trusty)'
    2018-09-11 02:34:15.999 | /tmp/in_target.d/pre-install.d/10-percona-apt-key: line 10: die: command not found
    在/opt/stack/trove/integration/scripts/files/elements/ubuntu-mysql/pre-install.d找到10-percona-apt-key文件出错代码
    1
    10 [ -n "${RELEASE}" ] || die "RELEASE must be set to a valid Ubuntu release (e.g. trusty)"
  • 解决问题
    在设置变量时添加RELEASE=xenial

apt-update失败

  • 执行代码

    1
    disk-image-create -a amd64 -o ubuntu-xenial-mysql -x --qemu-img-options compat=1.1 ubuntu vm cloud-init-datasources ubuntu-guest ubuntu-xenial-guest ubuntu-mysql ubuntu-xenial-mysql
  • 出错日志

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    2018-09-11 02:40:15.989 | dib-run-parts Running /tmp/in_target.d/pre-install.d/10-percona-apt-key
    2018-09-11 02:40:15.996 | + '[' -n root ']'
    2018-09-11 02:40:15.997 | + '[' -n xenial ']'
    2018-09-11 02:40:15.997 | + mkdir -p /home/root/.gnupg
    2018-09-11 02:40:15.998 | + get_key_robust 1C4CBDCDCD2EFD2A
    2018-09-11 02:40:15.998 | + KEY=1C4CBDCDCD2EFD2A
    2018-09-11 02:40:15.998 | + set +e
    2018-09-11 02:40:15.998 | + apt-key adv --keyserver hkp://keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A
    2018-09-11 02:40:16.121 | Executing: /tmp/tmp.qhaS3an1yi/gpg.1.sh --keyserver
    2018-09-11 02:40:16.121 | hkp://keys.gnupg.net
    2018-09-11 02:40:16.121 | --recv-keys
    2018-09-11 02:40:16.121 | 1C4CBDCDCD2EFD2A
    2018-09-11 02:40:16.127 | gpg: requesting key CD2EFD2A from hkp server keys.gnupg.net
    2018-09-11 02:40:20.249 | gpg: key CD2EFD2A: public key "Percona MySQL Development Team <mysql-dev@percona.com>" imported
    2018-09-11 02:40:20.249 | gpg: Total number processed: 1
    2018-09-11 02:40:20.249 | gpg: imported: 1
    2018-09-11 02:40:20.375 | + '[' 0 -ne 0 ']'
    2018-09-11 02:40:20.375 | + set -e
    2018-09-11 02:40:20.375 | + get_key_robust 9334A25F8507EFA5
    2018-09-11 02:40:20.375 | + KEY=9334A25F8507EFA5
    2018-09-11 02:40:20.375 | + set +e
    2018-09-11 02:40:20.375 | + apt-key adv --keyserver hkp://keys.gnupg.net --recv-keys 9334A25F8507EFA5
    2018-09-11 02:40:20.469 | Executing: /tmp/tmp.NgGbibfTaA/gpg.1.sh --keyserver
    2018-09-11 02:40:20.469 | hkp://keys.gnupg.net
    2018-09-11 02:40:20.469 | --recv-keys
    2018-09-11 02:40:20.469 | 9334A25F8507EFA5
    2018-09-11 02:40:20.472 | gpg: requesting key 8507EFA5 from hkp server keys.gnupg.net
    2018-09-11 02:40:21.076 | gpg: key 8507EFA5: public key "Percona MySQL Development Team (Packaging key) <mysql-dev@percona.com>" imported
    2018-09-11 02:40:21.076 | gpg: Total number processed: 1
    2018-09-11 02:40:21.076 | gpg: imported: 1 (RSA: 1)
    2018-09-11 02:40:21.191 | + '[' 0 -ne 0 ']'
    2018-09-11 02:40:21.191 | + set -e
    2018-09-11 02:40:21.191 | + cat
    2018-09-11 02:40:21.192 | + apt-get update
    2018-09-11 02:40:21.712 | Hit:1 http://security.ubuntu.com/ubuntu xenial-security InRelease
    2018-09-11 02:40:22.429 | Hit:2 http://archive.ubuntu.com/ubuntu xenial InRelease
    2018-09-11 02:40:22.700 | Hit:3 http://archive.ubuntu.com/ubuntu xenial-updates InRelease
    2018-09-11 02:40:22.733 | Get:4 http://repo.percona.com/apt xenial InRelease [16.0 kB]
    2018-09-11 02:40:22.968 | Hit:5 http://archive.ubuntu.com/ubuntu xenial-backports InRelease
    2018-09-11 02:40:23.683 | Get:6 http://203.187.160.133:9011/repo.percona.com/c3pr90ntc0td/apt xenial/main Sources [6942 B]
    2018-09-11 02:40:23.684 | Ign:6 http://203.187.160.133:9011/repo.percona.com/c3pr90ntc0td/apt xenial/main Sources
    2018-09-11 02:40:24.022 | Get:7 http://203.187.160.132:9011/repo.percona.com/c3pr90ntc0td/apt xenial/main amd64 Packages [21.1 kB]
    2018-09-11 02:40:24.023 | Ign:7 http://203.187.160.132:9011/repo.percona.com/c3pr90ntc0td/apt xenial/main amd64 Packages
    2018-09-11 02:40:24.189 | Err:6 http://203.187.160.133:9011/repo.percona.com/c3pr90ntc0td/apt xenial/main Sources
    2018-09-11 02:40:24.189 | Writing more data than expected (8870 > 6942)
    2018-09-11 02:40:24.452 | Get:7 http://203.187.160.132:9011/repo.percona.com/c3pr90ntc0td/apt xenial/main amd64 Packages [115 kB]
    2018-09-11 02:40:25.250 | Fetched 131 kB in 4s (32.5 kB/s)
    2018-09-11 02:40:26.762 | Reading package lists...
    2018-09-11 02:40:26.797 | E: Failed to fetch http://repo.percona.com/apt/dists/xenial/main/source/Sources Writing more data than expected (8870 > 6942)
    2018-09-11 02:40:26.797 | E: Some index files failed to download. They have been ignored, or old ones used instead.
  • 解决问题
    将trove/integration/scripts/files/elements/ubuntu-mysql/pre-install.d/10-percona-apt-key中的

    1
    2
    3
    4
    5
    6
    7
    8
    9
    get_key_robust 1C4CBDCDCD2EFD2A
    get_key_robust 9334A25F8507EFA5

    # Add Percona repo
    # Creates the percona sources list
    cat <<EOL > /etc/apt/sources.list.d/percona.list
    deb http://repo.percona.com/apt $RELEASE main
    deb-src http://repo.percona.com/apt $RELEASE main
    EOL

    改为

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    get_key_robust 1C4CBDCDCD2EFD2A
    get_key_robust 9334A25F8507EFA5

    apt-get install -y apt-transport-https

    # Add Percona repo
    # Creates the percona sources list
    cat <<EOL > /etc/apt/sources.list.d/percona.list
    deb https://repo.percona.com/apt $RELEASE main
    deb-src https://repo.percona.com/apt $RELEASE main
    EOL

其他错误

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Device or resource busy
Inappropriate ioctl for device
2020-12-28 07:33:21.807 | SyntaxError: invalid syntax
2020-12-28 07:33:21.835 | *** /tmp/dib_build.PoO5ok68/mnt is not a directory
```bash

### 其他
#### 官网安装教程
[官网安装教程](https://docs.openstack.org/trove/pike/admin/building_guest_images.html)

#### 代码
``` bash
disk-image-create -a amd64 -o ubuntu-xenial-redis -x --qemu-img-options compat=1.1 ubuntu vm cloud-init-datasources ubuntu-xenial-guest ubuntu-xenial-redis

disk-image-create -a amd64 -o ubuntu-xenial-mysql -x --qemu-img-options compat=1.1 ubuntu vm cloud-init-datasources ubuntu-guest ubuntu-xenial-guest ubuntu-mysql ubuntu-xenial-mysql

openstack image create ubuntu-xenial-mysql --file ubuntu-xenial-mysql.qcow2 --disk-format qcow2 --container-format bare --public --property image_type=distribution --property image_label=Test --property expected_size=10 --property hw_qemu_guest_agent=yes

openstack image create ubuntu-xenial-mysql --file ubuntu-xenial-mysql.qcow2 --disk-format qcow2 --container-format bare --public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash

set -x
set -e

source /root/xieyy-openrc.sh

openstack image delete redis5

openstack image create \
--file /home/wkt/centos-amd64-redis-5-0-10.qcow2 \
--disk-format qcow2 redis5 \
--property hw_qemu_guest_agent='yes' \
--property hw_disk_bus='scsi' \
--property hw_scsi_model='virtio-scsi' \
--property os_require_quiesce='yes'

image_id=$(openstack image show redis5 -c id | grep id | awk -F '|' '{print $3}' | sed s/[[:space:]]//g)

docker exec trove_taskmanager trove-manage --config-file=/etc/trove/trove-taskmanager.conf \
datastore_version_update redis 5.0.10 redis ${image_id} "" 1

openstack volume delete Redis_base

openstack volume create --image ${image_id} --property 'base_clone'='True' --type ceph --size 50 Redis_base
openstack volume show Redis_base

base_volume_id=$(openstack volume show -c id Redis_base | grep id | awk -F '|' '{print $3}' | sed s/[[:space:]]//g)
url=$(openstack image show -f json ${image_id} | grep url | awk -F '"' '{print $4}')

metadata=$(printf '{"base_volume": "%s"}' ${base_volume_id})

glance location-update --url ${url} --metadata "${metadata}" ${image_id}

1 + 2 + 1 = 4

docker run -itd –name trove_monitor
-v /project/boncloud-trove/:/root/trove:rw
-v /etc/kolla/trove-monitor:/etc/trove/:rw
172.16.58.14:4000/bonc/centos-source-trove-api:7.0.1
bash