Redis cluster builds linux

1. What is a Redis cluster

        Redis cluster is to solve the problem of insufficient capacity of one master server or insufficient performance during high concurrent write operations. Redis cluster is to connect multiple master servers to realize data synchronization and sharing of multiple master servers.

       Each Redis cluster has a total of 16384 slots, and these 16384 slots will be evenly allocated to the main servers in the group. When the key is stored, Redis will calculate the corresponding slot through the CRC16 algorithm and Write to the corresponding master server, so each master server only saves part of the data. This is also the principle of distributed storage of Redis cluster first, and expands capacity through distributed storage data.

Two, the characteristics of Redis cluster

  1. Decentralized, it can be multi-master and multi-slave, each node is interconnected with each other (PING-PONG mechanism), internally uses binary protocol to optimize transmission speed and bandwidth.
  2. The client directly connects to the Redis node without an intermediate agent. The client can obtain operations by connecting to any available node in the cluster.
  3. Each master server is responsible for maintaining a part of the data. At the same time, each node in the cluster has a full amount of slot information, and the storage node of each piece of data can be obtained through the slot information.

3. Construction of Redis cluster

        At least three hosts are required in the Redis cluster. In order to realize the disaster recovery processing of the host, at least one slave needs to be added to each host, so at least there are 3 masters and 3 slaves in the server architecture, and each server is an independent physical server.

        Here we are still simulating the mode of different servers through different ports on one server. We choose 6379=>6389, 6380=>6390, 6381=>6391, among which 6379, 6380, 6381 are the master servers, and 6389, 6390, 6391 are the corresponding slave servers.

1. Configuration file configuration

My Redis configuration path is in /usr/local/redis, you need to change it to your own path

include /usr/local/redis/redis.conf
pidfile "/var/run/redis6379.pid"
port 6379

daemonize yes
appendonly no
dbfilename "dump6379.rdb"
dir "/usr/local/redis/"
logfile "/usr/local/redis/log/rediserr6379.log"
cluster-enabled yes
cluster-config-file nodes6379.conf
cluster-node-timeout 15000

The same is true for the configuration files of several other port numbers, just change the corresponding port numbers. If you have used rdb persistence before, you need to delete the dump.rdb file first.

2. Start the Redis service

Start the 6 redis services, check whether the nodesXXX.conf file is generated normally, if so, it is normal.

3. Start the cluster

        First, enter the original installation path of Redis. My installation path is /usr/local/redis-6.2.7/, and enter the src directory.

 cd usr/local/redis-6.2.7/src

         Composite cluster mode

redis-cli --cluster create --cluster-replicas 1 ip address: 6379 ip address: 6380 ip address: 6381 ip address: 6389 ip address: 6390 ip address: 6391

4. Cluster login

        You can enter the cluster by entering any master server.

   redis-cli -c -p 6379

        At this point, the cluster deployment of Redis is completed

5. The relationship between Redis cluster servers

  • Any server can function the node information of the entire cluster
  • When the master server is down, the slave server will directly take over the master server, and the original master server will be mounted on the new server as a slave server after restarting

Guess you like

Origin blog.csdn.net/weixin_64940494/article/details/126380530