1.下载官方 redis.conf
http://download.redis.io/redis-stable/redis.conf
2.修改redis.conf
# bind 127.0.0.1 //加上注释#
protected-mode no //关闭保护模式
port 6061 //绑定自定义端口
#daemonize yes //禁止redis后台运行
pidfile /var/run/redis_6061.pid
cluster-enabled yes //开启集群 把注释#去掉
cluster-config-file nodes_6061.conf //集群的配置 配置文件首次启动自动生成
2.docker-compose.yaml
version: '3.4'
services:
node1:
image: redis:5.0.5
container_name: redis-node1
restart: always
ports:
- 6061:6061
- 16061:16061
volumes:
- /home/smb/data/redis-cluster/node1:/data
- /home/smb/config/redis-cluster/node1:/usr/local/etc/redis
command:
redis-server /usr/local/etc/redis/redis.conf
node2:
image: redis:5.0.5
container_name: redis-node2
restart: always
ports:
- 6062:6062
- 16062:16062