kyyee
发布于 2024-09-27 / 180 阅读
0

kolla-ansible部署openstack

开始前必读

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

搭建编译构建环境

tips:info 通过虚拟机部署openstack单机版

网络规划

开始之前,先对virtualbox的网络模式做一个简单介绍。

VirtualBox网络模式比较

VM<->VM VM->Host VM<-Host VM->LAN VM<-LAN
NAT - + Port Forward + Port Forward
NAT-Network + + Port Forward + Port Forward
Host-only + + + - -
Bridged + + + + +

通过对比,本例采用NAT-Network和Host-only网络结合的方式搭建Openstack集群。

单机版(本例采用)

graph TB subgraph Host["Host"] Switch1["Switch 1 <br> nat-network:10.20.0.0/24"] Switch2["Switch 2 <br> nat-network:10.21.0.0/24"] Switch3["Switch 3 <br> host-only:192.168.10.1/24"] ALL-IN-ONE --eth0: <br> 10.20.0.5/24--> Switch1 ALL-IN-ONE --eth1: <br> 10.21.0.5/24--> Switch2 ALL-IN-ONE --eth2: <br> 192.168.10.4/24--> Switch3 end classDef switch fill:#fa8,stroke:#333,stroke-width:4px; classDef server fill:#8a2be2,stroke:#333,stroke-width:2px; class Switch1,Switch2,Switch3 switch class ALL-IN-ONE server

集群版

graph TB subgraph Host["Host"] Switch1["Switch 1 <br> nat-network:10.20.0.0/24"] Switch2["Switch 2 <br> nat-network:10.21.0.0/24"] Switch3["Switch 3 <br> host-only:192.168.10.1/24"] Controller0 --eth0: <br> 10.20.0.5/24--> Switch1 Controller0 --eth1: <br> 10.21.0.5/24--> Switch2 Controller1 --eth0: <br> 10.20.0.6/24--> Switch1 Controller1 --eth1: <br> 10.21.0.6/24--> Switch2 Controller2 --eth0: <br> 10.20.0.7/24--> Switch1 Controller2 --eth1: <br> 10.21.0.7/24--> Switch2 Switch1 --eth0: <br> 10.20.0.8/24--> Network0 Switch2 --eth1: <br> 10.21.0.8/24--> Network0 Switch3 --eth2: <br> 192.168.10.4/24--> Network0 Switch1 --eth0: <br> 10.20.0.9/24--> Network1 Switch2 --eth1: <br> 10.21.0.9/24--> Network1 Switch3 --eth2: <br> 192.168.10.5/24--> Network1 Switch1 --eth0: <br> 10.20.0.10/24--> Network2 Switch2 --eth1: <br> 10.21.0.10/24--> Network2 Switch3 --eth2: <br> 192.168.10.6/24--> Network2 Switch1 --eth0: <br> 10.20.0.11/24--> Compute0 Switch2 --eth1: <br> 10.21.0.11/24--> Compute0 Switch3 --eth2: <br> 192.168.10.7/24--> Compute0 Switch1 --eth0: <br> 10.20.0.12/24--> Compute1 Switch2 --eth1: <br> 10.21.0.12/24--> Compute1 Switch3 --eth2: <br> 192.168.10.8/24--> Compute1 end classDef switch fill:#fa8,stroke:#333,stroke-width:4px; classDef controller fill:#98d1b5,stroke:#333,stroke-width:2px; classDef network fill:#f9f,stroke:#333,stroke-width:2px; classDef compute fill:#FFECA1,stroke:#333,stroke-width:2px; class Switch1,Switch2,Switch3 switch class Controller0,Controller1,Controller2 controller class Network0,Network1,Network2 network class Compute0,Compute1 compute

virtualbox网络创建

  1. File->Tools->Network Manager->NAT Networks->Create

    2024-10-01_104102.png

  2. Create Host-only Networks,参照网络规划创建网络

    Host-only Networks

    2024-10-01_104448.png

    NAT Networks

    2024-10-01_104616.png

准备虚拟机

下载 Debian

新建openstack-allinone

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

  1. 规格信息如下

    hostname vCPU memory disk net
    openstack-allinone 8C 8G 256G switch1,switch2,switch3
  2. 开启EFI支持,采用uefi的方式安装Debian,分区信息如下

    格式 大小 挂载点
    efi 256M /boot/efi
    xfs ALL /

    2024-10-01 110744.png

网络配置

参考网络规划完成网络的静态配置,switch1为控制面网络,switch2所在的网络不配置IP,为openstack的外部网络,switch3为数据面网络。

8.2. 配置网络 (debian.org)

Debian12采用NetworkManager网络管理工具,它将所有的网卡都存储在同一个连接中。

  1. 通过如下命令查看设备状态

    nmcli device status
    
  2. 通过如下命令查看连接状态

    nmcli connection show
    
  3. 通过如下命令新建连接 Wired connection 2Wired connection 3

    nmcli connection add con-name 'Wired connection 2' ifname enp0s8 type ethernet
    
    nmcli connection add con-name 'Wired connection 3' ifname enp0s9 type ethernet
    
  4. 通过如下命令重建连接 Wired connection 1

    nmcli connection del 'Wired connection 1'
    nmcli connection add con-name 'Wired connection 1' ifname enp0s3 type ethernet
    
  5. 之后通过 nmtui 配置连接的静态IP地址

  6. nmtuinmcli 的更多用法可查阅使用手册

安装virtualbox additions

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

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

    apt install 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
    

kolla-ansible

Quick Start for deployment/evaluation — kolla-ansible 18.1.0.dev217 documentation (openstack.org)

准备python虚拟环境

  1. 准备python虚拟环境

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

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

    pip3 install -U pip
    
  4. 安装ansible

    pip install 'ansible-core>=2.16,<2.17.99'
    
  5. 修改ansible配置

    mkdir -p /etc/ansible
    vi /etc/ansible/ansible.cfg
    

    /etc/ansible/ansible.cfg 写入如下内容:

    [defaults]
    host_key_checking=False
    pipelining=True
    forks=100
    

安装kolla-ansible

通过pip安装

  1. 安装docker的python库

    pip3 install docker
    
  2. 安装kolla的python库

    pip3 install kolla-ansible
    

从源代码安装(推荐)

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

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

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

    kolla-ansible --version
    

    2024-09-27_100346.png

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

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

准备部署配置文件

  1. 准备节点配置文件 all-in-one

    cp /opt/kolla-ansible/pyenv/share/kolla-ansible/ansible/inventory/all-in-one /opt/kolla-ansible/
    
  2. 准备组件配置文件 globals.yml 和密码配置文件 passwords.yml

    mkdir -p /etc/kolla && chown $USER:$USER /etc/kolla
    
    cp -r /opt/kolla-ansible/pyenv/share/kolla-ansible/etc_examples/kolla/* /etc/kolla
    

部署openstack组件

初始化

ansible

  1. 检查节点连通性

    ansible -i all-in-one common -m ping
    
  2. 激活python虚拟环境

    cd /opt/kolla-ansible/ && source /opt/kolla-ansible/pyenv/bin/activate
    
  3. 安装ansible依赖

    kolla-ansible -i all-in-one install-deps
    

/etc/kolla/passwords.yml

  1. 密码生成 /etc/kolla/passwords.yml
    kolla-genpwd
    

/etc/kolla/globals.yml

网络配置
组件配置

使用kolla-ansible部署

  1. 激活python虚拟环境

    cd /opt/kolla-ansible/ && source /opt/kolla-ansible/pyenv/bin/activate
    
  2. 环境安装,自动安装依赖,如docker等

    kolla-ansible -i all-in-one bootstrap-servers
    
  3. 环境和配置参数预检查

    kolla-ansible -i all-in-one prechecks
    
  4. 部署openstack

    kolla-ansible -i all-in-one deploy
    
  5. 升级openstack(可选)

    kolla-ansible -i all-in-one reconfigure
    

openstack客户端

  1. 安装openstack client
    pip3 install python-openstackclient -c https://releases.openstack.org/constraints/upper/master
    
  2. 生成openstack client的客户端令牌 /etc/kolla/admin-openrc.sh
    kolla-ansible post-deploy
    
  3. 使用令牌 /etc/kolla/admin-openrc.sh
    source /etc/kolla/admin-openrc.sh
    

销毁openstack集群

使用kolla-ansible销毁

  1. 激活python虚拟环境

    cd /opt/kolla-ansible/ && source /opt/kolla-ansible/pyenv/bin/activate
    
  2. 销毁openstack集群

    tips:warn 销毁集群将删除所有数据,请谨慎操作 一般仅在部署遇到报错时进行销毁操作
    kolla-ansible -i all-in-one destroy --yes-i-really-really-mean-it
    

附录

dbus模块找不到

  1. 执行prechecks时报错如下

    2024-09-27_112511.png

  2. 执行如下命令安装dbus的python库

    pip3 install dbus-python
    
  3. 上述命令报错找不到CMake、pkg-config

    2024-09-27_113155.png

  4. 执行如下命令安装CMake、pkg-config

    apt install -y cmake pkg-config
    
  5. ERROR: Dependency "dbus-1" not found, tried pkgconfig and cmake

    apt install -y libdbus-1-dev
    
  6. ERROR: Dependency "glib-2.0" not found, tried pkgconfig and cmake

    apt install -y libglib2.0-dev
    
  7. 再次安装dbus的python库

    pip3 install dbus-python