採用libs3進行簡單的ceph radosgw測試和使用

1.引言

通常狀況下推薦使用s3cmd工具進行ceph對象存儲的體驗與測試,可是我須要提供C/C++的sdk包,因此將注意力集中在了libs3上,並採用libs3的命令進行測試,效果與s3cmd相似。命令參數稍有不一樣。欲深刻理解請閱讀源碼,本文做入門級使用說明。java

2. 編譯安裝

2.1 源碼下載

github libs3源碼下載路徑linux

請採用git clone的方式從服務器下載源碼。nginx

2.2 源碼編譯安裝

源碼下載後目錄以下:git

# ll -h
total 136K
drwxr-xr-x 2 root root 4.0K Jan  8 13:59 archlinux
drwxr-xr-x 7 root root 4.0K Jan  8 13:59 build
-rw-r--r-- 1 root root  653 Jan  5 14:57 ChangeLog
-rw-r--r-- 1 root root 7.5K Jan  5 14:57 COPYING
drwxr-xr-x 2 root root 4.0K Jan  8 13:59 debian
-rw-r--r-- 1 root root  35K Jan  5 14:57 doxyfile
-rw-r--r-- 1 root root  14K Jan  5 14:57 GNUmakefile
-rw-r--r-- 1 root root 9.7K Jan  5 14:57 GNUmakefile.mingw
-rw-r--r-- 1 root root 9.9K Jan  5 14:57 GNUmakefile.osx
drwxr-xr-x 3 root root 4.0K Jan  8 13:59 inc
-rw-r--r-- 1 root root 2.4K Jan  5 14:57 INSTALL
-rw-r--r-- 1 root root 2.2K Jan  5 14:57 libs3.spec
-rw-r--r-- 1 root root  846 Jan  5 14:57 LICENSE
drwxr-xr-x 2 root root 4.0K Jan  8 13:59 mswin
-rw-r--r-- 1 root root  126 Jan  5 14:57 README
drwxr-xr-x 2 root root 4.0K Feb 19 11:10 src
drwxr-xr-x 2 root root 4.0K Jan  8 13:59 test
-rw-r--r-- 1 root root 3.0K Jan  5 14:57 TODO

簡單說明: inc 頭文件 src 實現文件 build 用於存放編譯好的庫、可執行文件github

執行命令make install便可編譯安裝服務器

# make install
/usr/bin/s3: Installing executable
/usr/lib/libs3.so.2.0: Installing shared library
/usr/lib/libs3.so.2: Linking shared library
/usr/lib/libs3.so: Linking shared library
/usr/lib/libs3.a: Installing static library
/usr/include/libs3.h: Installing header

這裏要注意的是,在使用s3命令的時候,須要先設置參數:eclipse

export S3_ACCESS_KEY_ID="JD1**************TCI4"
export S3_SECRET_ACCESS_KEY="88sAejI*************F4oHTLnqD"
export S3_HOSTNAME="183.*.*.*"

3.使用

對象存儲主要有以下幾個關鍵操做: 羅列用戶全部的bucket
羅列某個bucket下的對象
建立bucket
刪除bucket 向某個bucket中上傳對象 刪除bucket中的某個對象 下載某個bucket中的對象工具

下面針對這些操做進行一一說明:測試

3.1 羅列當前用戶下的全部bucket信息

# s3 -u list
                         Bucket                                 Created       
--------------------------------------------------------  --------------------
big_rd_test_bucket                                        2016-02-04T06:18:04Z
mytest                                                    2016-03-18T01:24:53Z
new_bucket1                                               2016-03-15T05:05:35Z
rd_test_bucket_fifty_mb                                   2016-03-17T22:56:56Z
wr_new_test_bucket_fifty                                  2016-03-18T01:10:00Z
wr_test_bucket_fifty_mb                                   2016-03-18T00:30:38Z

3.2 羅列bucket下的對象信息

# s3  -u list new_bucket1
                       Key                             Last Modified      Size 
--------------------------------------------------  --------------------  -----
16                                                  2016-03-15T05:11:08Z   3496
ADBlockSetup.zip                                    2016-03-17T18:21:04Z  4.55M
ZoneData                                            2016-03-17T23:20:51Z   564M
eclipse-java-mars-R-win32-x86_64.zip                2016-03-18T00:23:25Z   163M
nginx-1.6.3.tar.gz                                  2016-03-17T23:17:24Z   786K
virtual machine.big.rar                             2016-03-18T01:12:36Z  3.86G
virtual machine.rar                                 2016-03-18T00:31:29Z  1.93G

3.3 建立bucket

# s3 -u create xuwenqiang
Bucket successfully created.
# s3 -u list
                         Bucket                                 Created       
--------------------------------------------------------  --------------------
wr_test_bucket_fifty_mb                                   2016-03-18T00:30:38Z
write_test_bucket1                                        2016-03-20T18:23:53Z
xuwenqiang                                                2016-03-21T04:30:06Z

經過list命令能夠發現,BUCKET xuwenqiang被成功建立。ui

3.4 刪除bucket

# s3 -u delete xuwenqiang
# s3 -u list
                         Bucket                                 Created       
--------------------------------------------------------  --------------------
wr_new_test_bucket_fifty                                  2016-03-18T01:10:00Z
wr_test_bucket_fifty_mb                                   2016-03-18T00:30:38Z
write_test_bucket1                                        2016-03-20T18:23:53Z

經過命令能夠發現BUCKET xuwenqiang已不存在

3.5 向指定BUCKET中上傳文件

# s3 -u put new_bucket1/newkey1 filename=CephS3.o
111392 bytes remaining (12% complete) ...
95008 bytes remaining (25% complete) ...
78624 bytes remaining (38% complete) ...
62240 bytes remaining (51% complete) ...
45856 bytes remaining (64% complete) ...
29472 bytes remaining (76% complete) ...
13088 bytes remaining (89% complete) ...

3.6 刪除BUCKET中某個對象

# s3 -u list new_bucket1
                       Key                             Last Modified      Size 
--------------------------------------------------  --------------------  -----
1                                                   2016-03-21T00:34:46Z  1.00G
10                                                  2016-03-20T18:29:10Z    50M
11                                                  2016-03-20T18:29:28Z    50M
12                                                  2016-03-20T18:29:31Z    50M

# s3 -u delete write_new_bucket1/1

# s3 -u list   new_bucket1
                       Key                             Last Modified      Size 
--------------------------------------------------  --------------------  -----
10                                                  2016-03-20T18:29:10Z    50M
11                                                  2016-03-20T18:29:28Z    50M
12                                                  2016-03-20T18:29:31Z    50M
13                                                  2016-03-20T18:29:28Z    50M
14                                                  2016-03-20T18:29:29Z    50M
15                                                  2016-03-20T18:29:30Z    50M
16                                                  2016-03-20T18:29:30Z    50M

3.7 下載BUCKET中某個對象

本例子從BUCKET new_bucket1中下載ID爲10的文件到本地,命名爲currenttest

# s3 -u get new_bucket1/10 filename=currenttest
# ll -h
total 3.8G
......
-rw-r--r-- 1 root root  19K Feb  6 16:42 CephS3Test-WS.cpp
-rw-r--r-- 1 root root  50M Mar 21 20:36 currenttest
......

#4 附錄

使用前請設置環境變量 若是使用的http協議,請帶上-u選項 我基於Libs3作了一個簡易版的SDK,主要接口就是上述操做,不過將操做命令轉換爲接口便可。

相關文章
相關標籤/搜索