Currently the most popular non-relational database—Nosql-Redis persistent storage, key-value pairs

Nosql overview

What is nosql?

  • Nosql is not only sql, which means: use a relational database when it is suitable for a relational database, and it is not necessary to use a relational database when it is not applicable. You can consider using a more suitable data storage. This refers to non-relational databases in general. NoSQL is used for the storage of very large-scale data.

Master-slave replication

What is master-slave replication

  • Master-slave replication refers to copying the data of one Redis server to other Redis servers. The former is called the master and the latter is called the slave. The data replication is one-way and can only be from the master to the slave.
  • By default, each Redis server is the master node; and a master node can have multiple slave nodes (or no slave nodes), but a slave node can only have one master node.

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 deployment:

Environment configuration:

A Centos7 virtual machine
Insert picture description here

redis package upload
Insert picture description here

1. Installation related dependencies
yum -y install gcc gcc-c++
2. Unpack into the directory and compile
tar xf redis-3.2.11.tar.gz 
cd redis-3.2.11
make
3. Copy the master-slave configuration file
cp redis.conf /etc/redis-master.conf
cp redis.conf /etc/redis-slave.conf
4. Modify the configuration file
vim /etc/redis-master.conf 
vim /etc/redis-slave.conf 

Master modification:

Insert picture description here
Slave modification:

Insert picture description here
Insert picture description here
Insert picture description here

5. Start the master and slave redis services in the background
/root/redis-3.2.11/src/redis-server /etc/redis-master.conf &
/root/redis-3.2.11/src/redis-server /etc/redis-slave.conf &
6. Test whether the redis master-slave is successful

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_49296785/article/details/109020963