跑项目的时候需要在本地调试,但是config配置的集群是生产环境,于是在本地部署单节点集群,方便调试。

#1.本地安装redis

#2.进入/etc/redis/redis.conf 进行如下设置:

bind 127.0.0.1 -::1 # 如果需要从外部连接,一定要注释掉这行
daemonize yes
port 6379
cluster-enabled yes
cluster-config-file nodes6379.conf
appendonly yes
protected-mode no

#3.mkdir 3主3从并修改每个配置的port和cluster-config
.
├── 6379
│   └── redis_6379.conf
├── 6380
│   └── redis_6380.conf
├── 6479
│   └── redis_6479.conf
├── 6480
│   └── redis_6480.conf
├── 6579
│   └── redis_6579.conf
├── 6580
│   └── redis_6580.conf
└── redis.conf

#4.分别进入到不同的目录启动对应Redis实例
$ cd 6379/
$ redis-server redis_6379.conf
$ cd 6380/
$ redis-server redis_6380.conf
$ cd 6479/
$ redis-server redis_6479.conf
$ cd 6480/
$ redis-server redis_6480.conf 
$ cd 6579/
$ redis-server redis_6579.conf 
$ cd 6580/
$ redis-server redis_6580.conf

#5.启动redis集群
redis-cli --cluster create 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6479 127.0.0.1:6480 127.0.0.1:6579 127.0.0.1:6580 --cluster-replicas 1