Redis cluster mode installation ------- at a glance

Table of contents

 

Introduction to reids cluster mode

start installation

host planning

Preparation

Configuration file - port 6379

Configuration file - port 6380

Replenish

Redis occupies memory size configuration

Memory elimination for Redis


 

Introduction to reids cluster mode

 

1. All redis nodes are interconnected with each other (PING-PONG mechanism), and the binary protocol is used internally to optimize the transmission speed and bandwidth.
2. The fail of a node takes effect only when more than half of the nodes in the cluster detect the failure.
3. The client is directly connected to the redis node, without the need for an intermediate proxy layer. The client does not need to connect to all nodes in the cluster, but to any available node in the cluster. 4. In order to ensure high availability of data,
redis cluster has added a master-slave mode , a master node corresponds to one or more slave nodes, the master node
    provides data access, and the slave node pulls data backup from the master node, when the master node hangs up, one of the slave nodes will be selected to act as the
    master node, so as to ensure that the cluster will not hang up.
5. redis-cluster maps all physical nodes to [0-16384] slots (not necessarily evenly distributed), and the cluster is responsible for maintaining node<->slot<->value.
6. The Redis cluster has pre-divided 16384 buckets. When a key-value needs to be placed in the Redis cluster, according to the
    value of CRC16(key) mod 16384, decide which bucket to put a key in 

start installation

host planning

This tutorial is in redis cluster mode, and three machines are used for deployment. The host planning is as follows.

Number of hosts: 3
Coordination: 1 core 1G
System: centos: 7
Version: CentOS Linux release 7.8.2003 (Core)
Kernel version: 3.10.0-1127.el7.x86_64
Firewall: Close
selinux: Close (setenforce 0)

IP planning
No. Service type Planning IP Remarks (port)

1      redis-1    192.168.241.5     6379
2      redis-1    192.168.241.5     6380
3      redis-2    192.168.241.6     6379
4      redis-2    192.168.241.6     6380
5      redis-3    192.168.241.123     6379
6      redis-3    192.168.241.123     6380

 

 


Preparation

ps (# is comment $ is operation command)

 #Do three masters and three slaves, follow this step for all three machines
#Install the required plug-ins

$ yum -y install wget gcc gcc-c++ make tar openssl openssl-devel cmake
#Use the 6.2.4 version to pull directly from the Internet Take
$wget http://download.redis.io/releases/redis-6.2.4.tar.gz
#Unzip and install 
$tar zxf redis-6.2.4.tar.gz  
#Place the execution file
$cd redis-6.2.4 /src/ 
$cp redis-trib.rb /usr/local/bin

#Install

$cd /root/redis-6.2.4

#Deploy the first redis installation path to define
$make PREFIX=/usr/local/redis1 install  

#Deploy the second redis
$make MALLOC=libc PREFIX=/usr/local/redis2 install
#When installing redis2, there may be an error and execute it again
$make MALLOC=libc PREFIX=/usr/local/redis2 install

#Copy reids-cli to /usr/local/bin

$cp /redis-6.2.4/src/redis-cli    /usr/local/bin/

Configuration file - port 6379

config-file-6379

Modify the redis.conf template in the installation package as follows: modify the number of lines one by one
$cp /root/redis-6.2.4/redis.conf /usr/local/redis1
$vim /usr/local/redis1/redis.conf     bind 0.0.0.0 // Test link, any address can be connected to line 75     port 6379 // modify to the corresponding port number line 98     daemonize yes // run 257 lines in the background     pidfile /var/run/redis_6379.pid // pid file 289 Line     logfile "/usr/local/redis1/logs/redis.log" // Log 302 line     requirepass 123456 // Line 483 joins the password to connect to the node     masterauth 123456 // Line 484 The password for mutual access between nodes     appendonly yes / / Enable aop to backup 1252 lines     appendfsync always // Write a backup once 1282 lines     cluster-enabled yes // Enable Redis Cluster 1385 lines     cluster-config-file nodes-6379.conf // Record cluster information, no manual maintenance, Redis Cluster 1393 lines will be automatically maintained 











    cluster-node-timeout 15000 // Cluster timeout time 1399 lines
    cluster-require-full-coverage no // As long as there is a node downtime and 16384 slots are not covered, the entire cluster will stop serving, so it must be changed to no 1485 lines

#The log path has to be created manually or it will fail to start

$ mkdir /usr/local/redis1/logs

$touch  /usr/local/redis1/logs/redis.log

#start up

$cd /usr/local/redis1/

$nohup ./bin/redis-server redis.conf &

Configuration file - port 6380

Profile-6380

Just copy the configuration file of redis1 and modify it

$cp /usr/local/redis1/redis.conf  /usr/local/redis2/redis.conf

$vim /usr/local/redis2/redis.conf     bind 0.0.0.0 // test link, any address can be connected 75     port 6380 // modify to the corresponding port number 98     daemonize yes // run in the background 257     pidfile /usr/local /redis2/redis_6380.pid // pid file 289     logfile "/usr/local/redis2/logs/redis.log" // log 302     requirepass 123456 //483 lines join to connect to node password     masterauth 123456 //484 lines between nodes password for mutual access     appendonly yes // enable aop backup 1252     appendfsync always // write a backup once every time 1281     cluster-enabled yes // enable Redis Cluster 1358     cluster-config-file nodes-6380.conf // record cluster information, Without manual maintenance, Redis Cluster will automatically maintain 1393     cluster-node-timeout 15000 // Cluster timeout 1399 












    cluster-require-full-coverage no // As long as a node is down and 16384 slots are not covered, the entire cluster will stop serving, so it must be changed to no 1458

#The log path has to be created manually or it will fail to start

$ mkdir /usr/local/redis1/logs

$touch  /usr/local/redis1/logs/redis.log

#start up

$cd /usr/local/redis2/

$./bin/redis-server redis.conf

Check if the process exists

$ ps -ef | grep redis

Check if the port exists

$ ss -ntlp | grep 6379 

$ ss -ntlp | grep 6380

 

 

 

#Start to use Redis's own cluster management tool to create a cluster
#Create a cluster, --cluster-replicas 1 specifies the number of slave libraries 1, and the creation sequence is three masters-three slaves. That is master-master-master-slave-slave-slave.
#If a password is set for redis, you need to add password information when creating a cluster -a password:

redis-cli --cluster create ip+port ip+port ip+port ip+port ip+port ip+port --cluster-replicas 1 -a 123456


#If you see a prompt like [OK] All 16384 slots covered., the cluster is created successfully.
#You can enter redis to view the cluster information by entering any one

 

 

 

 So far the cluster installation is complete...  


Replenish

Redis occupies memory size configuration

We know that Redis is a memory-based key-value database. Because the memory size of the system is limited, we can configure the maximum memory size that Redis can use when using Redis.

1. Configure through the configuration file

Set the memory size by adding the following configuration to the redis.conf configuration file under the Redis installation directory​
//Set the maximum memory size of Redis to 100M​
maxmemory 100mb ​ 
The redis configuration file does not necessarily use the redis.conf file under the installation directory. When starting the redis service, you can pass a parameter to specify the redis configuration file

2. Modify by command

#Redis supports dynamic modification of memory size through commands at runtime
 //Set the maximum memory size of Redis to 100M​
127.0.0.1:6379> config set maxmemory 100mb ​ 
//Get the maximum memory size that Redis can use
127.0.0.1:6379> config get maxmemory 
1) "maxmemory" 
2) "0" 
#If you do not set the maximum memory size or set the maximum memory size to 0, the memory size is not limited under the 64-bit operating system, and the maximum memory size is 3GB under the 32-bit operating system

Memory elimination for Redis

Since the maximum memory size of Redis can be set, the configured memory will be used up. Then when the memory is used up, if you continue to add data to Redis, won't there be no memory available?

In fact, Redis defines several strategies to deal with this situation:

noeviction (default policy): no longer provide services for write requests, and return errors directly (except for DEL requests and some special requests)

allkeys-lru: use the LRU algorithm for elimination from all keys

volatile-lru: Use the LRU algorithm to eliminate from the key with the expiration time set

allkeys-random: Randomly eliminate data from all keys

volatile-random: Randomly eliminated from the key with the expiration time set

volatile-ttl: In the key with the expiration time set, it will be eliminated according to the expiration time of the key. The earlier the expiration time, the higher priority it will be eliminated

When using the three strategies of volatile-lru, volatile-random, and volatile-ttl, if no key can be eliminated, an error will be returned like noeviction


#Get the current memory elimination strategy:

127.0.0.1:6379> config get maxmemory-policy
1) "maxmemory-policy"
2) "noeviction"


#1. Set the elimination strategy through the configuration file (modify the redis.conf file):

maxmemory-policy allkeys-lru

#2. Modify the elimination strategy by command:

127.0.0.1:6379> config set maxmemory-policy allkeys-lru

Guess you like

Origin blog.csdn.net/weixin_48780227/article/details/127749750