redis集群docker化部署

Posted by 刘勇(lyonger) on 2020-03-20

redis集群docker化部署

  • 使用场景:单台机器使用容器部署。

机器环境

1
2
3
4
Distributor ID:	Debian
Description: Debian GNU/Linux 8.11 (jessie)
Release: 8.11
Codename: jessie

安装docker-compose

1
2
3
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version

创建redis数据目录

1
mkdir -p /home/liuyong/redis-cluster/{8001,8002,8003,8004,8005,8006}/data

准备docker-compose文件

  • 部署时使用了人家已经做好的镜像publicisworldwide/redis-cluster
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
version: '3'

services:
redis1:
image: publicisworldwide/redis-cluster
restart: always
volumes:
- /home/liuyong/redis-cluster/8001/data:/data
environment:
- REDIS_PORT=8001
ports:
- '8001:8001' #服务端口
- '18001:18001' #集群端口

redis2:
image: publicisworldwide/redis-cluster
restart: always
volumes:
- /home/liuyong/redis-cluster/8002/data:/data
environment:
- REDIS_PORT=8002
ports:
- '8002:8002'
- '18002:18002'

redis3:
image: publicisworldwide/redis-cluster
restart: always
volumes:
- /home/liuyong/redis-cluster/8003/data:/data
environment:
- REDIS_PORT=8003
ports:
- '8003:8003'
- '18003:18003'

redis4:
image: publicisworldwide/redis-cluster
restart: always
volumes:
- /home/liuyong/redis-cluster/8004/data:/data
environment:
- REDIS_PORT=8004
ports:
- '8004:8004'
- '18004:18004'

redis5:
image: publicisworldwide/redis-cluster
restart: always
volumes:
- /home/liuyong/redis-cluster/8005/data:/data
environment:
- REDIS_PORT=8005
ports:
- '8005:8005'
- '18005:18005'

redis6:
image: publicisworldwide/redis-cluster
restart: always
volumes:
- /home/liuyong/redis-cluster/8006/data:/data
environment:
- REDIS_PORT=8006
ports:
- '8006:8006'
- '18006:18006'

启动redis集群

1
2
3
4
#启动redis实例
docker-compose -f docker-compose-redis-cluster.yml up -d
#初始化redis集群, inem0o/redis-trib为docker镜像名称
docker run --rm -it inem0o/redis-trib create --replicas 1 eth0_ip:8001 eth0_ip:8002 eth0_ip:8003 eth0_ip:8004 eth0_ip:8005 eth0_ip:8006
  • 看到类似如下信息代表成功
    请在这里输入图片描述

参考资料



支付宝打赏 微信打赏

赞赏一下