Skip to content

OpenStack 故障排查与性能调优

本文介绍生产环境中常见的故障场景排查方法、性能优化方案,以及与 Kubernetes 的集成和选型对比。

故障排查

Nova-Compute 宕机

故障现象

  • 计算节点状态显示 DOWN
  • 该节点上的虚拟机无法访问
  • 新建虚拟机调度失败

排查步骤

bash
# 1. 检查 Nova-Compute 服务状态
systemctl status nova-compute

# 2. 检查 Nova-Compute 日志
journalctl -u nova-compute -n 100

# 3. 检查与消息队列的连接
rabbitmqctl list_connections name

# 4. 检查 Nova-Compute 配置
grep -E "^host|^vnc" /etc/nova/nova.conf

# 5. 检查 libvirt 服务
systemctl status libvirtd
virsh list

常见原因及解决方案

原因解决方案
Nova-Compute 服务崩溃重启服务 systemctl restart nova-compute
与 RabbitMQ 连接断开检查网络,重启服务
libvirt 异常重启 libvirtd 服务
主机名变更导致认证失败更新 nova.conf 中的 host 配置

恢复步骤

bash
# 重启 Nova-Compute
systemctl restart nova-compute

# 验证服务状态
openstack compute service list

# 检查虚拟机状态
openstack server list --host <compute-host>

RabbitMQ 队列堆积

故障现象

  • 虚拟机创建缓慢或失败
  • API 请求超时
  • 队列消息持续增长

排查步骤

bash
# 1. 查看队列状态
rabbitmqctl list_queues name messages messages_ready

# 2. 查看消费者状态
rabbitmqctl list_consumers

# 3. 查看队列深度变化
rabbitmqctl list_queues name messages | tail -n +2 | awk '{print $2}' | sort -rn | head

# 4. 检查 RabbitMQ 日志
tail -f /var/log/rabbitmq/rabbitmq.log

解决方案

bash
# 清理积压消息(谨慎使用)
rabbitmqctl purge_queue nova_compute

# 重启消费者服务
systemctl restart nova-compute
systemctl restart neutron-linuxbridge-agent

# 如果是 RabbitMQ 集群问题,重启节点
rabbitmqctl stop_app
rabbitmqctl start_app

预防措施

  • 监控队列深度,设置告警
  • 合理配置预取数量(prefetch)
  • 确保消费者服务高可用

网络不通

故障现象

  • 虚拟机无法 ping 通网关
  • 虚拟机无法访问外部网络
  • 浮动 IP 无法访问

排查步骤

bash
# 1. 检查 Neutron 代理状态
openstack network agent list

# 2. 检查网络命名空间
ip netns list

# 3. 检查路由器状态
openstack router show <router-id>

# 4. 检查安全组规则
openstack security group rule list <sg-id>

# 5. 在计算节点检查 OVS
ovs-vsctl show
ovs-ofctl dump-flows br-int

常见问题及解决方案

bash
# 问题:DHCP 不可用
# 解决:重启 DHCP Agent
systemctl restart neutron-dhcp-agent

# 问题:路由器网关未设置
# 解决:设置外部网关
openstack router set <router-id> --external-gateway public-network

# 问题:安全组阻止流量
# 解决:添加安全组规则
openstack security group rule create --ingress \
  --protocol icmp --remote-ip 0.0.0.0/0 <sg-id>

# 问题:VLAN/隧道未创建
# 解决:检查 Neutron 插件配置

Ceph 故障

故障现象

  • 卷无法挂载
  • 虚拟机无法启动
  • 存储操作超时

排查步骤

bash
# 1. 检查 Ceph 状态
ceph -s

# 2. 检查 OSD 状态
ceph osd status

# 3. 检查 PG 状态
ceph pg stat

# 4. 检查 Ceph 日志
tail -f /var/log/ceph/ceph-mon.log
tail -f /var/log/ceph/ceph-osd.log

常见故障处理

bash
# OSD 宕机
# 1. 检查磁盘故障
smartctl -a /dev/sdb

# 2. 重启 OSD
systemctl restart ceph-osd@<id>

# 3. 如果磁盘损坏,替换并恢复
ceph osd out <osd-id>
ceph osd crush remove osd.<id>
ceph auth del osd.<id>

# PG 降级
# 1. 检查数据恢复进度
ceph -s

# 2. 如果长时间不恢复,手动修复
ceph pg force_recovery <pg-id>

# Ceph 存储池问题
# 1. 检查存储池
ceph osd pool ls detail

# 2. 调整 PG 数量
ceph osd pool set <pool> pg_num 256

性能调优

CPU Pinning

CPU Pinning 将虚拟机 CPU 固定到物理 CPU 核心,避免跨核心调度带来的性能损失:

配置步骤

bash
# 1. 在计算节点启用 CPU pinning
# /etc/nova/nova.conf
[compute]
cpu_allocation_ratio = 1.0
reserved_host_memory_mb = 1024

# 2. 创建支持 CPU pinning 的 flavor
openstack flavor create --vcpus 4 --ram 8192 --disk 50 m1.pinning
openstack flavor set m1.pinning set hw:cpu_policy=dedicated
openstack flavor set m1.pinning set hw:numa_nodes=1

验证配置

bash
# 查看虚拟机 CPU 亲和性
virsh vcpupin <vm-id>

# 查看 NUMA 配置
numactl --hardware

DPDK/SR-IOV

DPDK(Data Plane Development Kit)和 SR-IOV(Single Root I/O Virtualization)提供高性能网络:

DPDK 配置

bash
# 1. 安装 DPDK
yum install dpdk

# 2. 绑定网卡到 DPDK
dpdk-devbind.py --bind vfio-pci 0000:04:00.0

# 3. 配置 Neutron 使用 DPDK
# /etc/neutron/plugins/ml2/openvswitch_agent.ini
[ovs]
bridge_mappings = physnet1:br-physnet1
datapath_type = netdev

[agent]
dpdk_socket_mem = "1024,0"
dpdk_lcore_mask = 0x1

SR-IOV 配置

bash
# 1. 启用 SR-IOV
# /etc/nova/nova.conf
[pci]
passthrough_whitelist = {"devname": "eth1", "physical_network": "physnet1"}

# 2. 创建 SR-IOV 端口
openstack port create --network private \
  --vnic-type direct sriov-port

# 3. 创建虚拟机
openstack server create --nic port-id=<port-id> --flavor m1.small vm1

数据库优化

MySQL/MariaDB 调优

ini
# /etc/my.cnf.d/openstack.cnf
[mysqld]
max_connections = 1000
innodb_buffer_pool_size = 4G
innodb_log_file_size = 1G
innodb_flush_log_at_trx_commit = 2
innodb_flush_method = O_DIRECT
query_cache_size = 0
query_cache_type = 0
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 2

连接池配置

ini
# /etc/nova/nova.conf
[database]
connection_pool_size = 50
connection_pool_max_overflow = 20
connection_pool_timeout = 30

消息队列优化

RabbitMQ 调优

ini
# /etc/rabbitmq/rabbitmq.conf
loopback_users = []
tcp_listeners = 5672
heartbeat = 60
channel_max = 2048
frame_max = 131072

队列参数优化

bash
# 设置队列参数
rabbitmqctl set_policy ha-all "^ha\." '{"ha-mode":"all"}'

与 Kubernetes 集成

Magnum 容器服务

Magnum 是 OpenStack 的容器编排服务,基于 Kubernetes:

bash
# 1. 创建 COE(Container Orchestration Engine)
openstack coe cluster template create k8s-template \
  --image fedora-atomic-latest \
  --keypair mykey \
  --external-network public \
  --dns-nameserver 8.8.8.8 \
  --flavor m1.small

# 2. 创建 Kubernetes 集群
openstack coe cluster create k8s-cluster \
  --cluster-template k8s-template \
  --master-count 3 \
  --node-count 3

# 3. 获取集群配置
openstack coe cluster config k8s-cluster > kubeconfig

Kuryr 网络集成

Kuryr 提供 Kubernetes 网络与 OpenStack Neutron 的集成:

bash
# 1. 安装 Kuryr
pip install kuryr-kubernetes

# 2. 配置 Kuryr
# /etc/kuryr/kuryr.conf
[DEFAULT]
bind_addr = 0.0.0.0

[neutron]
auth_url = http://keystone:5000/v3
project_name = service
user_domain_name = default
username = kuryr
password = password

# 3. 配置 Kubernetes CNI
# /etc/kubernetes/cni/net.d/10-kuryr.conf
{
  "cniVersion": "0.3.1",
  "name": "kuryr",
  "type": "kuryr-cni"
}

OpenStack-Helm

OpenStack-Helm 使用 Helm 在 Kubernetes 上部署 OpenStack:

bash
# 1. 添加 OpenStack-Helm 仓库
helm repo add openstack-helm https://charts.openstack.org/openstack-helm

# 2. 部署 OpenStack
cd openstack-helm
./tools/deployment/common/start-all.sh

# 3. 验证部署
kubectl get pods -n openstack

OpenStack vs VMware 选型对比

功能对比

特性OpenStackVMware vSphere
许可证开源(Apache 2.0)商业授权
虚拟化技术KVM/QEMUESXi
架构复杂度
硬件兼容性广泛受限
社区支持活跃企业支持
运维成本较高较高
自动化程度依赖工具原生完善

性能对比

指标OpenStackVMware
虚拟机密度
网络性能中(需优化)
存储性能依赖后端高(vSAN)
虚拟化开销5-10%2-5%

成本对比

成本项OpenStackVMware
软件许可免费昂贵
硬件成本
运维成本
培训成本
支持成本社区/厂商厂商

选型建议

选择 OpenStack 的场景

  • 需要开源可控
  • 已有 Linux 运维团队
  • 需要与 Ceph 集成
  • 成本敏感
  • 需要定制化开发

选择 VMware 的场景

  • 追求稳定性
  • 有 Windows 虚拟化需求
  • 需要成熟的虚拟化功能
  • 有预算购买许可
  • 需要专业支持

混合方案

许多企业采用混合方案:

┌─────────────────────────────────────────┐
│              统一管理层                  │
│  VMware vCenter / OpenStack Horizon    │
└──────────────────┬──────────────────────┘

     ┌─────────────┴─────────────┐
     │                           │
┌────▼────┐                ┌────▼────┐
│VMware   │                │OpenStack│
│vSphere  │                │KVM      │
└─────────┘                └─────────┘

统一管理工具

  • VMware 的 OpenStack Driver
  • OpenStack 的 vCenter 插件
  • 第三方多云管理平台(RightScale、CloudHealth)