redis cluster installation and configuration

Native command to build redis cluster distributed 3 masters and 3 slaves

1. Prepare the node

Here is a demonstration of single-machine multi-deployment (multi-machine production environment). First, prepare 6 nodes, which are ports 7000-7005.

Configure port 7000 first

The configuration related to the cluster is explained here

cluster-enabled indicates whether the node enables cluster mode

cluster-config-file is a configuration file for generating a local cluster

cluster-require-full-coverage This means that if one node in the cluster dies, the entire cluster will be unavailable. The default yes is changed to no, that is, if a node dies, the cluster still provides services to the outside world.

Then configure other nodes (same as 7000)

Then start all nodes

Here we randomly select a node set data, and found that an error was reported

Here, because we have not allocated slots, the cluster is unavailable. You can enter the cluster info command to see the status of the cluster.

2. Node handshake

After the node configuration is started, the next step is to perform the node handshake (meet operation)

Execute cluster meet ip port on the node to handshake a node in the cluster

The cluster nodes command lists all nodes in the cluster and found 6, of which 7000 is the master node

Then execute the cluster info command to observe:

Both nodes found that there are 6 nodes, and all nodes in the table name cluster have been interconnected.

3. Distribution slot

The command to allocate slots is cluster addslots [slot] where the slot parameter is that slot nodes can only be allocated one at a time. If we want to allocate slots in the range of 0 to 5000 for 7000 nodes, we need to execute 5000 commands, so we need to write a shell script to Complete the allocation slot:

start=$1
end=$2
port=$3
for slot in `seq ${start} ${end}`
do
  echo "slot:${slot}"
  redis-cli -p ${port} cluster addslots ${slot}
done

The cluster has a total of 16384 slots (0-16383), so in order to distribute evenly to 3 nodes (7000-7002 is the master, 7003-7005 is the slave), we plan 16384/3, which is 0~5461, 5462~10922, three ranges.

Next we execute the allocation slot script:

sh addslots.sh 0 5461 7000
sh addslots.sh 5462 10922 7001
sh addslots.sh 10923 16383 7002

Execute cluster nodes and cluster info to check that all slots have been allocated.

At this time, we set a value and succeeded

4. Configure master-slave

Configuration method: execute cluster replicate [nodeId] on the selected slave node, nodeId can be obtained through cluster nodes

After execution, look at the node status and find that the master-slave relationship already exists

Enter cluster slots to see slot allocation and master-slave

So far, the native manual installation method is demonstrated!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324419379&siteId=291194637