riak文件服务器,riak简介(一)
本人機(jī)子為ubuntu。所以安裝比較簡(jiǎn)單
sudo apt-get install openssl
sudo apt-get install erlang下載deb包安裝
wget -c http://s3.amazonaws.com/downloads.basho.com/riak/2.0/2.0.2/ubuntu/trusty/riak_2.0.2-1_amd64.deb
dpkg -i riak_2.0.2-1_amd64.deb
就此安裝完成。喜歡用源碼安裝的同學(xué)也請(qǐng)考慮上面的依賴。不難,只不過可能有點(diǎn)麻煩。
啟動(dòng)riak服務(wù)
sudo riak start
具體的配置文件請(qǐng)看
/etc/riak/riak.conf
http默認(rèn)的監(jiān)聽端口為
127.0.0.1:8098
因?yàn)槭堑谝黄?#xff0c;所以暫時(shí)使用單節(jié)點(diǎn),講解簡(jiǎn)單的操作。
添加
curl -i -H "Content-Type: plain/text" -d "Some text" http://localhost:8098/riak/foo返回:
HTTP/1.1 201 Created
Vary: Accept-Encoding
Server: MochiWeb/1.1 WebMachine/1.10.5 (jokes are better explained)
Location: /riak/foo/86qDc77dbesWX651mgSYKLqSDSW
Date: Mon, 12 Jan 2015 15:10:58 GMT
Content-Type: plain/text
Content-Length: 0上面使用的是hash key。當(dāng)然,我們可以使用指定的key:
curl -i -d '{"name":"Bruce"}' -H "Content-Type: application/json" http://localhost:8098/riak/artists/Bruce返回:
HTTP/1.1 204 No Content
Vary: Accept-Encoding
Server: MochiWeb/1.1 WebMachine/1.10.5 (jokes are better explained)
Date: Mon, 12 Jan 2015 15:22:23 GMT
Content-Type: application/json
Content-Length: 0觀察可以看到如果我們存儲(chǔ)文本成功的時(shí)候返回的代碼為201.存儲(chǔ)對(duì)象成功的時(shí)候返回的是204 No Content。另外值得注意的地方還有Content-Type.通過修改Conten-Type,我們可以存儲(chǔ)圖像等其他mime類型消息。
查詢
curl -i http://localhost:8098/riak/artists/Bruce返回:
HTTP/1.1 200 OK
X-Riak-Vclock: a85hYGBgzGDKBVIcypz/fj7T3PktgymRMY+VYX2Sxjm+LAA=
Vary: Accept-Encoding
Server: MochiWeb/1.1 WebMachine/1.10.5 (jokes are better explained)
Link: ; rel="up"
Last-Modified: Mon, 12 Jan 2015 15:22:23 GMT
ETag: "41UXK3bSSH2tRZ4Ft6OlKH"
Date: Mon, 12 Jan 2015 15:35:38 GMT
Content-Type: application/json
Content-Length: 16
{"name":"Bruce"}
更新
curl -i -X PUT -d '{"name":"Bruce", "nickname":"The Boss"}' -H "Content-Type: application/json" http://localhost:8098/riak/artists/Bruce返回:
HTTP/1.1 204 No Content
Vary: Accept-Encoding
Server: MochiWeb/1.1 WebMachine/1.10.5 (jokes are better explained)
Date: Mon, 12 Jan 2015 15:40:35 GMT
Content-Type: application/json
Content-Length: 0
刪除
curl -i -X DELETE http://localhost:8098/riak/artists/Bruce返回:
BruceHTTP/1.1 204 No Content
Vary: Accept-Encoding
Server: MochiWeb/1.1 WebMachine/1.10.5 (jokes are better explained)
Date: Mon, 12 Jan 2015 15:43:02 GMT
Content-Type: application/json
Content-Length: 0刪除了之后再去Get得到的是404
riak的基礎(chǔ)操作介紹的差不多了。作為一個(gè)web開發(fā)者,感嘆其實(shí)現(xiàn)的RESTful如此優(yōu)雅。
總結(jié)
以上是生活随笔為你收集整理的riak文件服务器,riak简介(一)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c++无序容器
- 下一篇: 张宇考研数学闭关修炼【解析分册】