Skip to content

OpenStack 企业部署实践

本文介绍生产环境中 OpenStack 的部署方案、架构设计和最佳实践。

Kolla-Ansible 部署

Kolla-Ansible 是 OpenStack 官方推荐的容器化部署方案,使用 Ansible 编排 Docker 容器运行 OpenStack 服务。

环境准备

硬件要求

节点类型CPU内存磁盘网络
控制节点8 核32GB100GB2x1GbE
计算节点16 核64GB500GB2x10GbE
存储节点8 核16GB4TB2x10GbE

操作系统要求

  • Ubuntu 20.04/22.04 或 CentOS 8/Rocky Linux 8
  • Python 3.8+
  • Ansible 2.12+

部署步骤

1. 安装依赖

bash
# Ubuntu
apt update && apt install -y python3-pip

# CentOS
yum install -y python3-pip

# 安装 Ansible
pip3 install ansible kolla-ansible

2. 配置 inventory

ini
# /etc/kolla/inventory/all-in-one
[control]
localhost ansible_connection=local

[network]
localhost

[compute]
localhost

[storage]
localhost

[monitoring]
localhost

[deployment]
localhost ansible_connection=local

3. 配置 globals.yml

yaml
# /etc/kolla/globals.yml
kolla_base_distro: "ubuntu"
kolla_install_type: "binary"
openstack_release: "2023.1"

kolla_internal_vip_address: "192.168.100.10"
kolla_external_vip_address: "10.0.0.10"

network_interface: "ens3"
neutron_external_interface: "ens4"

enable_cinder: "yes"
enable_ceph: "yes"
enable_horizon: "yes"
enable_neutron_provider_agent: "yes"

4. 初始化配置

bash
# 生成密码
kolla-ansible -i all-in-one passwords

# 拉取镜像(可选)
kolla-ansible -i all-in-one pull

# 预检查
kolla-ansible -i all-in-one prechecks

5. 执行部署

bash
# 部署
kolla-ansible -i all-in-one deploy

# 验证部署
kolla-ansible -i all-in-one post-deploy

多节点部署 inventory 示例

ini
# /etc/kolla/inventory/multinode
[control]
control01 ansible_host=192.168.100.11
control02 ansible_host=192.168.100.12
control03 ansible_host=192.168.100.13

[network]
network01 ansible_host=192.168.100.21
network02 ansible_host=192.168.100.22

[compute]
compute01 ansible_host=192.168.100.31
compute02 ansible_host=192.168.100.32
compute03 ansible_host=192.168.100.33

[storage]
storage01 ansible_host=192.168.100.41
storage02 ansible_host=192.168.100.42

[monitoring]
monitor01 ansible_host=192.168.100.51

[keystone:children]
control

[glance:children]
control

[nova:children]
control

[neutron:children]
network

[cinder:children]
control

多 Region/AZ 架构

Region 架构

Region 是 OpenStack 的地理隔离单元,每个 Region 有独立的 API 端点和资源:

┌─────────────────────────────────────────────────────────┐
│                    Region One                          │
│  ┌─────────────────────────────────────────────────┐   │
│  │ Controller Cluster (HA)                         │   │
│  │ Keystone / Nova / Neutron / Cinder / Glance     │   │
│  └─────────────────────────────────────────────────┘   │
│  API Endpoint: https://region1.api.example.com:5000   │
└─────────────────────────────────────────────────────────┘

                          │ Federation

┌─────────────────────────────────────────────────────────┐
│                    Region Two                          │
│  ┌─────────────────────────────────────────────────┐   │
│  │ Controller Cluster (HA)                         │   │
│  │ Keystone / Nova / Neutron / Cinder / Glance     │   │
│  └─────────────────────────────────────────────────┘   │
│  API Endpoint: https://region2.api.example.com:5000   │
└─────────────────────────────────────────────────────────┘

跨 Region 认证配置

ini
# /etc/keystone/fernet_keys/ 同步或独立配置

# Region 配置
[DEFAULT]
region = RegionTwo

# 跨 Region 认证
[auth]
methods = password,token

可用区(Availability Zone)

AZ 是计算节点或存储节点的逻辑分组,提供故障隔离:

bash
# 创建计算可用区
openstack aggregate create --zone availability_zone compute-az1

# 添加主机到可用区
openstack aggregate add host compute-az1 compute01

# 设置可用区元数据
openstack aggregate set --property availability_zone=az1 compute-az1

AZ 感知调度

yaml
# nova.conf
[scheduler]
default_availability_zone = az1

高可用设计

控制节点高可用

                    ┌─────────────┐
                    │   Keepalived│
                    │   VRRP VIP  │
                    └──────┬──────┘

        ┌──────────────────┼──────────────────┐
        │                  │                  │
┌──────▼──────┐    ┌──────▼──────┐    ┌──────▼──────┐
│ Controller1 │    │ Controller2 │    │ Controller3 │
│ ┌──────────┐│    │ ┌──────────┐│    │ ┌──────────┐│
│ │ Keystone ││    │ │ Keystone ││    │ │ Keystone ││
│ │ Glance   ││    │ │ Glance   ││    │ │ Glance   ││
│ │ Nova     ││    │ │ Nova     ││    │ │ Nova     ││
│ │ Neutron  ││    │ │ Neutron  ││    │ │ Neutron  ││
│ └──────────┘│    │ └──────────┘│    │ └──────────┘│
└──────┬──────┘    └──────┬──────┘    └──────┬──────┘
       │                  │                  │
       └──────────────────┼──────────────────┘

                    ┌──────▼──────┐
                    │   MySQL     │
                    │   Galera    │
                    │   Cluster   │
                    └──────┬──────┘

                    ┌──────▼──────┐
                    │  RabbitMQ   │
                    │   Cluster   │
                    └─────────────┘

MySQL Galera 配置

yaml
# kolla-ansible globals.yml
enable_mariadb: "yes"
mariadb_cluster_name: "openstack"
mariadb_max_connections: 1000

RabbitMQ HA 配置

yaml
# kolla-ansible globals.yml
enable_rabbitmq: "yes"
rabbitmq_cluster: "yes"
rabbitmq_vip: "192.168.100.10"

计算节点高可用

Nova 支持计算节点故障检测和虚拟机恢复:

yaml
# nova.conf
[compute]
resume_guests_state_on_host_boot = true

[scheduler]
track_instance_changes = true

网络高可用

Neutron HA Router

bash
# 创建 HA 路由器
openstack router create --ha --external-gateway public-network ha-router

配置 L3 Agent HA

yaml
# /etc/neutron/l3_agent.ini
[DEFAULT]
ha_router_keepalived_update_period = 5
ha_router_keepalived_restart_delay = 10

负载均衡

Octavia 作为 LBaaS

yaml
# kolla-ansible globals.yml
enable_octavia: "yes"
octavia_auto_ip: true
bash
# 创建负载均衡器
openstack loadbalancer create --name lb1 --vip-subnet-id <subnet-id>

# 添加监听器
openstack loadbalancer listener create --name listener1 \
  --protocol HTTP --protocol-port 80 lb1

# 添加后端池
openstack loadbalancer pool create --name pool1 \
  --lb-algorithm ROUND_ROBIN --listener listener1 \
  --protocol HTTP

# 添加后端成员
openstack loadbalancer member create --name member1 \
  --address 192.168.100.50 --protocol-port 80 pool1

存储高可用

Ceph 部署

yaml
# kolla-ansible globals.yml
enable_ceph: "yes"
ceph_pool_size: 3
ceph_pool_ec_profile: ""

Ceph 集群状态检查

bash
# 查看 Ceph 状态
ceph -s

# 查看 OSD 状态
ceph osd status

# 查看 PG 状态
ceph pg stat

Cinder 多后端高可用

yaml
# cinder.conf
[lvm]
enabled_backends = lvm-1,lvm-2

[lvm-1]
volume_backend_name = lvm-1
volume_group = cinder-volumes-1

[lvm-2]
volume_backend_name = lvm-2
volume_group = cinder-volumes-2

网络设计

物理网络规划

网络类型VLAN ID网段用途
Management100192.168.100.0/24管理平面
Tunnel101172.16.100.0/24VXLAN 隧道
Storage102192.168.200.0/24存储网络
External10310.0.0.0/24浮动 IP 池

VLAN Provider 网络配置

yaml
# /etc/neutron/plugins/ml2/ml2_conf.ini
[ml2]
type_drivers = flat,vlan,vxlan
tenant_network_types = vxlan
mechanism_drivers = openvswitch

[ml2_type_vlan]
network_vlan_ranges = physnet1:100:200

网络节点分离部署

yaml
# multinode inventory
[network]
network01 ansible_host=192.168.100.21
network02 ansible_host=192.168.100.22

[compute]
compute01 ansible_host=192.168.100.31
compute02 ansible_host=192.168.100.32

部署验证

服务状态检查

bash
# 检查所有 OpenStack 服务
openstack endpoint list

# 检查 Nova 服务
openstack compute service list

# 检查 Neutron 代理
openstack network agent list

# 检查 Cinder 服务
openstack volume service list

创建测试虚拟机

bash
# 创建网络
openstack network create test-network
openstack subnet create --network test-network \
  --subnet-range 192.168.10.0/24 test-subnet

# 创建 flavor
openstack flavor create --ram 2048 --vcpus 2 --disk 20 m1.small

# 创建密钥对
openstack keypair create mykey > mykey.pem
chmod 400 mykey.pem

# 创建安全组规则
openstack security group rule create --ingress \
  --protocol icmp default

# 启动虚拟机
openstack server create --flavor m1.small --image centos7 \
  --network test-network --key-name mykey \
  --security-group default test-vm

性能基准测试

bash
# 使用 Rally 进行基准测试
rally task start /usr/share/rally/samples/tasks/scenarios/nova/boot-and-delete.json