[OpenStack 存储] Nova,Glance与Cinder 基于Ceph的统一存储方案

本文详细介绍了如何在OpenStack环境中整合Ceph存储系统,包括安装部署、配置与Nova、Glance、Cinder的集成,解决相关依赖与环境配置问题,实现资源高效管理和存储优化。

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


http://blog.youkuaiyun.com/juvxiao/article/details/35254613


Ceph作为Linux PB级分布式文件系统,因其灵活智能可配置, 在软件定义存储的大潮中,越来越受到iass方案提供商的注意。

我们知道OpenStack中围绕虚拟机主要的存储需求来自于nova中的disk,glance中的image,cinder中的虚拟硬盘,本文中,我们将全部采用ceph作为这些存储的后端,摆脱现有部署中各搞一套的现状。本文主要主要是对Ceph使用的总结,因个人环境不同,可能存在各种环境与包依赖等问题,本人就遇到了qemu的版本不够,iptables等问题,欢迎交流微笑。先画个集成逻辑图


CEPH底层为RADOS存储,提供访问RADOS的是librados库,librbd的调用就是基于librados,Nova只要是通过libvirt->qemu来调用librbd,所以我们知道暂时只有libvirtDriver支持,Cinder与Glance直接调用librbd。

CEPH存储集群中的层次结构也可见上图,主要是先文件条带化为obj, obj通过hash函数映射到PG(上图中Pool就是PG的容器),PG通过CRUSH算法均匀映射到OSD,OSD基于文件系统,比如xfs,ext4等等。

本文中将只使用三个osd(官方推荐是至少两个, 一个无法应对故障), 三个监视器(主要负责接受数据上报, 提供cluster map, 至少要三个, 一个不好容灾,奇数个可确保PAXOS算法能确定一批监视器里哪个版本的集群运行图是最新的) , 只放了一个mds,  这样的搭配基本是测试环境下最小的配置了,ceph很强调它的扩展性, 所以越多越好, 越能体现其优势

本文使用的系统环境: redhat6.5 四台机器 规划如下:

  1. mds 192.168.122.149 装一个mds 一个mon, 一个osd  
  2. osd 192.168.122.169 装一个mon, 一个osd  
  3. mon 192.168.122.41 装 一个mon, 一个osd  
  4. client 192.168.122.104 上安装openstack all-in-one,管理节点  

三台机器组成ceph存储集群,hostname分别为mds,osd,mon,下文将都是使用这些短的hostname代表节点,其中在这三台机器上都部署monitor和对象存储osd,在mds上部署metadata服务器mds,另外一台机器作为openstack all-in-one环境节点 hostname:client

采用ceph-deploy来部署安装ceph, 这个类似与我们部署openstack用的chef。非常方便。

第一步:  在管理节点上修改/etc/hosts,ceph-deploy 后面的节点参数必须使用hostname,为了能够解析hostname,需要配置/etc/hosts,为下面粘贴部分的后四行。

  1. [root@client ceph ]# cat /etc/hosts  
  2. 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4  
  3. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6  
  4. 192.168.122.149 mds  
  5. 192.168.122.169 osd  
  6. 192.168.122.41 mon  
  7. 192.168.122.104 client  


第二步:配置管理节点无密码访问其他节点,这个是方便我们使用ceph-deploy部署安装ceph

  1. [root@client install]# ssh-keygen  
  2. [root@client install]# ssh-copy-id mds  
  3. [root@client install]# ssh-copy-id ods  
  4. [root@client install]# ssh-copy-id mon  


第三步:在client上添加yum源文件ceph.repo 使用最新版本 firefly, 本地环境是redhat 6.5, 所以baseurl中用rhel6, 本机为64位系统,后面的目录也使用的x86_64, 如下

  1. [root@client~]# cat /etc/yum.repos.d/ceph.repo  
  2. [Ceph]  
  3. name=Cephpackages for $basearch  
  4. gpgkey=https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/release.asc  
  5. enabled=1  
  6. baseurl=http://ceph.com/rpm-firefly/rhel6/x86_64  
  7. priority=1  
  8. gpgcheck=1  
  9. type=rpm-md  
  10. [ceph-source]  
  11. name=Cephsource packages  
  12. gpgkey=https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/release.asc  
  13. enabled=1  
  14. baseurl=http://ceph.com/rpm-firefly/rhel6/SRPMS  
  15. priority=1  
  16. gpgcheck=1  
  17. type=rpm-md  
  18. [Ceph-noarch]  
  19. name=Cephnoarch packages  
  20. gpgkey=https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/release.asc  
  21. enabled=1  
  22. baseurl=http://ceph.com/rpm-firefly/rhel6/noarch  
  23. priority=1  
  24. gpgcheck=1  
  25. type=rpm-md  


第四步: 安装ceph

  1. [root@client~]# yum -y install ceph-deploy  
本文使用 ceph-deploy来做部署,这时最好建个目录,存放一些生成文件,避免在其他目录中与已有文件交杂在一起。
  1. [root@client ~]# mkdir ceph  
  2. [root@client ~]# cd ceph  

建立一个集群包含mds osd mon

  1. [root@client ceph]# ceph-deploy new mds mon osd # 必须使用hostname  

安装ceph在三个节点上。

  1. [root@client ceph]# ceph-deploy install mds mon osd  

安装monitor

  1. [root@client ceph]# ceph-deploy mon create mds mon osd  
收集 keyring文件, Note: 做这个时候,这个如果 mds mon osd上防火墙开着, 会收集不到,建议关掉,不然就要通过 iptables设置相关rule,

不关报的错是:[ceph_deploy.gatherkeys][WARNIN]Unable to find /var/lib/ceph/bootstrap-mds/ceph.keyring

  1. [root@client ceph]# ceph-deploy gatherkeys mds #用其中一个节点即可  
  2. [root@client ceph]# ls  
  3. ceph.bootstrap-mds.keyring  ceph.bootstrap-osd.keyring  ceph.client.admin.keyring  ceph.conf  ceph.log  ceph.mon.keyring  
  4. 建立osd,默认是基于xfs文件系统,并激活。  
  1. [root@client ceph]# ceph-deploy osd prepare mds:/opt/ceph mds:/opt/cephmon:/opt/ceph  
  2. [root@client ceph]# ceph-deploy osd activate mds:/opt/ceph mds:/opt/cephmon:/opt/ceph  
创建 metadata服务器
  1. [root@client ceph]# ceph-deploy mds create mds  
这里插一段[如果只做ceph与openstack集成,请无视它]

* 如果到此位止,我们仅想把这个文件系统mountclient端,我们需要安装ceph-fuse

  1. [root@client ceph]# yum -y install ceph-fuse  
  2. [root@client ceph]#  
  3. [root@client ceph]# ceph-fuse -m 192.168.122.169:6789 /mnt/ceph  
  4. ceph-fuse[24569]:starting ceph client  
  5. ceph-fuse[24569]:starting fuse  
  6. [root@client ceph]# df  
  7. Filesystem 1K-blocks Used Available Use%Mounted on  
  8. /dev/mapper/vg_client-lv_root 18069936 2791420 14360604 17% /  
  9. tmpfs 812188 4 812184 1%/dev/shm  
  10. /dev/vda1 495844 34541 435703 8% /boot  
  11. /etc/swift/data/drives/images/swift.img 1038336 32976 1005360 4% /etc/swift/data/drives/sdb1  
  12. ceph-fuse 54304768 25591808 28712960 48%/mnt/ceph #这一行  

第五步: 整合到nova,glance 和cinder的使用上
  1. [root@client ceph]# yum install ceph  
  2. [root@client ceph]# rados mkpool volumes  
  3. [root@client ceph]# rados mkpool images  
  4. [root@client ceph]# ceph osd pool set volumes size 3  
  5. [root@client ceph]# ceph osd pool set images size 3   
  6. [root@client ceph]# ceph osd lspools  
  7. 0data,1 metadata,2 rbd,4 volumes,5 images,  

keyring

  1. [root@client ceph]# ceph auth get-or-create client.volumes mon 'allow r' osd 'allow class-read object_prefix rbd_children, allow rwx pool=volumes,allow rx pool=images' -o /etc/ceph/client.volumes.keyring  
  2. [root@client ceph]# ceph auth get-or-create client.images mon 'allow r' osd 'allow class-read object_prefix rbd_children, allow rwx pool=images' -o /etc/ceph/client.images.keyring   

在ceph.conf 中加上后面的几行。

  1. [root@clientceph]# cat /etc/ceph/ceph.conf  
  2. [global]  
  3. auth_service_requiredcephx  
  4. filestore_xattr_use_omaptrue  
  5. auth_client_requiredcephx  
  6. auth_cluster_requiredcephx  
  7. mon_host192.168.122.149,192.168.122.169,192.168.122.41  
  8. mon_initial_membersmds, osd, mon  
  9. fsid3493ee7b-ce67-47ce-9ce1-f5d6b219a709  
  10.   
  11. [client.volumes] #此行开始是加的  
  12. keyring= /etc/ceph/client.volumes.keyring  
  13. [client.images]  
  14. keyring= /etc/ceph/client.images.keyring  

一定要加上,不然 glance image upload的时候会报如下错

Requestreturned failure status.

500Internal Server Error

GL-F9EE247Failed to upload image 1c3d2523-9752-4644-89c2-b066428144fd

(HTTP500)

本文中安装的qemu,libvirt均为新版本,版本过低可能存在rbd的支持问题。编译安装的方法为qemu安装libvirt安装

问题: qemu版本问题,必须能支持rbd格式的,因为libvirt就是通过qemu相关命令与ceph存储交互,可通过"qemu-img–help”察看。

qemu-img version 0.12.1,

Supported formats: raw cow qcow vdi vmdk cloop dmg bochs vpc vvfat qcow2 qedvhdx parallels nbd blkdebug host_cdrom host_floppy host_device filegluster gluster gluster gluster

可以看到0.12.1不支持rbd,要装0.15以上的】

为了集成nova, 先做如下给libvirt创建密钥的操作,这个密钥在qemu执行创建image命令时会使用到,应在nova-compute服务运行的节点上执行如下操作。本文使用all-in-one,所以直接在client节点执行

  1. [root@client ~]#ceph auth get-key client.volumes | ssh client tee client.volumes.key #ssh后紧跟的是本机的hostname  
  2. [root@client ~]# cat > secret.xml << EOF  
  3. <secret ephemeral = 'no' private = 'no'>  
  4. <usage type = 'ceph'>  
  5. <name>client.volumes secret</name>  
  6. </usage>  
  7. </secret>  
  8. EOF  
  9. [root@client ~]# sudo virsh secret-define --file secret.xml  
  10. Secret ce31d8b1-62b5-1561-a489-be305336520a created  
  11.   
  12. [root@client ~]# sudo virsh secret-set-value --secret ce31d8b1-62b5-1561-a489-be305336520a --base64 $(cat client.volumes.key) &&rm client.volumes.key secret.xml  
  13. Secret value set  
  14.   
  15. rm:是否删除普通文件 "client.volumes.key"?y  
  16. rm:是否删除普通文件 "secret.xml"?y  
修改配置文件

/etc/glance/glance-api.conf

  1. default_store = rbd  
  2. show_image_direct_url = True  
  3. bd_store_user = images  
  4. rbd_store_pool = images  
/etc/cinder/cinder.conf
  1. volume_driver=cinder.volume.drivers.rbd.RBDDriver  
  2. rbd_pool=volumes  
  3. rbd_user=volumes  
  4. rbd_secret_uuid=ce31d8b1-62b5-1561-a489-be305336520a  

/etc/nova/nova.conf

  1. images_type=rbd  
  2. images_rbd_pool=volumes  
  3. rbd_user=volumes  
  4. rbd_secret_uuid=ce31d8b1-62b5-1561-a489-be305336520a  

接着重启glance-api, cinder-volume,nova-compute

  1. [root@clientceph]# service openstack-glance-api restart  
  2. Stoppingopenstack-glance-api: [ OK ]  
  3. Startingopenstack-glance-api: [ OK ]  
  4. [root@clientceph]# glance image-create --disk-format qcow2 --is-public True --container-format bare --file cirros-0.3.1-x86_64-disk.img --name cirros  
  5. +------------------+--------------------------------------+  
  6. |Property | Value |  
  7. +------------------+--------------------------------------+  
  8. |checksum | d972013792949d0d3ba628fbe8685bce |  
  9. |container_format | bare |  
  10. |created_at | 2014-06-24T08:49:43 |  
  11. |deleted | False |  
  12. |deleted_at | None |  
  13. |disk_format | qcow2 |  
  14. |id | 77b79879-addb-4a22-b750-7f0ef51ec154 |  
  15. |is_public | True |  
  16. |min_disk | 0 |  
  17. |min_ram | 0 |  
  18. |name | cirros |  
  19. |owner | f17fbd28fa184a39830f14a2e01a3b70 |  
  20. |protected | False |  
  21. |size | 13147648 |  
  22. |status | active |  
  23. |updated_at | 2014-06-24T08:50:01 |  
  24. |virtual_size | None |  
  25. +------------------+--------------------------------------+  
  26. [root@clientceph]# glance index  
  27. ID Name DiskFormat Container Format Size  
  28. ------------------------------------------------------------------ ---------------------------------------- --------------  
  29. 77b79879-addb-4a22-b750-7f0ef51ec154cirros qcow2 bare 13147648  
  30.   
  31. [root@client ceph]# service openstack-cinder-volume restart  
  32. Stopping openstack-cinder-volume:                          [  OK  ]  
  33. Starting openstack-cinder-volume:                          [  OK  ]  
  34. [root@client ceph]# cinder create –display-name test-ceph 1  
  35. [root@client ceph]# cinder list  
  36. +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+  
  37. | ID | Status | Display Name | Size| Volume Type | Bootable | Attached to |  
  38. +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+  
  39. |1cc908d0-bbe9-4008-a10f-80cf1aa53afb | available | test-ceph | 1 | None | false | |  
  40. +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+  
  41. [root@client ceph]# service openstack-nova-compute restart  
  42. Stopping openstack-nova-compute:                          [  OK  ]  
  43. Starting openstack-nova-compute:                          [  OK  ]  
  44. [root@client ceph]# nova boot --image image1 --flavor 1 xiao-new    
  45. [root@client ceph]# nova list  
  46. +--------------------------------------+-----------+--------+------------+-------------+---------------------+  
  47. | ID                                   | Name      | Status | Task State | Power State | Networks            |  
  48. +--------------------------------------+-----------+--------+------------+-------------+---------------------+  
  49. | f6b04300-2d60-47d3-a65b-2d4ce32eeced | xiao-new | ACTIVE  | -   | Running     | net_local=10.0.1.33 |  
  50. +--------------------------------------+-----------+--------+------------+-------------+---------------------+  
最后附上ceph相关资料的链接

1. ceph英文使用文档

2. ceph中文使用文档

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值