docker-compose-redis

docker compose 部署 主从复制

prepare

docker compose 部署主从复制

1
2
cd ~/apps/redis
mkdir -p redis-master/data redis-slave-1/data redis-slave-2/data
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
version: '3'

services:
master:
image: redis
container_name: redis-master
privileged: true
restart: always
command: redis-server --cluster-enabled yes --cluster-announce-ip 192.168.50.28 --requirepass summer
volumes:
- ./redis-master/data:/data
ports:
- 6379:6379

slave1:
image: redis
container_name: redis-slave-1
privileged: true
restart: always
command: redis-server --slaveof redis-master 6379 --cluster-announce-ip 192.168.50.28 --requirepass summer --masterauth summer
volumes:
- ./redis-slave-1/data:/data
ports:
- 6380:6379

slave2:
image: redis
container_name: redis-slave-2
privileged: true
restart: always
command: redis-server --slaveof redis-master 6379 --cluster-announce-ip 192.168.50.28 --requirepass summer --masterauth summer
volumes:
- ./redis-slave-2/data:/data
ports:
- 6381:6379

启动命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
systemctl start docker

docker-compose up -d

docker exec -it redis-master /bin/bash
## fix slots coverage
redis-cli --cluster fix 192.168.50.28:6379 -a summer

redis-cli -h redis-master -a summer

cluster nodes

# 检查集群
redis-cli --cluster check 192.168.50.28:6379 --cluster-search-multiple-owners -a summer
# 修复集群
redis-cli --cluster fix 192.168.50.28:6379 --cluster-search-multiple-owners -a summer
# 说明:检查key、slots、从节点个数的分配情况


# 集群信息查看
redis-cli --cluster info 192.168.50.28:6379 -a summer


安装常见问题

ps命令在docker容器不存在

1
apt-get update && apt-get install procps -y

容器 下查看redis的安装目录的方法是什么

1
ps -ef|grep redis

得到了进程号 xxxx,
然后 ls -l /proc/xxxx/cwd

Redis集群Hash槽分配异常 CLUSTERDOWN Hash slot not served的解决方式

1
2
redis-cli --cluster check  192.168.171.134:6379
redis-cli --cluster fix 192.168.171.134:6379
1
redis-cli -c -h 192.168.171.134
1
redis-cli -h host -p port -a password

参考文章

评论