kyyee
发布于 2024-09-25 / 166 阅读
0

kolla构建openstack镜像

开始前必读

自动化镜像构建需要对Linux系统和shell、python有一定了解,具备一定的shell、python编程能力。

搭建编译构建环境

tips:info 通过虚拟机构建openstack组件镜像

安装virtualbox

tips:info 备选: VMWare virt-manager

Downloads – Oracle VirtualBox

软件版本:7.1.2

tips:info 详细安装步骤略
  1. 安装VirtualBox Platform Packages
  2. 安装VirtualBox Extension Pack

准备虚拟机

下载 Debian

新建openstack-builder

操作系统:Debian12.6,内核:6.1.0-23-amd64

  1. 规格信息如下
    hostname vCPU memory disk net
    openstack-builder 2C 2G 256G nat
  2. 开启EFI支持,采用uefi的方式安装Debian,分区信息如下
    格式 大小 挂载点
    efi 256M /boot/efi
    xfs ALL /

安装virtualbox additions

  1. 使用如下命令更新apt缓存

    apt update && apt upgrade -y
    
  2. 安装依赖包

    apt install -y build-essential gcc make dkms linux-headers-`uname -r`
    
  3. C:\Program Files\Oracle\VirtualBox\VBoxGuestAdditions.iso 挂载到虚拟机

    mount /dev/cdrom /mnt
    
  4. 执行安装命令

    bash /mnt/VBoxLinuxAdditions.run
    

基础配置

关闭防火墙

  1. 使用如下命令关闭防火墙,并禁止防火墙开机启动(debian为ufw,fedora为firewalld)

    systemctl stop ufw && systemctl disable ufw
    

    显示如下信息,说明防火墙服务ufw不存在

    Failed to stop ufw.service: Unit ufw.service not loaded.
    
  2. 检查防火墙状态,状态如下所示则表示修改成功

    systemctl status ufw
    

修改源

  1. 使用如下命令在 /etc/apt/创建 bak目录

    mkdir -p /etc/apt/bak/
    
  2. 备份原配置,使用如下命令备份原配置

    mv /etc/apt/sources.list /etc/apt/bak/
    
  3. 添加中科大源配置文件,使用 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
    
  4. 使用如下命令更新apt缓存

    apt update && apt upgrade -y
    

软件安装

基础软件

  1. 安装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
    
  2. 安装virt-manager、libvirt、libguestfs-tools、jq等软件

    apt install -y virt-manager libvirt-dev libguestfs-tools jq neofetch
    
  3. 修改pip仓库地址,使用 vim打开 ~/.pip/pip.conf,添加如下内容:

    [global]
    index-url = http://mirrors.aliyun.com/pypi/simple/
    
    [install]
    trusted-host=mirrors.aliyun.com
    timeout=90
    

docker

Debian | Docker Docs

  1. 卸载旧版本

    for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done
    
  2. 安装必要的一些系统工具

    apt-get update && apt install -y ca-certificates curl
    
  3. 安装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
    
  4. 写入软件源信息

    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
    
  5. 通过apt安装docker-ce

    apt-get update && apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
    
  6. 配置国内docker源代理

    自行寻找配置国内镜像加速源

  7. 重启docker,并设置开机启动

    systemctl daemon-reload
    systemctl enable docker && systemctl restart docker
    

docker仓库

  1. 通过如下命令创建本地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虚拟环境

  1. 准备python虚拟环境

    mkdir -p /opt/kolla/pyenv/
    python3 -m venv /opt/kolla/pyenv/
    
  2. 激活python虚拟环境

    tips:info 以后每次使用kolla-build,都要使用如下命令激活kolla的python虚拟环境
    cd /opt/kolla/ && source /opt/kolla/pyenv/bin/activate
    
  3. 升级pip

    pip3 install -U pip
    

安装kolla

通过pip安装

  1. 安装docker的python库

    pip3 install docker
    
  2. 安装kolla的python库

    pip3 install kolla
    

从源代码安装(推荐)

tips:info 推荐,有助于对kolla构建过程进行学习,也方便对源码进行二次开发
  1. 安装docker的python库

    pip3 install docker
    
  2. 使用pip从git代码仓安装

    pip3 install git+https://opendev.org/openstack/kolla.git
    
  3. 检查安装结果

    kolla-build --version
    

    2024-09-25_142605.png

  4. 使用pip从git代码仓升级

    pip3 install -U git+https://opendev.org/openstack/kolla.git
    

构建openstack组件docker镜像

使用kolla-build构建

  1. 激活python虚拟环境

    cd /opt/kolla/ && source /opt/kolla/pyenv/bin/activate
    
  2. 构建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
    

    2024-09-26_095554.png

清理docker镜像

tips:warn 清理操作不可恢复,请谨慎操作
  1. 使用docker命令清理无用镜像
    docker images | grep none | awk '{print $3}'|xargs docker rmi