主题
Kolla-Ansible 部署实施指南
1. 环境准备
1.1 部署节点 (Ansible Control)
bash
# 在 Management 节点上准备部署环境
# 操作系统: Rocky Linux 9.x / Ubuntu 22.04
# 安装依赖
sudo dnf install -y python3 python3-pip python3-devel \
git gcc make sshpass ntp chrony
# 安装 Ansible
pip3 install ansible-core==2.16.*
# 安装 Kolla-Ansible
pip3 install kolla-ansible
# 安装 Docker (所有目标节点)
curl -fsSL https://get.docker.com | sh
# 或使用包管理器
sudo dnf install -y docker-ce docker-ce-cli containerd.io1.2 目标节点基础配置
bash
# 所有节点统一配置 (通过 Ansible 批量执行)
# 1. 关闭 SELinux (Kolla-Ansible 要求)
setenforce 0
sed -i 's/^SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config
# 2. 关闭防火墙 (由安全组管理)
systemctl stop firewalld
systemctl disable firewalld
# 3. 时间同步 (关键!)
cat > /etc/chrony.conf << 'EOF'
server ntp1.example.com iburst
server ntp2.example.com iburst
driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
EOF
systemctl enable --now chronyd
# 4. 配置 Docker
mkdir -p /etc/docker
cat > /etc/docker/daemon.json << 'EOF'
{
"storage-driver": "overlay2",
"log-driver": "json-file",
"log-opts": {
"max-size": "50m",
"max-file": "3"
},
"insecure-registries": ["registry.internal:5000"],
"default-address-pools": [
{"base": "172.30.0.0/16", "size": 24}
]
}
EOF
systemctl enable --now docker
# 5. 内核参数优化
cat > /etc/sysctl.d/99-openstack.conf << 'EOF'
# 网络优化
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.core.somaxconn = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.core.netdev_max_backlog = 65535
# 内存优化
vm.swappiness = 10
vm.overcommit_memory = 1
# 文件描述符
fs.file-max = 2097152
fs.inotify.max_user_watches = 524288
EOF
sysctl --system2. Kolla-Ansible 配置
2.1 生成密码文件
bash
# 生成所有服务密码
kolla-genpwd
# 修改关键密码
vi /etc/kolla/passwords.yml
# keystone_admin_password: xxx
# database_password: xxx2.2 Inventory 文件
bash
# /etc/kolla/inventory (多节点配置)
[control]
ctrl-01 ansible_host=10.0.1.11
ctrl-02 ansible_host=10.0.1.12
ctrl-03 ansible_host=10.0.1.13
ctrl-04 ansible_host=10.0.1.14
ctrl-05 ansible_host=10.0.1.15
[network]
ctrl-01
ctrl-02
ctrl-03
ctrl-04
ctrl-05
[compute]
# 计算节点 (可通过脚本批量生成)
compute-001 ansible_host=10.0.2.1
compute-002 ansible_host=10.0.2.2
...
compute-1000 ansible_host=10.0.2.1000
[monitoring]
mgmt-01 ansible_host=10.0.1.51
mgmt-02 ansible_host=10.0.1.52
mgmt-03 ansible_host=10.0.1.53
[storage]
ceph-mon-01 ansible_host=10.0.3.1
ceph-mon-02 ansible_host=10.0.3.2
ceph-mon-03 ansible_host=10.0.3.3
ceph-osd-01 ansible_host=10.0.3.11
...
ceph-osd-30 ansible_host=10.0.3.402.3 globals.yml 核心配置
yaml
# /etc/kolla/globals.yml
---
# 基础配置
kolla_base_distro: "rocky"
kolla_install_type: "source"
openstack_release: "2024.2"
# 网络配置
kolla_internal_vip_address: "10.0.1.100"
kolla_external_vip_address: "10.0.0.100"
kolla_internal_fqdn: "openstack-internal.example.com"
kolla_external_fqdn: "openstack.example.com"
# 网络接口
network_interface: "bond0"
neutron_external_interface: "bond1"
kolla_external_vip_interface: "bond0"
tunnel_interface: "bond1"
api_interface: "bond0"
storage_interface: "bond0"
# Neutron 网络插件
neutron_plugin_agent: "ovn"
enable_neutron_provider_networks: "yes"
# 启用服务
enable_keystone: "yes"
enable_nova: "yes"
enable_neutron: "yes"
enable_glance: "yes"
enable_cinder: "yes"
enable_heat: "yes"
enable_horizon: "yes"
enable_octavia: "yes"
enable_designate: "yes"
enable_barbican: "yes"
enable_ovn: "yes"
# 禁用 OVS (使用 OVN)
enable_openvswitch: "no"
# Ceph 集成
enable_ceph: "yes"
ceph_nova_backend: "rbd"
enable_ceph_glance: "yes"
enable_ceph_cinder: "yes"
# 高可用
enable_haproxy: "yes"
enable_keepalived: "yes"
# 日志与监控
enable_central_logging: "yes"
enable_prometheus: "yes"
enable_grafana: "yes"
enable_elasticsearch: "yes"
enable_kibana: "yes"
# Nova 配置
nova_compute_virt_type: "kvm"
nova_safety_reset_state_timeout: 600
# 数据库配置 (大规模调优)
openstack_database_max_overflow: 100
openstack_database_max_pool_size: 50
# RabbitMQ 配置
om_enable_rabbitmq_high_availability: "yes"
om_rabbitmq_ha_replica_count: 32.4 Nova 大规模调优 (nova.conf 覆盖)
yaml
# /etc/kolla/config/nova/nova-compute.conf
[DEFAULT]
# 大规模部署优化
resume_guests_state_on_host_boot = true
max_concurrent_builds = 20
max_concurrent_live_migrations = 4
block_device_allocate_retries = 120
block_device_allocate_retries_interval = 3
[scheduler]
max_placement_results = 1000
[compute]
consecutive_build_service_disable_threshold = 20
[workarounds]
disable_libvirt_livemigration = false2.5 Neutron/OVN 配置
yaml
# /etc/kolla/config/neutron.conf 覆盖
[DEFAULT]
# 大规模网络优化
api_workers = 16
rpc_workers = 8
rpc_state_report_workers = 4
[oslo_messaging_rabbit]
rabbit_ha_queues = true
rabbit_retry_interval = 1
rabbit_retry_backoff = 2
rabbit_max_retries = 03. 部署执行
3.1 部署步骤
bash
# 1. 验证 Inventory
ansible -i /etc/kolla/inventory all -m ping
# 2. 引导 (Bootstrap) - 安装 Docker、配置用户等
kolla-ansible -i /etc/kolla/inventory bootstrap-servers
# 3. 预检查
kolla-ansible -i /etc/kolla/inventory prechecks
# 4. 拉取/构建镜像
kolla-ansible -i /etc/kolla/inventory pull
# 或使用本地 Registry
# kolla-ansible -i /etc/kolla/inventory pull --tag 2024.2-rocky
# 5. 部署
kolla-ansible -i /etc/kolla/inventory deploy
# 6. 后配置 (创建网络、flavor 等)
kolla-ansible -i /etc/kolla/inventory post-deploy
# 7. 生成 admin-openrc.sh
source /etc/kolla/admin-openrc.sh3.2 分批部署计算节点
bash
# 大规模部署建议分批进行 (每批 100-200 节点)
# 创建分批 inventory
# /etc/kolla/inventory-batch-1
[compute]
compute-001 ansible_host=10.0.2.1
...
compute-100 ansible_host=10.0.2.100
# 分批部署
for batch in 1 2 3 4 5; do
echo "=== Deploying batch $batch ==="
kolla-ansible -i /etc/kolla/inventory-batch-${batch} deploy
# 验证本批节点
openstack compute service list --service nova-compute | \
grep "batch-${batch}" | grep -c "up"
# 等待稳定 (5分钟)
sleep 300
done4. 部署后验证
4.1 基础验证检查
bash
#!/bin/bash
# verify-deployment.sh
echo "=== OpenStack 部署验证 ==="
# 1. 检查所有服务状态
echo "--- 服务状态 ---"
openstack compute service list
openstack network agent list
# 2. 检查 Ceph 状态
echo "--- Ceph 集群 ---"
docker exec ceph_mon ceph status
# 3. 创建测试实例
echo "--- 创建测试 VM ---"
openstack flavor create m1.test --ram 512 --disk 1 --vcpus 1
openstack network create test-net
openstack subnet create test-subnet --network test-net \
--subnet-range 192.168.100.0/24 --gateway 192.168.100.1
openstack server create test-vm --flavor m1.test \
--image cirros --network test-net
# 4. 等待实例就绪
sleep 30
openstack server show test-vm -c status -c addresses
# 5. 清理测试资源
openstack server delete test-vm
sleep 10
openstack network delete test-net
openstack flavor delete m1.test4.2 性能基线测试
bash
# API 响应时间测试
for i in $(seq 1 100); do
curl -s -o /dev/null -w "%{time_total}\n" \
-H "X-Auth-Token: $OS_TOKEN" \
http://10.0.1.100:8774/v2.1/servers
# VM 启动时间测试
start=$(date +%s)
openstack server create perf-test --flavor m1.small \
--image cirros --network test-net --wait
end=$(date +%s)
echo "VM boot time: $((end - start)) seconds"5. 升级与回滚
5.1 滚动升级
bash
# 1. 更新 Kolla-Ansible
pip3 install --upgrade kolla-ansible
# 2. 更新 globals.yml 版本号
sed -i 's/2024.1/2024.2/' /etc/kolla/globals.yml
# 3. 拉取新镜像
kolla-ansible -i /etc/kolla/inventory pull
# 4. 滚动升级 (控制节点优先)
kolla-ansible -i /etc/kolla/inventory upgrade \
--limit control
kolla-ansible -i /etc/kolla/inventory upgrade \
--limit compute5.2 回滚方案
bash
# 如果升级失败,回滚到旧版本
kolla-ansible -i /etc/kolla/inventory deploy \
--tag <old_version>
# 或手动回滚特定服务
docker stop nova_api
docker start nova_api:<old_tag>