In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Redis is a distributed-oriented Nosql product, which naturally supports the active / standby mode, and it is very simple to configure a complete set of active / standby mode. For redis, the configuration of active / standby mode is very simple, but it is of great significance online.
Main content
1.CAP theory
two。 The replication principle of simple redis
Analysis of configuration parameters related to 3.redis replaction
4. Configure star model active and standby mode
5. Configure the active and standby mode of directed non-joyful model
1. Replication and Cluster concept of Grinding redis
Redis replication and clustering, at first I made a misunderstanding between the two, and corrected them in time in the process of in-depth learning.
Make a simple distinction.
Redis replication: it can be understood as copy multiple copies of the redis service for client access. But the data held between servers is the same. You can compare the RAC of oracle with the active / standby mode in mysql database. Mainly solve the reliability and expansibility of redis service.
Redis cluster: cluster mainly solves the problem of large amount of data. The memory and storage of a machine is often limited, but the growth of the amount of data is often "unlimited". You can use clustering to spread the data among multiple redis services. If you can think of memcached's consistent hashing algorithm, that's right.
No matter the redis replication core cluster, it will involve the synchronization of node information, which has to be affected by the CAP theory.
Introduction to 2.CAP Theory
CAP Theorem (CAP theorem), also known as Brewer's theorem Theorem, points out that it is impossible for a distributed computing system to satisfy the following three points at the same time:
Consistency (Consistence) (equivalent to all nodes accessing the same latest copy of data)
Availability (Availability) (high availability for data updates)
Tolerate network partitioning (Partition tolerance) (in practical terms, partitioning is equivalent to a time limit for traffic. If the system cannot achieve data consistency within the time limit, it means that a partition situation has occurred and a choice must be made between C and A for the current operation [3]. )
According to the theorem, distributed systems can only satisfy two of the three terms, but not all three [4].
The design and configuration of redis is also trying to solve the problems caused by CAP, but it is impossible to make a complete decision and can only be balanced among the three.
An introduction to 3.Redis replication
Database replication refers to the behavior of one-way information dissemination between different database instances, which is usually composed of the replicated party and the replicated party, and a network connection is established between the replicated party and the replicated party. Usually, the replicated party takes the initiative to send the data to the replicator, and the replicator receives the data stored in the current instance. The ultimate goal is to ensure that the data of both parties are consistent and synchronized.
Copy the schematic diagram
There are two ways to copy Redis, one is master-slave mode, the other is slave-slave mode, so the replication topology diagram of Redis will be richer, either like star topology or directed acyclic:
Redis cluster replication structure diagram
Multiple Redis instances are configured to run independently and replicate directionally to form a Redis cluster (the concept of cluster here is a broad concept). Master is responsible for writing and slave is responsible for reading.
Through replication, the following goals can be achieved
1. High availability (if master is down, slave can step in and replace master)
2. High performance (separation of active and standby, sharing master pressure)
3. Horizontal scalability (according to the 2008 law, increase the ability of slave machines to horizontally (horizontally) expand the entire query service of Redis services)
The problems brought about:
1. Synchronization overhead
two。 Data inconsistency problem
3. Programming complexity
Analysis of configuration parameters related to 4.redis replaction
This parameter is enabled when slaveof # sets the database as the slave database of another database.
# set when the machine is a slave service, set the IP address and port of the master service. When Redis starts, it automatically synchronizes data from the master slave-serve-stale-data yes#. When the slave library loses connection with the host or replication is in progress, the slave library can be run in two ways:
# 1) if slave-serve-stale-data is set to yes (the default), the slave library will continue to respond to client requests.
# 2) if slave-serve-stale-data refers to no, any request other than the INFO and SLAVOF commands will return an error "SYNC with master in progress" slave-read-only yes# to configure whether the slave instance accepts writing. Writing slave is useful for storing short-lived data (which can be easily deleted after synchronizing with master data), but without configuration, client writes may send problems. The repl-ping-slave-period 1 slave library sends PINGs to the master library at a time interval. You can set this interval through repl-ping-slave-period. The default is 10 seconds repl-timeout 60#repl-timeout to set the bulk data transfer time of the main library or the ping reply time interval. The default value is 60 seconds.
# make sure that repl-timeout is greater than repl-ping-slave-periodrepl-diskless-sync no to start diskless replication. Synchronization to the backup node does not need to be done by the intermediate Mr. into files.
Repl-diskless-sync-delay 5
Delay before synchronization to wait for other slave to be linked
Configure the delay time for the start of the transfer to wait for more connections from the server
Repl-disable-tcp-nodelay no# disables TCP_NODELAY after SYNC of slave socket
# if you select "yes", Redis will use a smaller digital TCP packet and less bandwidth to send the data to slave, but this may cause a delay in sending the data to the slave side, up to 40 milliseconds if it is the default configuration of Linux kernel.
# if you select "no", the delay in sending data to the slave side will be reduced, but more bandwidth will be used for replication .repl-backlog-size 1mb
# set the size of the replicated backlog (background log).
# the larger the background log of replication, the longer it will take for slave to disconnect and possibly perform partial replication later.
# backend logs are allocated only once when there is at least one slave connection. Repl-backlog-ttl 360 after master no longer connects to slave, the background log will be released. The following configuration defines the time (in seconds) to be released after disconnecting from the last slave. # 0 means that the background log slave-priority 10 is never released. If master can no longer work properly, the slave with the lowest priority value will be selected to promote to master, and a priority value of 0 means that it cannot be promoted to mastermin-slaves-to-write 0.
At least the number of slave servers required to perform a write operation
# if less than N slave connections And delay time set title "replaction" OK127.0.0.1:6379 > exit [root@hadoop2 redis] # bin/redis-cli-p 6380127.0.0.1root@hadoop2 redis 6380 > keys * 1) "title" 127.0.0.1root@hadoop2 redis 6380 > get title "replaction" [root@hadoop2 redis] # bin/redis-cli-p 6381127.0.1OK127.0.0.1:6379 6381 > keys * 1) "title" 127.0.0.1lug 6381 > get title "replaction" 127.0.0.1: 6381 > set title 111 (error) READONLY You can't write against a read only slave. Modify the following values: 127.0.0.1 OK127.0.0.1:6380 6379 > set title "replaction 1" OK127.0.0.1:6380 > get title "replaction 1" 127.0.0.1 replaction 6381 > get title "replaction 1"
Verification passed
5. Configure the active and standby mode of directed non-joyful model
Basically, there is no difference between the active and standby mode of the star model.
Change point # standby (Slaver2) node, disable RDB, disable AOFslaveof 127.0.0.1 6379 to slaveof 127.0.0.1 6380
Test strategy
Reference resources
Http://my.oschina.net/andylucc/blog/683631
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.