轻松做到OpenStack对接Ceph集群,便于扩展的分布式存储实战--黑夜青儿

本文详述了如何在OpenStack环境中配置和使用Ceph作为后端存储,包括镜像服务Glance、块存储服务Cinder及云主机存储的对接步骤。涵盖Ceph池创建、客户端认证、镜像与计算节点配置等关键环节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

概述

libvirt配置了librbd的QEMU接口,通过它可以在OpenStack中使用Ceph块存储。Ceph块存储是集群对象,这意味着它比独立的服务器有更好的性能。
在OpenStack中使用Ceph块设备,必须首先安装QEMU,libvirt;OpenStack,下图描述了 OpenStack和Ceph技术层次结构:

在这里插入图片描述
OpenStack的功能服务对接的有三种
对接分为三种,也就是存储为openstack提供的三类功能
1.镜像服务Glance对接
2.块存储服务Cinder对接
3.云主机储存对接

OpenStack对接Ceph集群前提条件
1.Openstack集群已完成部署
详细部署实战URL:https://blog.youkuaiyun.com/weixin_41711331/article/details/83992040

2.Ceph集群部署完成
详细部署实战
URL:https://blog.youkuaiyun.com/weixin_41711331/article/details/84023279

开始进行对接

  1. OpenStack使用ceph作为后端存储
    1.1. Ceph相关配置
     在ceph上创建pool
    #ceph osd pool create volumes 64
    #ceph osd pool create images 64
    #ceph osd pool create vms 64

 在glance-api(控制节点)节点上
#yum install python-rbd-rbd –y
 (计算节点)在nova-compute和cinder-volume节点上
#yum install ceph-common –y

1.2. openstack安装Ceph客户端认证
 集群ceph存储端操作
[root@ceph]# ssh 172.26.128.126 tee /etc/ceph/ceph.conf < /etc/ceph/ceph.conf
[root@ceph]# ssh 172.26.128.166 tee /etc/ceph/ceph.conf < /etc/ceph/ceph.conf
[root@ceph]# ssh 172.26.128.167 tee /etc/ceph/ceph.conf < /etc/ceph/ceph.conf
[root@ceph]# ssh 172.26.128.168 tee /etc/ceph/ceph.conf < /etc/ceph/ceph.conf
 用户授权
ceph auth get-or-create client.cinder mon ‘allow r’ osd ‘allow class-read object_prefix rbd_children, allow rwx pool=volumes, allow rwx pool=vms, allow rx pool=images’
ceph auth get-or-create client.glance mon ‘allow r’ osd ‘allow class-read object_prefix rbd_children, allow rwx pool=images’
ceph auth get-or-create client.cinder-backup mon ‘allow r’ osd ‘allow class-read object_prefix rbd_children, allow rwx pool=backups’

 把 client.cinder 、 client.glance 和 client.cinder-backup 的密钥环复制到适当的节点,并更改所有权:
ceph auth get-or-create client.glance | ssh {your-glance-api-server} tee /etc/ceph/ceph.client.glance.keyring
ssh {your-glance-api-server} sudo chown glance:glance /etc/ceph/ceph.client.glance.keyring
ceph auth get-or-create client.cinder | ssh {your-volume-server} tee /etc/ceph/ceph.client.cinder.keyring
ssh {your-cinder-volume-server} sudo chown cinder:cinder /etc/ceph/ceph.client.cinder.keyring
ceph auth get-or-create client.cinder-backup | ssh {your-cinder-backup-server} sudo tee /etc/ceph/ceph.client.cinder-backup.keyring
ssh {your-cinder-backup-server} sudo chown cinder:cinder /etc/ceph/ceph.client.cinder-backup.keyring

 运行 nova-compute 的节点,其进程需要密钥环文件:
没有复制167,是因为cinder-volumes和计算节点在一个机器
ceph auth get-or-create client.cinder | ssh 172.26.128.166 tee /etc/ceph/ceph.client.cinder.keyring
ceph auth get-or-create client.cinder | ssh 172.26.128.168 tee /etc/ceph/ceph.client.cinder.keyring

 在计算节点上把密钥加进 libvirt ,每个节点都操作
uuidgen 457eb676-33da-42ec-9a8c-9293d545c337 每个计算节点uuid可能不一样
cat > secret.xml <<EOF 457eb676-33da-42ec-9a8c-9293d545c337 client.cinder secret EOF
virsh secret-define --file secret.xml Secret 457eb676-33da-42ec-9a8c-9293d545c337 created

sudo virsh secret-set-value --secret 457eb676-33da-42ec-9a8c-9293d545c337 --base64 $(cat client.cinder.key) &&

1.3. 镜像对接:
修改部署glance服务的节点配置文件/etc/glance/glance-api.conf
[glance_store]
default_store = rbd
stores = rbd
rbd_store_pool = images
rbd_store_user = glance
rbd_store_ceph_conf = /etc/ceph/ceph.conf
rbd_store_chunk_size = 8

 重启镜像
systemctl restart openstack-glance-api

 上传镜像看看在ceph是否可以查询到,最好上传raw格式镜像
openstack image create “centos7.4-ceph” --file centos7.4-cloud.raw --disk-format raw --container-format bare --public

1.3.1. nova对接
各个计算节点修改/etc/nova/nova.conf
[libvirt]
images_type = rbd
images_rbd_pool = vms
images_rbd_ceph_conf = /etc/ceph/ceph.conf
rbd_user = cinder
rbd_secret_uuid = 192ff8f8-2e80-4b5f-abcf-9792ccc5a91f #对应每个计算节点的uuid
disk_cachemodes=“network=writeback”
inject_password = false
inject_key = false
inject_partition = -2
live_migration_flag=“VIR_MIGRATE_UNDEFINE_SOURCE,VIR_MIGRATE_PEER2PEER,VIR_MIGRATE_LIVE,VIR_MIGRATE_PERSIST_DEST,VIR_MIGRATE_TUNNELLED”
hw_disk_discard = unmap

重启计算节点
systemctl restart openstack-nova-compute.service

1.3.2. 配置cinder
各个存储节点修改 /etc/cinder/cinder.conf
[DEFAULT]
enabled_backends = ceph
[ceph]默认没有这个框,一定要加上!
volume_driver = cinder.volume.drivers.rbd.RBDDriver
rbd_pool = volumes
rbd_ceph_conf = /etc/ceph/ceph.conf
rbd_flatten_volume_from_snapshot = false
rbd_max_clone_depth = 5
rbd_store_chunk_size = 4
rados_connect_timeout = -1
glance_api_version = 2
rbd_user = cinder
rbd_secret_uuid = 192ff8f8-2e80-4b5f-abcf-9792ccc5a91f

### OpenStack 中使用 ceph-deploy 部署 Ceph 集群的思维导图 在 OpenStack 环境下,Ceph 是一种常用的分布式存储解决方案。通过 `ceph-deploy` 工具可以简化 Ceph 集群的部署过程[^1]。以下是关于如何使用 `ceph-deploy` 在 OpenStack 中部署 Ceph 集群的一个思维导图概述: #### 1. 准备工作 - **环境准备** - 安装操作系统(推荐 CentOS 或 Ubuntu) - 更新系统软件包 - 关闭防火墙或配置允许的端口范围 - **节点规划** - 至少三个节点用于 Ceph 的 Monitor 和 OSD 功能 - 明确各节点的角色分配(Monitor、OSD) #### 2. 安装 ceph-deploy ```bash sudo yum install ceph-deploy # 对于 CentOS/RHEL # 或者 sudo apt-get install ceph-deploy # 对于 Debian/Ubuntu ``` #### 3. 初始化集群 - 创建一个新的目录作为工作空间 ```bash mkdir my-cluster && cd my-cluster ``` - 使用 `ceph-deploy new` 命令初始化集群配置文件 ```bash ceph-deploy new node1 node2 node3 ``` #### 4. 配置 Ceph Monitors - 将监控节点安装到指定服务器上 ```bash ceph-deploy mon create-initial ``` #### 5. 添加 OSDs - 准备磁盘设备供 Ceph 使用 ```bash ssh node1 sudo ceph-disk prepare /dev/sdb ``` - 激活磁盘并将其加入集群 ```bash ssh node1 sudo ceph-disk activate /dev/sdb1 ``` #### 6. 测试与验证 - 查看集群状态 ```bash ceph status ``` - 确认健康状况是否正常 (`HEALTH_OK`) - 如果有警告或错误信息,则需排查具体原因。 #### 7. 整合至 OpenStack - 修改 Cinder 后端配置以支持 RBD 存储池 ```ini enabled_backends = rbd rbd_pool = volumes rbd_user = cinder rbd_secret_uuid = <secret-uuid> ``` - 重启相关服务使更改生效 ```bash systemctl restart openstack-cinder-volume.service ``` --- ### 参考代码示例 以下是一个简单的脚本片段,展示如何自动化部分部署流程: ```python import subprocess def deploy_ceph(nodes): commands = [ f"mkdir ~/my-cluster", f"cd ~/my-cluster", f"ceph-deploy new {' '.join(nodes)}", f"ceph-deploy mon create-initial" ] for cmd in commands: result = subprocess.run(cmd, shell=True, check=True) print(f"{cmd} executed with code {result.returncode}") deploy_ceph(["node1", "node2", "node3"]) ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值