Docker实现一个Redis cluster

Recommend: http://www.hawu.me/operation/802
1. docker-machine 建立三台虚拟机,first,second,third,third is a worker and the other
two are managers as the following picture.
docker-machine 建立三台虚拟机,first,second,third,third is a worker and the other two are managers.

2.
You can also encrypt data exchanged between containers on different nodes on the overlay network. To enable encryption, when you create an overlay network pass the –opt encrypted flag:

$ docker network create --opt encrypted --driver overlay myapp

When you enable overlay encryption, Docker creates IPSEC tunnels between all the nodes where tasks are scheduled for services attached to the overlay network. These tunnels also use the AES algorithm in GCM mode and manager nodes automatically rotate the keys every 12 hours.
建立overlay 网络myapp方便跨主机容器通信,–opt encrypted为加密,可不加。
3.
use command on manager node :

docker service create --network myapp --name redis-1 -p  7001:6379 redis

可以用docker service scale = 3 把任务副本调到3个,默认为1;

4.

docker service ps redis-1

查看service在哪些nodes上运行,发现second上有运行
5.
之后进入second容器docker exec -it 1a040a45302c /bin/bash
6.
然后docker@second:~$ redis-cli -h 192.168.99.101 -p 7001可以自己连接,也可以通过其他主机连接second.(方式一样,进入redis容器,然后主机连接second主机的7001端口即可。)

root@1a040a45302c:/data# redis-cli -h 192.168.99.101 -p 7001
192.168.99.101:7001> set abc 123
OK
192.168.99.101:7001> get abc
"123"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值