riak文件服务器,riak简介(一)
本人機子為ubuntu。所以安裝比較簡單
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
就此安裝完成。喜歡用源碼安裝的同學也請考慮上面的依賴。不難,只不過可能有點麻煩。
啟動riak服務
sudo riak start
具體的配置文件請看
/etc/riak/riak.conf
http默認的監聽端口為
127.0.0.1:8098
因為是第一篇,所以暫時使用單節點,講解簡單的操作。
添加
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。當然,我們可以使用指定的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觀察可以看到如果我們存儲文本成功的時候返回的代碼為201.存儲對象成功的時候返回的是204 No Content。另外值得注意的地方還有Content-Type.通過修改Conten-Type,我們可以存儲圖像等其他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的基礎操作介紹的差不多了。作為一個web開發者,感嘆其實現的RESTful如此優雅。
總結
以上是生活随笔為你收集整理的riak文件服务器,riak简介(一)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c++无序容器
- 下一篇: 张宇考研数学闭关修炼【解析分册】