Remember a Centos7.x installation configuration Redis 6.0.5 and configuration master-slave replication

1. Basic information

Official website: https://redis.io/ 

Official document:   https://redis.io/documentation

Chinese website:   http://www.redis.cn/ 

Chinese forum:   http://bbs.redis.cn/forum.php

Redis tutorial:   https://www.runoob.com/redis/redis-tutorial.html

Chinese tutorial:   http://www.redis.com.cn/

Chinese community: https://ruby-china.org/topics/node10 

Redis community:   http://www.redis.cn/community.html

2. Overview

Most of the existing enterprises use redis stand-alone service in 80% of companies. In actual scenarios, single node redis is prone to risk.

Facing problem

1. The machine is malfunctioning. We deploy to a Redis server. When a machine fails, we need to migrate to another server and ensure that the data is synchronized. And data is the most important thing. If you don't care, you basically won't use Redis.

2. Capacity bottleneck. When we need to expand the Redis memory, from 16G to 64G, a stand-alone machine is definitely not enough. Of course, you can buy a new 128G machine.

Solution

To achieve greater storage capacity of the distributed database and withstand high concurrent access, we will store the data of the original centralized database on multiple other network nodes.

In order to solve this single node problem, Redis will also deploy multiple copies of data replication to other nodes for replication to achieve high availability of Redis and redundant backup of data, thereby ensuring high availability of data and services.

Three, the role of master-slave replication

1. Data redundancy: Master-slave replication realizes hot backup of data, which is a data redundancy method besides persistence.

2. Failure recovery: When the master node has a problem, the slave node can provide services to achieve rapid failure recovery; in fact, it is a kind of service redundancy.

3. Load balancing: On the basis of master-slave replication, with the separation of read and write, the master node can provide write services and the slave nodes provide read services (that is, the application connects to the master node when writing Redis data, and the application connects to the slave node when reading Redis data. Node) to share the server load; especially in the scenario of writing less and reading more, sharing the read load by multiple slave nodes can greatly increase the concurrency of the Redis server.

4. Read-write separation: It can be used to realize read-write separation. The main library writes and reads from the library. The read-write separation can not only increase the load capacity of the server, but also change the number of slave libraries according to changes in demand.

5. The cornerstone of high availability: In addition to the above functions, master-slave replication is also the basis for the implementation of sentinels and clusters. Therefore, master-slave replication is the basis for Redis high availability.

Master-slave replication enabled

There are 3 ways to start master-slave replication from the node:

1. Configuration file: Add replicaof (lower version: slaveof) to the configuration file of the slave server.

2. Start command: add --replicaof (lower version: slaveof) after redis-server start command.

3. Client command: After the Redis server is started, directly execute the command replicaof (lower version: slaveof) through the client, then the Redis instance becomes a slave node.

Four, system and tools

1. System information

system IP RAM CPU program
CentOS-7-x86_64-Minimal-1810.iso 192.168.11.18 2G 1 core redis-6.0.5.tar.gz
CentOS-7-x86_64-Minimal-1810.iso 192.168.11.19 2G 1 core redis-6.0.5.tar.gz

System mirror download address:

http://archive.kernel.org/centos-vault/7.4.1708/isos/x86_64/

Virtual machine installation process reference:

https://blog.csdn.net/llwy1428/article/details/89328381

2. VMware version: VMware Workstation Pro15

3. Tools: xshell5

Five, installation, deployment, configuration

1. Install basic tools

[root@localhost ~]# yum install gcc gcc-c++ wget vim net-tools nmap lrasz tree make tcl -y

2. Modify the gcc version

[root@localhost ~]# yum -y install centos-release-scl

[root@localhost ~]# yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils

[root@localhost ~]# scl enable devtoolset-9 bash

3. Create a directory and download

[root@localhost ~]# mkdir /opt/redis

[root@localhost ~]# cd /opt/

[root@localhost opt]# wget http://download.redis.io/releases/redis-6.0.5.tar.gz

4. Unzip the file

[root@localhost opt]# tar zxvf redis-6.0.5.tar.gz

5. Compile and install (I installed in the /opt/redis path)

[root@localhost ~]# cd /opt/redis-6.0.5

[root@localhost redis-6.0.5]# make 

[root@localhost redis-6.0.5]# make test

The following errors may be reported

If an error is reported, execute make distclean

[root@localhost redis-6.0.5]# make distclean

Continue to compile and install (I installed in the /opt/redis path)

[root@localhost redis-6.0.5]# make PREFIX=/opt/redis install

View installation results

6. Copy the redis.conf file in redis to the installation directory

[root@localhost ~]# cp /opt/redis-6.0.5/redis.conf /opt/redis

Create log directory

[root@localhost ~]# mkdir /opt/redis/log

Create data directory

[root@localhost ~]# mkdir /opt/redis/data

7. Send the installation file on this node (master node) to another node (slave node)

[root@localhost ~]# scp -r /opt/redis/* 192.168.11.19:/opt/redis

8. Edit configuration content

[root@localhost ~]# vim /opt/redis/redis.conf

(1)bind 0.0.0.0 127.0.0.1

(2)daemonize yes

(3)pidfile /opt/redis/redis_6379.pid

(4)logfile /opt/redis/redis.log

(5) dir / opt / redis / data

(6) requirepass 123456 #local password

(7) #<masterip> <masterport> The IP and port of the master node Redis Note: The lower version of Redis may be slaveof (only configured on the slave node)

         replicaof 192.168.11.18

(8)#<master-password> The password on the master node (only configured on the slave node)

         masterauth 123456

Description:

#daemonize no change to daemonize yes means to enable background operation

#protected-mode yes remove the # sign, which means to open the protection mode, you can choose to bind ip, or you can specify a password

dir ./ is modified to dir /opt/redis6/data which means to store the data of the specified redis

The logfile line is modified to /opt/redis/log/redis-6379.log # Specify the log storage directory

# requirepass local password

# replicaof <masterip> <masterport> # master-slave replication 

# masterauth <master-password> # Master node password

9. The master node starts the service

[root@localhost ~]# /opt/redis/bin/redis-server /opt/redisredis.conf

10. Master node test

Enter the command line

[root@localhost ~]# /opt/redis/bin/redis-cli

Enter the password in the configuration file

auth 123456

11. Start from the node

[root@localhost ~]# /opt/redis/bin/redis-server /opt/redis/redis.conf

12. When the master node is started, test the slave node

Enter the command line from the node

[root@localhost ~]# /opt/redis/bin/redis-cli

At the master node

Slave node

13, set the service to start up

https://blog.csdn.net/llwy1428/article/details/106741119

 

At this point, Centos7 has installed and configured Redis and configured the master-slave replication operation!

6. Reference address:

Centos7.x build Redis v5.0-stand-alone version-pseudo cluster

https://blog.csdn.net/llwy1428/article/details/93659772

Centos7.2 install stand-alone Redis 5.0 (compile and install)

https://blog.csdn.net/llwy1428/article/details/93612187

Redis visualization tool

https://blog.csdn.net/llwy1428/article/details/85340165

Guess you like

Origin blog.csdn.net/llwy1428/article/details/106730436