Article directory
1. Add configuration file
A total of 8 files
- Create 6 redisXXX.conf files.
The content of the 6 files is the same as the following, but the port value needs to be modified. For example: change all the following 6379 to 6380# 路径为redis.conf的绝对路径 include /redis集群/redis.conf pidfile "/var/run/redis_6379.pid" # 端口 port 6379 # 持久化文件名字 dbfilename "dump6379.rdb" cluster-enabled yes # 打开集群模式 cluster-config-file nodes-6379.conf #设定节点配置文件 cluster-node-timeout 15000 # 设定节点失联时间,超过该时间(毫秒),集群自动进行主从切换
- redis.conf file
The redis.conf file is copied from the redis installation directory, andappendonly
the parameters are changed tono
more than 600 lines. You can use /appendonly or ?appendonly to find the content
- sentinel.conf file
Create a sentinel.conf file and add the following# 以6379为主节点 sentinel monitor mymaster 127.0.0.1 6379 1
2. Start the service and cluster
-
Start 6 with redis-server redisXXX.conf command
服务
will generate nodes configuration file
-
Combine 6 nodes into a cluster
and go to the src folder under the redis installation path#执行 redis-cli --cluster create --cluster-replicas 1 192.168.121.133:6379 192.168.121.133:6380 192.168.121.133:6381 192.168.121.133:6389 192.168.121.133:6390 192.168.121.133:6391 命令启动集群
Enter yes to determine the master-slave assignment
The cluster started successfully
-
connect redis
连接集群 redis-cli -p -c 6379 查看节点 cluster nodes
3. Cluster operation
Data will be allocated by slot
set k1 k1
View the slot value of the key in the cluster
cluster keyslot key
Check how many keys are in the slot
cluster getkeysinslot 插槽值
View the first key of the slot
cluster getkeysinslot 插槽值 第几个
4. Fault recovery
- hang up a host
- Restart will become slave
A section of master-slave is down, the cluster is unavailable
cluster-require-full-coverage yes
A section of master-slave is down, the cluster is available, but this section of slot is unavailable
cluster-require-full-coverage no