溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

如何實(shí)現(xiàn)Ceph librados編程訪問

發(fā)布時間:2021-12-17 10:12:47 來源:億速云 閱讀:163 作者:小新 欄目:云計算

這篇文章主要介紹了如何實(shí)現(xiàn)Ceph librados編程訪問,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

引言 

我需要針對Ceph的對象存儲直接進(jìn)行編程訪問,看看用網(wǎng)關(guān)和不用網(wǎng)關(guān)下的性能差別?;趃ate-way進(jìn)行訪問例子已經(jīng)走通?,F(xiàn)在 要測的是不走網(wǎng)關(guān),用librados直接和Ceph集群打交道。 

環(huán)境配置
 1. Ceph集群:你要有一個已經(jīng)配置好的Ceph集群,通過ceph -s可以看到集群的狀態(tài)。
如何實(shí)現(xiàn)Ceph librados編程訪問

2. 開發(fā)庫安裝 我的系統(tǒng)是CentOS6.5 采用如下命令安裝相關(guān)開發(fā)包(C/C++開發(fā)包)

sudo yum install librados2-devel

安裝成功后,你可以在/usr/include/rados路徑下看到相應(yīng)的頭文件 如何實(shí)現(xiàn)Ceph librados編程訪問

示例程序
該實(shí)例程序來自官網(wǎng),可參官網(wǎng)實(shí)例
http://docs.ceph.com/docs/master/rados/api/librados-intro/

#include <rados/librados.hpp>
#include <string>
#include <list>
int main(int argc, const char **argv)
{
int ret = 0 ;
// Get cluster handle and connect to cluster
std::cout<<"ceph Cluster connect begin."<<std::endl;
std::string cluster_name("ceph");
std::string user_name("client.admin");
librados::Rados cluster ;
ret = cluster.init2(user_name.c_str(), cluster_name.c_str(), 0);
if (ret < 0)
{
std::cerr << "Couldn't initialize the cluster handle! error ">

編譯指令

g++ -g -c cephclient.cxx -o cephclient.o
g++ -g cephclient.o -lrados -o cephclient

結(jié)果輸出

[root@gnop029-ct-zhejiang_wenzhou-16-34 ceph-rados]# ./cephclient 
ceph Cluster connect begin.
Created a cluster handle.
Read the Ceph configuration file Succeed.
Connected to the cluster.
ceph Cluster connect end.
ceph Cluster create io context for pool begin.
Created an ioctx for the pool.
ceph Cluster create io context for pool end.
Write an object synchronously begin.
Wrote new object 'hw' 
Write an object synchronously end.
Object name: hw
Content: Hello World!
Object xattr: en_US
List of pools from this cluster handle
rbd
pool-1
pool-2
.rgw
.rgw.root
.rgw.control
.rgw.gc
.rgw.buckets
.rgw.buckets.index
.log
.intent-log
.usage
.users
.users.email
.users.swift
.users.uid
List of objects from this pool
rb.0.d402.238e1f29.00000000ee00
rb.0.d402.238e1f29.000000015000
rb.0.d402.238e1f29.00000000fa2f
rb.0.d402.238e1f29.00000001ac00
rb.0.d402.238e1f29.000000012000

接口說明
實(shí)例代碼中包含了主要的接口,有:
1. 集群句柄創(chuàng)建
2. 集群連接
3. IO上下文環(huán)境初始化
4. 對象讀寫
5. IO上下文環(huán)境關(guān)閉
6. 集群句柄關(guān)閉

感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“如何實(shí)現(xiàn)Ceph librados編程訪問”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習(xí)!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI