openstack基于CEPH的共享盘实现方案



首先,让我们先了解下librbd I/O的协议栈


 其中VM根据libvirt通过配置文件来调用QEMU的。而块存储RBD,其实是CEPH集群的一个client而已。所以,可以控制OSD中的/etc/ceph/ceph.conf中的[client]字段的rbd_cache来决定是否开启RBD的缓存。对应图上的关系则是QEMU对应服务nova-compute,Ceph Cluster对应OSD(真实的数据读写都是为OSD)。因此配置后要先重启OSD,然后再重启nova-compute。QEMU中的qemu driver ‘writeback’(即/etc/nova/nova.conf中的disk_cachemodes)和CEPH配置文件中的rbd_cache会相互影响,因此需要设置一致的模式,防止产生不必要的麻烦。

   在CEPH官网(http://docs.ceph.org.cn/rbd/libvirt/)中,也有这么一段解释

  libvirt 库是管理程序和软件应用间的一个虚拟机抽象层。通过libvirt ,开发者和系统管理员只需要关注这些管理器的一个通用管理框架、通用 API 、和通用 shell 接口(即virsh )即可,包括:
  • QEMU/KVM

  • XEN

  • LXC

  • VirtualBox

  • 等等

  Ceph 块设备支持 QEMU/KVM ,所以你可以通过能与libvirt 交互的软件来使用 Ceph 块设备。下面的堆栈图解释了libvirt 和 QEMU 如何通过librbd 使用 Ceph 块设备。


  libvirt 常见于为云解决方案提供 Ceph 块设备,像 OpenStack 、 ClouldStack 。它们用libvirt 和 QEMU/KVM 交互、 QEMU/KVM 再通过librbd 与 Ceph 块设备交互。


 了解以上基础知识之后,我们还需要了解到CEPH到两种缓存机制,Tier和RBD cache两种机制。首先它们两者都有缓存、预读的功能,但是它们缓存的位置却不相同。tier是rados层在osd端进行数据缓存,也就是说不论是块存储、对象存储还是文件存储都可以使用tier来提高读写速度;rbd cache是rbd层在客户端的缓存,也就是只支持块存储。Rbd cache是客户端的缓存,当多个客户端使用同个块设备时(例如ocfs2),存在客户端数据不一致的问题。举个例子,用户A向块设备写入数据后,数据停留在客户自己的缓存中,没有立即刷新到磁盘,所以其它用户读取不到A写入的数据。但是tier不存在这个问题,因为所有用户的数据都直接写入到ssd,用户读取数据也是在ssd中读取的,所以不存在客户端数据不一致问题。由此可见,实现缓存盘有两种形式,一种的关闭RBD cache,另一种就是使用Tier来实现,此两者都能解决客户端数据不一致的问题。


关闭RBD cache


 因此,要OSD所在的服务器上,分别在/etc/ceph/ceph.conf中,将[client]中的两个字段修改成false


 然后重启这个节点上的所有OSD


restart ceph-osd-all

 然后在计算节点上,打开/etc/nova/nova.conf中,找到字段disk_cachemodes,将内容改成


disk_cachemodes="network=none,block=none"
 

 重启nova-compute


service nova-compute restart

 

假设云主机为ubuntu14.04,云主机A(主机名为share-1,IP地址为192.168.1.5)和云主机B(主机名为share-2,IP地址为192.168.1.6)共享一个共享盘,这个共享盘在云主机AB中的设备路径为/dev/vdb,挂载点为/ocr


在云主机A中,执行以下shell脚本

#!/bin/bash
echo "nameserver 114.114.114.114" > /etc/resolv.conf 
echo "****************************begin**************************************"
echo "make a copy..."
mv /etc/apt/sources.list /etc/apt/sources.list.bak
echo "remove old sources.list..."
rm /etc/apt/sources.list
echo "creating new sources.list..."
touch /etc/apt/sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse" >> /etc/apt/sources.list
echo " create sources.list success"
echo "update package..."
apt-get update

echo "*****************************done************************************"

apt-get install ocfs2-tools ocfs2-tools-dev ocfs2console

touch /etc/ocfs2/cluster.conf
echo "node:
        ip_port = 7777
        ip_address = 192.168.1.6
        number = 0
        name = share-2
        cluster = ocfs2
node:
        ip_port = 7777
        ip_address = 192.168.1.5
        number = 1
        name = share-1
        cluster = ocfs2
cluster:
        node_count = 2
        name = ocfs2
" > /etc/ocfs2/cluster.conf

sed -i 's/false/true/g' /etc/default/o2cb

mkdir -p /ocr
/etc/init.d/o2cb start
mkfs.ocfs2 -b 4K -C 32K -N 3 -L /ocr /dev/vdb
mount -t ocfs2  /dev/vdb /ocr
 

云主机B同样执行上述脚本,但是需将倒二行的橙色字注释掉(只需格式化一次即可)

mkfs.ocfs2 -b 4K -C 32K -N 3 -L /ocr /dev/vdb

之后,还有很重要的一步,即需要打开这两台云主机的端口7777

成功后入下图所示





使用Tier

 以下为配置缓存层示例,其中假设ruleset 0为容量盘,ruleset 1为性能盘


ceph osd pool create storage_pool 256 256
ceph osd pool create cache_pool 64 64
ceph osd pool set cache_pool crush_ruleset 1
ceph osd tier add storage_pool cache_pool
ceph osd tier cache-mode cache_pool writeback
ceph osd tier set-overlay storage_pool cache_pool
ceph osd pool set cache_pool hit_set_type bloom
ceph osd pool set cache_pool hit_set_count 1
ceph osd pool set cache_pool hit_set_period 3600
ceph osd pool set cache_pool target_max_bytes 107374182400
ceph osd pool set cache_pool target_max_objects 25600
ceph osd pool set cache_pool cache_min_flush_age 3600
ceph osd pool set cache_pool cache_min_evict_age 3600
ceph osd pool set cache_pool cache_target_dirty_ratio .6
ceph osd pool set cache_pool cache_target_full_ratio .6

 

配置完成后,在cinder服务中将底层的pool配置成cache_pool,然后重启cinder-volume使其生效,之后创建的云硬盘即是使用了Tier的RBD块,之后在云主机的配置可参考上述配置即可






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值