开始前必读
自动化镜像构建需要对Linux系统和shell、python有一定了解,具备一定的shell、python编程能力。
搭建编译构建环境
安装virtualbox
软件版本:7.1.2
- 安装VirtualBox Platform Packages
- 安装VirtualBox Extension Pack
准备虚拟机
新建openstack-builder
操作系统:Debian12.6,内核:6.1.0-23-amd64
- 规格信息如下
hostname vCPU memory disk net openstack-builder 2C 2G 256G nat - 开启EFI支持,采用uefi的方式安装Debian,分区信息如下
格式 大小 挂载点 efi 256M /boot/efi xfs ALL /
安装virtualbox additions
-
使用如下命令更新apt缓存
apt update && apt upgrade -y
-
安装依赖包
apt install -y build-essential gcc make dkms linux-headers-`uname -r`
-
将
C:\Program Files\Oracle\VirtualBox\VBoxGuestAdditions.iso
挂载到虚拟机mount /dev/cdrom /mnt
-
执行安装命令
bash /mnt/VBoxLinuxAdditions.run
基础配置
关闭防火墙
-
使用如下命令关闭防火墙,并禁止防火墙开机启动(debian为ufw,fedora为firewalld)
systemctl stop ufw && systemctl disable ufw
显示如下信息,说明防火墙服务ufw不存在
Failed to stop ufw.service: Unit ufw.service not loaded.
-
检查防火墙状态,状态如下所示则表示修改成功
systemctl status ufw
修改源
-
使用如下命令在
/etc/apt/
创建bak
目录mkdir -p /etc/apt/bak/
-
备份原配置,使用如下命令备份原配置
mv /etc/apt/sources.list /etc/apt/bak/
-
添加中科大源配置文件,使用
vi
打开/etc/apt/sources.list
,添加如下内容:#deb cdrom:[Debian GNU/Linux 12.6.0 _Bookworm_ - Official amd64 DVD Binary-1 with firmware 20240629-10:19]/ bookworm contrib main non-free-firmware deb http://mirrors.ustc.edu.cn/debian/ bookworm main non-free-firmware deb-src http://mirrors.ustc.edu.cn/debian/ bookworm main non-free-firmware deb http://security.debian.org/debian-security bookworm-security main non-free-firmware deb-src http://mirrors.ustc.edu.cn/debian-security bookworm-security main non-free-firmware # bookworm-updates, to get updates before a point release is made; # see https://www.debian.org/doc/manuals/debian-reference/ch02.en.html#_updates_and_backports deb http://mirrors.ustc.edu.cn/debian/ bookworm-updates main non-free-firmware deb-src http://mirrors.ustc.edu.cn/debian/ bookworm-updates main non-free-firmware
-
使用如下命令更新apt缓存
apt update && apt upgrade -y
软件安装
基础软件
-
安装vim、python3、python3-venv、lsof、net-tools、git、gcc、make等软件
apt install -y vim python3 python3-pip python3-dev python3-venv libffi-dev openssl libssl-dev lsof net-tools git gcc make zip unzip
-
安装virt-manager、libvirt、libguestfs-tools、jq等软件
apt install -y virt-manager libvirt-dev libguestfs-tools jq neofetch
-
修改pip仓库地址,使用
vim
打开~/.pip/pip.conf
,添加如下内容:[global] index-url = http://mirrors.aliyun.com/pypi/simple/ [install] trusted-host=mirrors.aliyun.com timeout=90
docker
-
卸载旧版本
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done
-
安装必要的一些系统工具
apt-get update && apt install -y ca-certificates curl
-
安装GPG证书
install -m 0755 -d /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc chmod a+r /etc/apt/keyrings/docker.asc
-
写入软件源信息
echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \ $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ tee /etc/apt/sources.list.d/docker.list > /dev/null && apt-get update
-
通过apt安装docker-ce
apt-get update && apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
-
配置国内docker源代理
自行寻找配置国内镜像加速源
-
重启docker,并设置开机启动
systemctl daemon-reload systemctl enable docker && systemctl restart docker
docker仓库
- 通过如下命令创建本地docker仓库
docker run -d \ --network host \ --name registry \ --restart=always \ -e REGISTRY_HTTP_ADDR=0.0.0.0:4000 \ -v registry:/var/lib/registry \ registry
kolla
Welcome to Kolla’s documentation! — kolla 18.1.0.dev65 documentation (openstack.org)
准备python虚拟环境
-
准备python虚拟环境
mkdir -p /opt/kolla/pyenv/ python3 -m venv /opt/kolla/pyenv/
-
激活python虚拟环境
tips:info 以后每次使用kolla-build,都要使用如下命令激活kolla的python虚拟环境cd /opt/kolla/ && source /opt/kolla/pyenv/bin/activate
-
升级pip
pip3 install -U pip
安装kolla
通过pip安装
-
安装docker的python库
pip3 install docker
-
安装kolla的python库
pip3 install kolla
从源代码安装(推荐)
-
安装docker的python库
pip3 install docker
-
使用pip从git代码仓安装
pip3 install git+https://opendev.org/openstack/kolla.git
-
检查安装结果
kolla-build --version
-
使用pip从git代码仓升级
pip3 install -U git+https://opendev.org/openstack/kolla.git
构建openstack组件docker镜像
使用kolla-build构建
-
激活python虚拟环境
cd /opt/kolla/ && source /opt/kolla/pyenv/bin/activate
-
构建openstack镜像,基于debian系统
kolla-build -b debian --base-arch x86_64 --debian-arch amd64 --skip-existing --timeout 10 -T 5 --registry 127.0.0.1:4000
清理docker镜像
- 使用docker命令清理无用镜像
docker images | grep none | awk '{print $3}'|xargs docker rmi