采用CEPH实现Openstack统一存储

Ceph作为Linux PB级分布式文件系统,因其灵活智能可配置,在软件定义存储的大潮中,越来越受到IaaS方案提供商的注意。我们知道OpenStack中围绕虚拟机主要的存储需求来自于nova中的 disk,glance中的image,cinder中的虚拟硬盘,本文中,我们将全部采用ceph作为这些存储的后端,摆脱现有部署中各搞一套的现状。本文主要是对Ceph使用的总结,因个人环境不同,可能存在各种环境与包依赖等问题。集成逻辑图如下。

CEPH底层为RADOS块设备,提供访问RADOS的是librados 库,librad的调用就是基于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,为下面粘贴部分的后四行。
  5. [root@client ceph ]# cat /etc/hosts
  6. 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
  7. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  8. 192.168.122.149 mds
  9. 192.168.122.169 osd
  10. 192.168.122.41 mon
  11. 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来做部署,这时最好建个目录,存放一些生成文件,避免在其他目录中与已有文件交杂在一起
  2. [root@client ~]# mkdir ceph
  3. [root@client ~]# cd ceph
    建立一个集群包含mds osd mon
  4. [root@client ceph]# ceph-deploy new mds mon osd # 必须使用hostname
    安装ceph在三个节点上。
  5. [root@client ceph]# ceph-deploy install mds mon osd
    安装monitor
  6. [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
  7. [root@client ceph]# ceph-deploy gatherkeys mds #用其中一个节点即可
  8. [root@client ceph]# ls
  9. ceph.bootstrap-mds.keyring ceph.bootstrap-osd.keyring ceph.client.admin.keyring ceph.conf ceph.log ceph.mon.keyring
  10. 建立osd,默认是基于xfs文件系统,并激活。
  11. [root@client ceph]# ceph-deploy osd prepare mds:/opt/ceph mds:/opt/cephmon:/opt/ceph
  12. [root@client ceph]# ceph-deploy osd activate mds:/opt/ceph mds:/opt/cephmon:/opt/ceph
    创建metadata服务器
  13. [root@client ceph]# ceph-deploy mds create mds
    这里插一段[如果只做ceph与openstack集成,请无视它]
  • 如果到此位止,我们仅想把这个文件系统mount到client端,我们需要安装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
  8. [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
  9. [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 中加上后面的几行。
  10. [root@clientceph]# cat /etc/ceph/ceph.conf
  11. [global]
  12. auth_service_required= cephx
  13. filestore_xattr_use_omap= true
  14. auth_client_required= cephx
  15. auth_cluster_required= cephx
  16. mon_host= 192.168.122.149,192.168.122.169,192.168.122.41
  17. mon_initial_members= mds, osd, mon
  18. fsid= 3493ee7b-ce67-47ce-9ce1-f5d6b219a709
  19. [client.volumes] #此行开始是加的
  20. keyring= /etc/ceph/client.volumes.keyring
  21. [client.images]
  22. 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. client.volumes secret
  4. EOF
  5. [root@client ~]# sudo virsh secret-define --file secret.xml
  6. Secret ce31d8b1-62b5-1561-a489-be305336520a created
  7. [root@client ~]# sudo virsh secret-set-value --secret ce31d8b1-62b5-1561-a489-be305336520a --base64 $(cat client.volumes.key) &&rm client.volumes.key secret.xml
  8. Secret value set
  9. rm:是否删除普通文件 “client.volumes.key”?y
  10. rm:是否删除普通文件 “secret.xml”?y
    修改配置文件
    /etc/glance/glance-api.conf
  11. default_store = rbd
  12. show_image_direct_url = True
  13. bd_store_user = images
  14. rbd_store_pool = images
    /etc/cinder/cinder.conf
  15. volume_driver=cinder.volume.drivers.rbd.RBDDriver
  16. rbd_pool=volumes
  17. rbd_user=volumes
  18. rbd_secret_uuid=ce31d8b1-62b5-1561-a489-be305336520a
    /etc/nova/nova.conf
  19. images_type=rbd
  20. images_rbd_pool=volumes
  21. rbd_user=volumes
  22. rbd_secret_uuid=ce31d8b1-62b5-1561-a489-be305336520a
    接着重启glance-api, cinder-volume,nova-compute
  23. [root@clientceph]# service openstack-glance-api restart
  24. Stoppingopenstack-glance-api: [ OK ]
  25. Startingopenstack-glance-api: [ OK ]
  26. [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
  27. ±-----------------±-------------------------------------+
  28. |Property | Value |
  29. ±-----------------±-------------------------------------+
  30. |checksum | d972013792949d0d3ba628fbe8685bce |
  31. |container_format | bare |
  32. |created_at | 2014-06-24T08:49:43 |
  33. |deleted | False |
  34. |deleted_at | None |
  35. |disk_format | qcow2 |
  36. |id | 77b79879-addb-4a22-b750-7f0ef51ec154 |
  37. |is_public | True |
  38. |min_disk | 0 |
  39. |min_ram | 0 |
  40. |name | cirros |
  41. |owner | f17fbd28fa184a39830f14a2e01a3b70 |
  42. |protected | False |
  43. |size | 13147648 |
  44. |status | active |
  45. |updated_at | 2014-06-24T08:50:01 |
  46. |virtual_size | None |
  47. ±-----------------±-------------------------------------+
  48. [root@clientceph]# glance index
  49. ID Name DiskFormat Container Format Size

  50. 77b79879-addb-4a22-b750-7f0ef51ec154cirros qcow2 bare 13147648
  51. [root@client ceph]# service openstack-cinder-volume restart
  52. Stopping openstack-cinder-volume: [ OK ]
  53. Starting openstack-cinder-volume: [ OK ]
  54. [root@client ceph]# cinder create –display-name test-ceph 1
  55. [root@client ceph]# cinder list
  56. ±-------------------------------------±----------±-------------±-----±------------±---------±------------+
  57. | ID | Status | Display Name | Size| Volume Type | Bootable | Attached to |
  58. ±-------------------------------------±----------±-------------±-----±------------±---------±------------+
  59. |1cc908d0-bbe9-4008-a10f-80cf1aa53afb | available | test-ceph | 1 | None | false | |
  60. ±-------------------------------------±----------±-------------±-----±------------±---------±------------+
  61. [root@client ceph]# service openstack-nova-compute restart
  62. Stopping openstack-nova-compute: [ OK ]
  63. Starting openstack-nova-compute: [ OK ]
  64. [root@client ceph]# nova boot --image image1 --flavor 1 xiao-new
  65. [root@client ceph]# nova list
  66. ±-------------------------------------±----------±-------±-----------±------------±--------------------+
  67. | ID | Name | Status | Task State | Power State | Networks |
  68. ±-------------------------------------±----------±-------±-----------±------------±--------------------+
  69. | f6b04300-2d60-47d3-a65b-2d4ce32eeced | xiao-new | ACTIVE | - | Running | net_local=10.0.1.33 |
  70. ±-------------------------------------±----------±-------±-----------±------------±--------------------+
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值