以下操作基本上是follow Baho的官方指南.
http://basho.com/posts/technical/riak-quick-start-with-docker/
Step 1)设置DOCKER HOST环境变量
$ export DOCKER_HOST="tcp://127.0.0.1:4243"
Step 2) Build Riak镜像
2.1) clone github的脚本文件,运行build
$ git clone https://github.com/hectcastro/docker-riak.git
$ cd docker-riak
$ make build
2.2) 查看镜像是否成功生成.
$ docker images | egrep riak
hectcastro/riak latest b486d3732ec7 2 days ago 415.7 MB
#Note, 在我的系统上镜像是九百多M
Step 3) 运行docker container, 启动Riak
$ ./bin/start-cluster.sh
#Note, 我按照文档说明,把环境变量DOCKER_RIAK_AUTOMATIC_CLUSTERING 设置为true,依然没有自动把5个node加入一个cluster.进入docker container查看该环境变量也没有设置成功,没有仔细检查哪里设置的不对,因为手工做也不麻烦.
DOCKER_RIAK_CLUSTER_SIZE – The number of nodes in your Riak cluster (default: 5)
DOCKER_RIAK_AUTOMATIC_CLUSTERING – A flag to automatically cluster Riak (default: false)
DOCKER_RIAK_DEBUG – A flag to set -x on the cluster management scripts (default: false)
执行以下命令, 检测是否5个docker container已经运行起来.
$ sudo docker ps
[sudo] password for alex:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a394ddc81bfb hectcastro/riak "/sbin/my_init --quie" 25 hours ago Up 23 hours 0.0.0.0:32817->8087/tcp, 0.0.0.0:32816->8098/tcp riak05
83f9c5448ce9 hectcastro/riak "/sbin/my_init --quie" 25 hours ago Up 23 hours 0.0.0.0:32815->8087/tcp, 0.0.0.0:32814->8098/tcp riak04
cf06e87f2709 hectcastro/riak "/sbin/my_init --quie" 26 hours ago Up 23 hours 0.0.0.0:32813->8087/tcp, 0.0.0.0:32812->8098/tcp riak03
c94b016fcdc3 hectcastro/riak "/sbin/my_init --quie" 26 hours ago Up 23 hours 0.0.0.0:32811->8087/tcp, 0.0.0.0:32810->8098/tcp riak02
f63e1c059e89 hectcastro/riak "/sbin/my_init --quie" 26 hours ago Up 23 hours 0.0.0.0:32809->8087/tcp, 0.0.0.0:32808->8098/tcp riak01
Step 4) 把5个Riak node形成一个cluster.
分别连接到各个docker container,执行以下命令, 假设我们需要把node2,3,4,5加入到node1.
4.1) 查询node 2,3,4,5对应的docker container ID
$ sudo docker ps
[sudo] password for alex:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a394ddc81bfb hectcastro/riak "/sbin/my_init --quie" 25 hours ago Up 23 hours 0.0.0.0:32817->8087/tcp, 0.0.0.0:32816->8098/tcp riak05
83f9c5448ce9 hectcastro/riak "/sbin/my_init --quie" 25 hours ago Up 23 hours 0.0.0.0:32815->8087/tcp, 0.0.0.0:32814->8098/tcp riak04
cf06e87f2709 hectcastro/riak "/sbin/my_init --quie" 26 hours ago Up 23 hours 0.0.0.0:32813->8087/tcp, 0.0.0.0:32812->8098/tcp riak03
c94b016fcdc3 hectcastro/riak "/sbin/my_init --quie" 26 hours ago Up 23 hours 0.0.0.0:32811->8087/tcp, 0.0.0.0:32810->8098/tcp riak02
f63e1c059e89 hectcastro/riak "/sbin/my_init --quie" 26 hours ago Up 23 hours 0.0.0.0:32809->8087/tcp, 0.0.0.0:32808->8098/tcp riak01
#Note,4.2 至 4.3 重复操作,直到所有node都加入cluster
4.2) 连接到docker container并运行bash
$ sudo docker exec -it c94b016fcdc3 bash
root@c94b016fcdc3:/#
4.3) 把该node加入到node 1
root@c94b016fcdc3:/# riak-admin cluster join riak@172.17.0.2
root@c94b016fcdc3:/# riak-admin cluster plan
root@c94b016fcdc3:/# riak-admin cluster commit
4.4) 查看是否5个node都已经加入cluster
root@c94b016fcdc3:/# riak-admin cluster status
---- Cluster Status ----
Ring ready: true
+---------------------+------+-------+-----+-------+
| node |status| avail |ring |pending|
+---------------------+------+-------+-----+-------+
| riak@172.17.0.2 |valid | up | 18.8| -- |
| (C) riak@172.17.0.3 |valid | up | 18.8| -- |
| riak@172.17.0.4 |valid | up | 18.8| -- |
| riak@172.17.0.5 |valid | up | 18.8| -- |
| riak@172.17.0.6 |valid | up | 25.0| -- |
+---------------------+------+-------+-----+-------+
Step 5) 也可以执行Basho官方文档里的脚本来查看Cluster是否正常
alex@18:~/github/docker-riak$ make test-cluster | grep -A6 "ring_members"
"ring_members": [
"riak@172.17.0.2",
"riak@172.17.0.3",
"riak@172.17.0.4",
"riak@172.17.0.5",
"riak@172.17.0.6"
],
alex@18:~/github/docker-riak$ make test-cluster | grep "ring_ownership"
"ring_ownership": "[{'riak@172.17.0.2',12},\n {'riak@172.17.0.3',12},\n {'riak@172.17.0.4',12},\n {'riak@172.17.0.5',12},\n {'riak@172.17.0.6',16}]",
Step 6)测试Riak KV 是否可以正常读写
6.1) 从node 4 写入一个数据,没有 bucket type, bucket : "test" key : "database" value : "riak KV"
alex@18:~/github/docker-riak$ curl -i "http://localhost:32814/buckets/test/keys/database" -X PUT -H "Content-type: text/plain" -d "riak KV"
HTTP/1.1 204 No Content
Vary: Accept-Encoding
Server: MochiWeb/1.1 WebMachine/1.10.8 (that head fake, tho)
Date: Sun, 15 Jan 2017 16:22:15 GMT
Content-Type: text/plain
Content-Length: 0
6.2) 从node 3 读出我们刚刚写入的值
alex@18:~/github/docker-riak$ curl -i "http://localhost:32812/buckets/test/keys/database"
HTTP/1.1 200 OK
X-Riak-Vclock: a85hYGBgzGDKBVI8O3JTvxV/54mFCCUy5rEybJP9cJEvCwA=
Vary: Accept-Encoding
Server: MochiWeb/1.1 WebMachine/1.10.8 (that head fake, tho)
Link: </buckets/test>; rel="up"
Last-Modified: Sun, 15 Jan 2017 16:22:14 GMT
ETag: "JyZ6HhCo0nl0IQiw7Ug0q"
Date: Sun, 15 Jan 2017 16:22:29 GMT
Content-Type: text/plain
Content-Length: 7
riak KV
————————————————
版权声明:本文为CSDN博主「swedenfeng」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/swedenfeng/article/details/54565670
在Docker中运行Riak KV Cluster
分享好友
分享这个小栈给你的朋友们,一起进步吧。
订阅须知
• 所有用户可根据关注领域订阅专区或所有专区
• 付费订阅:虚拟交易,一经交易不退款;若特殊情况,可3日内客服咨询
• 专区发布评论属默认订阅所评论专区(除付费小栈外)
技术专家
查看更多- 飘絮絮絮丶专家