您好,登錄后才能下訂單哦!
一、什么是對(duì)象存儲(chǔ)
1、對(duì)象存儲(chǔ),也就是鍵值存儲(chǔ),通過(guò)其接口指令,也就是簡(jiǎn)單GET、PUT、DEL和其他擴(kuò)展指令,向存儲(chǔ)服務(wù)上傳下載數(shù)據(jù)等
2、對(duì)象存儲(chǔ)中所有數(shù)據(jù)都被認(rèn)為是一個(gè)對(duì)象。所以,任何數(shù)據(jù)都可以存入對(duì)象存儲(chǔ)服務(wù)器,如圖片、視頻、音頻等
二、Ceph 對(duì)象存儲(chǔ)的構(gòu)成
Ceph 對(duì)象存儲(chǔ)主要是通過(guò) RGW 來(lái)實(shí)現(xiàn),那么什么是 RGW 呢?
1、RGW 即 Rados Gateway 的全稱。
2、RGW 是 Ceph 對(duì)象存儲(chǔ)網(wǎng)關(guān),用于向客戶端應(yīng)用程序提供存儲(chǔ)界面,提供 RESTful API 訪問(wèn)接口。
3、RGW 可以部署多臺(tái)做為 高可用和負(fù)載均衡,拓?fù)淙缦聢D:
三、部署 RGW 服務(wù)
1、在 ceph-a 上通過(guò) ceph-deploy 將 ceph-radosgw 軟件包安裝到 ceph-e 中
[root@ceph-a ~]# ceph-deploy install --rgw ceph-e
2、將配置文件、密鑰文件同步到 ceph-e
[root@ceph-a ceph]# ceph-deploy admin ceph-e
3、啟動(dòng)一個(gè)RGW服務(wù)
[root@ceph-a ceph]# ceph-deploy rgw create ceph-e
4、登陸 ceph-e 驗(yàn)證服務(wù)是否啟動(dòng)
[root@ceph-e yum.repos.d]# ps -ef | grep radosgw
5、查看 rgw 狀態(tài)
[root@ceph-e yum.repos.d]# systemctl status ceph-radosgw\*
6、查看端口是否有監(jiān)聽(tīng)
[root@ceph-e yum.repos.d]# netstat -tpnl | grep 7480
通過(guò)以上 6 步,我們的 RGW 服務(wù)已經(jīng)可以成功運(yùn)行了。
7、RGW 內(nèi)建了一個(gè)名為 civetweb 的 web 服務(wù)器,這個(gè)服務(wù)器與 apache/nginx 類似,既然是 web 服務(wù),那么使用 80 端口就更為方便,為了應(yīng)用便捷,可以將默認(rèn)的 7480 端口修改為 80 端口。
修改 ceph-e 節(jié)點(diǎn)的 ceph.conf 配置文件,追加以下內(nèi)容:
[root@ceph-e ceph]# vim ceph.conf [client.rgw.ceph-e] host = ceph-e rgw_frontends = "civetweb port=80"
保存退出并重啟服務(wù)
[root@ceph-e ceph]# systemctl restart ceph-radosgw.target
8、查看端口是否修改成功
[root@ceph-e ceph]# netstat -tpnl
9、驗(yàn)證
打開(kāi)瀏覽器,輸入 http://192.168.20.148,如下圖
或者在命令行中輸入 curl http://192.168.20.148 \r ,\r表示發(fā)送回車鍵指令,如下如
四、使用第三方軟件訪問(wèn)
1、使用亞馬遜 s3 客戶端進(jìn)行訪問(wèn)
①、登陸 ceph-e(RGW)創(chuàng)建用戶
[root@ceph-e radosgw]# radosgw-admin user create --uid="radosgw" --display-name="First User"
user: radosgw access_key: N6ALEK0KS0ISYCIM5JBG secret_key: qK9hrpX2uwna4elPP1VsuErmAHBw3So40fE2K4yM
②、授權(quán)用戶,允許 radosgw 讀寫(xiě) users 信息:
[root@ceph-e radosgw]# radosgw-admin caps add --uid=radosgw --caps="users=*"
允許 radosgw 讀寫(xiě)所有的usage信息:
[root@ceph-e radosgw]# radosgw-admin caps add --uid=radosgw --caps="usage=read,write"
③、創(chuàng)建子用戶,做為后面 swift 客戶端訪問(wèn)時(shí)使用
[root@ceph-e radosgw]# radosgw-admin subuser create --uid=radosgw --subuser=radosgw:swift --access=full
④、創(chuàng)建密鑰
[root@ceph-e radosgw]# radosgw-admin key create --subuser=radosgw:swift --key-type=swift --gen-secret
user: radosgw:swift secret_key: NhTk42HlMcAnv2GBXqatqMPeI20eSLod30AOJLwl
⑤、在 ceph-f 安裝 s3 客戶端軟件
首先,我們找一下 yum 源有沒(méi)有 s3 的 rpm 包
[root@ceph-f ~]# yum list | grep s3
發(fā)現(xiàn),有 s3 的 rpm 包,因此直接安裝即可
[root@ceph-f ~]# yum -y install s3cmd.noarch
⑥、對(duì) s3 進(jìn)行配置
[root@ceph-f ~]# s3cmd --configure
注意:
Access Key: N6ALEK0KS0ISYCIM5JBG Secret Key: qK9hrpX2uwna4elPP1VsuErmAHBw3So40fE2K4yM Default Region [US]: #這里一定不要修改,否則后面會(huì)報(bào)錯(cuò) S3 Endpoint [s3.amazonaws.com]: 192.168.20.148 DNS-style bucket+hostname:port template for accessing a bucket [%(bucket)s.s3.amazonaws.com]: %(bucket)s.192.168.20.148 bucket #相當(dāng)于百度網(wǎng)盤(pán)的創(chuàng)建文件夾,這里是固定格式 Path to GPG program [/usr/bin/gpg]: #保持默認(rèn) Use HTTPS protocol [Yes]: no #這里寫(xiě) no ,因?yàn)闆](méi)有提供 https 端口 HTTP Proxy server name: #這里不用寫(xiě),因?yàn)闆](méi)有代理 Test access with supplied credentials? [Y/n] y Save settings? [y/N] y
⑦、客戶端測(cè)試,查看內(nèi)容
[root@ceph-f ~]# s3cmd ls
空的,因?yàn)榫拖癜俣仍票P(pán)一樣,剛申請(qǐng),沒(méi)有創(chuàng)建,所以是空的
⑧、創(chuàng)建存儲(chǔ)數(shù)據(jù)的 bucket (類似于存儲(chǔ)數(shù)據(jù)的目錄)要求 xxx_yyy 格式
[root@ceph-f ~]# s3cmd mb s3://cephdir
發(fā)現(xiàn)報(bào)錯(cuò)了,看上圖,發(fā)現(xiàn),出錯(cuò)是因?yàn)槲覀兊膶?xiě)的格式不正確,按照正確的格式重新書(shū)寫(xiě),再來(lái)一次
[root@ceph-f ~]# s3cmd mb s3://ceph_dir
如上圖,成功了
⑨、再次查看客戶端內(nèi)容
[root@ceph-f ~]# s3cmd ls
這里提供 s3 的測(cè)試腳本
[root@ceph-f ~]# yum -y install python-boto [root@ceph-f ~]# vim s3test.py
import boto.s3.connection access_key = 'N6ALEK0KS0ISYCIM5JBG' secret_key = 'qK9hrpX2uwna4elPP1VsuErmAHBw3So40fE2K4yM' conn = boto.connect_s3( aws_access_key_id=access_key, aws_secret_access_key=secret_key, host='ceph-e', port=80, is_secure=False, calling_format=boto.s3.connection.OrdinaryCallingFormat(), ) bucket = conn.create_bucket('xxx_yyy') for bucket in conn.get_all_buckets(): print "{name} {created}".format( name=bucket.name, created=bucket.creation_date, )
在使用時(shí),請(qǐng)?zhí)鎿Q自己的 access_key、secret_key、主機(jī)名和端口
2、swift 接口測(cè)試
①、需要安裝以下軟件包
[root@ceph-f ~]# yum install python-setuptools [root@ceph-f ~]# easy_install pip [root@ceph-f ~]# pip install --upgrade setuptools [root@ceph-f ~]# pip install --upgrade python-swiftclient
②、命令行訪問(wèn)
swift -A http://192.168.20.148/auth/v1.0 -U radosgw:swift -K NhTk42HlMcAnv2GBXqatqMPeI20eSLod30AOJLwl list
swift -A http://192.168.20.148/auth/v1.0 -U radosgw:swift -K NhTk42HlMcAnv2GBXqatqMPeI20eSLod30AOJLwl stat -v
這里提供 swift 的測(cè)試腳本:
[root@ceph-f ~]# vim swift.py
import swiftclient user = 'radosgw:swift' key = 'NhTk42HlMcAnv2GBXqatqMPeI20eSLod30AOJLwl' conn = swiftclient.Connection( user=user, key=key, authurl='http://192.168.20.148/auth/v1.0', ) for container in conn.get_account()[1]: print container['name']
在使用時(shí),請(qǐng)?zhí)鎿Q自己的 access_key、secret_key、authurl
到此,的 Ceph 對(duì)象存儲(chǔ)已經(jīng)完結(jié),如果各位大俠有什么不明白的地方,請(qǐng)參考官網(wǎng)文檔。
關(guān)于 Ceph 集群的實(shí)現(xiàn),請(qǐng)參閱小弟的另外一篇博文:https://blog.51cto.com/4746316/2329558
關(guān)于 Ceph 塊設(shè)備的應(yīng)用,請(qǐng)參閱小弟的另外一篇博文:https://blog.51cto.com/4746316/2330070
關(guān)于 CephFS 文件系統(tǒng)的應(yīng)用,請(qǐng)參閱小弟的另外一篇博文:https://blog.51cto.com/4746316/2330186
五、總結(jié)
Ceph 對(duì)象存儲(chǔ)目前尚不不穩(wěn)定,且官方文檔較舊,這里只做大概講解,不做深入研究。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。