redis cluster startup

1. Add configuration file

A total of 8 files
insert image description here

  1. 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 # 设定节点失联时间,超过该时间(毫秒),集群自动进行主从切换
    
  2. redis.conf file
    The redis.conf file is copied from the redis installation directory, and appendonlythe parameters are changed to no
    more than 600 lines. You can use /appendonly or ?appendonly to find the content
    insert image description here
  3. 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

  1. Start 6 with redis-server redisXXX.conf command 服务
    insert image description here
    will generate nodes configuration file
    insert image description here

  2. 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 命令启动集群
    

    insert image description here
    Enter yes to determine the master-slave assignment
    insert image description here

    The cluster started successfully
    insert image description here

  3. 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

  1. hang up a host
  2. 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

Guess you like

Origin blog.csdn.net/G_GUi/article/details/128685551